Add FnPtr::call_within_context.

This commit is contained in:
Stephen Chung
2021-11-29 12:43:59 +08:00
parent 0ab86ac623
commit ba0a6c667e
8 changed files with 106 additions and 39 deletions

View File

@@ -146,7 +146,7 @@ fn test_fn_ptr_raw() -> Result<(), Box<EvalAltResult>> {
let value = args[2].clone();
let this_ptr = args.get_mut(0).unwrap();
fp.call_dynamic(&context, Some(this_ptr), [value])
fp.call_raw(&context, Some(this_ptr), [value])
},
);

View File

@@ -17,7 +17,7 @@ fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
&[TypeId::of::<FnPtr>(), TypeId::of::<INT>()],
|context, args| {
let fn_ptr = std::mem::take(args[0]).cast::<FnPtr>();
fn_ptr.call_dynamic(&context, None, [std::mem::take(args[1])])
fn_ptr.call_raw(&context, None, [std::mem::take(args[1])])
},
);
@@ -155,7 +155,7 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
|context, args| {
let func = take(args[1]).cast::<FnPtr>();
func.call_dynamic(&context, None, [])
func.call_raw(&context, None, [])
},
);

View File

@@ -98,8 +98,8 @@ fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
engine.register_result_fn(
"do_stuff",
|context: NativeCallContext, callback: rhai::FnPtr| {
callback.call_dynamic(&context, None, [])
|context: NativeCallContext, callback: rhai::FnPtr| -> Result<INT, _> {
callback.call_within_context(&context, ())
},
);