From 4bb1a34abbb63df680b1c63d950828e829855cce Mon Sep 17 00:00:00 2001 From: Ilya Lakhin Date: Tue, 15 Sep 2020 10:03:46 +0700 Subject: [PATCH] Fixes bug in Module::set_fn_4_mut --- src/module.rs | 2 +- tests/modules.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/module.rs b/src/module.rs index 3513dd7f..4d70b169 100644 --- a/src/module.rs +++ b/src/module.rs @@ -913,7 +913,7 @@ impl Module { TypeId::of::(), TypeId::of::(), TypeId::of::(), - TypeId::of::(), + TypeId::of::(), ]; self.set_fn(name, Public, &arg_types, Func::from_method(Box::new(f))) } diff --git a/tests/modules.rs b/tests/modules.rs index 06f5e37e..0744fd8c 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -78,6 +78,15 @@ fn test_module_resolver() -> Result<(), Box> { 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); let mut engine = Engine::new(); @@ -130,6 +139,20 @@ fn test_module_resolver() -> Result<(), Box> { )?, 42 ); + #[cfg(not(feature = "no_float"))] + { + assert_eq!( + engine.eval::( + r#" + import "hello" as h; + let x = 21; + h::sum_of_three_args(x, 14, 26, 2.0); + x + "# + )?, + 42 + ); + } #[cfg(not(feature = "unchecked"))] {