rune icon indicating copy to clipboard operation
rune copied to clipboard

Implicit `i64` conversion / support for `u64`

Open SWW13 opened this issue 3 years ago • 0 comments

Currently all integers are implicitly converted to i64 and can cause overflow errors during runtime. This is related to #261 and more or less just a documentation of the error on the Rust integration side. (Feel free to close this as duplicate)

$ cargo run
Error: failed to convert integer `9223372036854775808` to value `i64`
use rune::{Context, FromValue, Vm};
use std::sync::Arc;

fn main() -> rune::Result<()> {
    let context = Context::new();
    let runtime = Arc::new(context.runtime());
    let mut sources = rune::sources! {
        entry => {
            pub fn main(a) { 0 }
        }
    };

    let unit = rune::prepare(&mut sources).with_context(&context).build()?;
    let mut vm = Vm::new(runtime, Arc::new(unit));
    let output = vm.call(&["main"], (0x8000_0000_0000_0000u64,))?;
    let output = u64::from_value(output)?;

    println!("{}", output);
    Ok(())
}

SWW13 avatar Aug 24 '22 16:08 SWW13