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:
Stephen Chung 2020-09-15 11:24:16 +08:00 committed by GitHub
commit 88e788208b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -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)))
} }

View File

@ -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"))]
{ {