Merge pull request #57 from Eliah-Lakhin/set-fn-4-mut-bug
Fixes bug in Module::set_fn_4_mut
This commit is contained in:
commit
88e788208b
@ -913,7 +913,7 @@ impl Module {
|
|||||||
TypeId::of::<A>(),
|
TypeId::of::<A>(),
|
||||||
TypeId::of::<B>(),
|
TypeId::of::<B>(),
|
||||||
TypeId::of::<C>(),
|
TypeId::of::<C>(),
|
||||||
TypeId::of::<C>(),
|
TypeId::of::<D>(),
|
||||||
];
|
];
|
||||||
self.set_fn(name, Public, &arg_types, Func::from_method(Box::new(f)))
|
self.set_fn(name, Public, &arg_types, Func::from_method(Box::new(f)))
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,15 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
module.set_fn_4_mut(
|
||||||
|
"sum_of_three_args".to_string(),
|
||||||
|
|target: &mut INT, a: INT, b: INT, c: f64| {
|
||||||
|
*target = a + b + c as INT;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
resolver.insert("hello", module);
|
resolver.insert("hello", module);
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
@ -130,6 +139,20 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
)?,
|
)?,
|
||||||
42
|
42
|
||||||
);
|
);
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
{
|
||||||
|
assert_eq!(
|
||||||
|
engine.eval::<INT>(
|
||||||
|
r#"
|
||||||
|
import "hello" as h;
|
||||||
|
let x = 21;
|
||||||
|
h::sum_of_three_args(x, 14, 26, 2.0);
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
)?,
|
||||||
|
42
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user