Simplify call_fn API, no need to pass &mut references.

This commit is contained in:
Stephen Chung
2020-03-10 14:09:05 +08:00
parent 711cd9bb1c
commit f3bcb2a10d
4 changed files with 61 additions and 38 deletions

View File

@@ -4,9 +4,15 @@ use rhai::{Engine, EvalAltResult};
fn test_engine_call_fn() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
let ast = engine.compile("fn hello(x, y) { x.len() + y }")?;
let ast = engine.compile(
r"
fn hello(x, y) {
x.len() + y
}
",
)?;
let result: i64 = engine.call_fn("hello", &ast, (&mut String::from("abc"), &mut 123_i64))?;
let result: i64 = engine.call_fn("hello", &ast, (String::from("abc"), 123_i64))?;
assert_eq!(result, 126);