#rhai is being funky

3 messages · Page 1 of 1 (latest)

tiny prairie
#

I can register a method with no arguments and it works fine, but if it has arguments the function is not found.

Minimal example:

use rhai::{CustomType, Engine, Scope, TypeBuilder};

const SCRIPT: &str = r#"
    test.method1();
    test.method2(1);
"#;

#[derive(Debug, Clone)]
struct TestStruct;

impl TestStruct {
    fn test_method1(&mut self) {
        println!("method 1")
    }

    fn test_method2(&mut self, x: u8) {
        println!("method 2")
    }
}

impl CustomType for TestStruct {
    fn build(mut builder: TypeBuilder<Self>) {
        builder
            .with_name("test")
            .with_fn("method1", Self::test_method1)
            .with_fn("method2", Self::test_method2);
    }
}

fn main() {
    let mut engine = Engine::new();
    engine.build_type::<TestStruct>();

    let mut scope = Scope::new();
    scope.push("test", TestStruct);

    println!("{:?}", engine.run_with_scope(&mut scope, SCRIPT));
}

output:

method 1
Err(ErrorFunctionNotFound("method2 (test, i64)", 3:10))
digital compass
#

so there is probably a way to specify 1_u8 in rhai