Merge pull request #234 from schungx/master

Fixes bug in Module::set_fn_4_mut
This commit is contained in:
Stephen Chung 2020-09-15 12:29:41 +08:00 committed by GitHub
commit 2c1b75e0bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -4,6 +4,12 @@ Rhai Release Notes
Version 0.19.0 Version 0.19.0
============== ==============
Bug fixes
---------
* `if` statement with an empty `true` block would not evaluate the `false` block. This is now fixed.
* Fixes a bug in `Module::set_fn_4_mut`.
New features New features
------------ ------------

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