Allow mutating a module-qualified function's first argument if it is a variable.

This commit is contained in:
Stephen Chung
2020-07-08 13:06:00 +08:00
parent d92a514f48
commit 703cc414b8
3 changed files with 145 additions and 41 deletions

View File

@@ -73,6 +73,10 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
module.set_fn_4("sum".to_string(), |x: INT, y: INT, z: INT, w: INT| {
Ok(x + y + z + w)
});
module.set_fn_1_mut("double".to_string(), |x: &mut INT| {
*x *= 2;
Ok(())
});
resolver.insert("hello", module);
@@ -90,6 +94,18 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
42
);
assert_eq!(
engine.eval::<INT>(
r#"
import "hello" as h;
let x = 21;
h::double(x);
x
"#
)?,
42
);
#[cfg(not(feature = "unchecked"))]
{
engine.set_max_modules(5);