Merge branch 'master' into plugins

This commit is contained in:
Stephen Chung
2020-08-08 23:01:48 +08:00
6 changed files with 32 additions and 15 deletions

View File

@@ -1,12 +1,13 @@
#![cfg(not(feature = "no_function"))]
use rhai::{Dynamic, Engine, EvalAltResult, FnPtr, Module, INT};
use rhai::{Dynamic, Engine, EvalAltResult, FnPtr, Module, RegisterFn, INT};
use std::any::TypeId;
#[test]
fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
let mut module = Module::new();
let mut engine = Engine::new();
module.set_raw_fn(
#[allow(deprecated)]
engine.register_raw_fn(
"call_with_arg",
&[TypeId::of::<FnPtr>(), TypeId::of::<INT>()],
|engine: &Engine, lib: &Module, args: &mut [&mut Dynamic]| {
@@ -15,9 +16,6 @@ fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
},
);
let mut engine = Engine::new();
engine.load_package(module);
#[cfg(not(feature = "no_object"))]
assert_eq!(
engine.eval::<INT>(
@@ -38,7 +36,7 @@ fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_closure"))]
#[cfg(not(feature = "no_object"))]
fn test_closures() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let mut engine = Engine::new();
assert_eq!(
engine.eval::<INT>(
@@ -77,6 +75,19 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
"#
)?);
engine.register_fn("plus_one", |x: INT| x + 1);
assert_eq!(
engine.eval::<INT>(
r#"
let a = 41;
let f = || plus_one(a);
f.call()
"#
)?,
42
);
Ok(())
}