Add function pointer short-hand.
This commit is contained in:
@@ -186,7 +186,7 @@ fn test_fn_ptr_raw() -> Result<(), Box<EvalAltResult>> {
|
||||
fn foo(x) { this += x; }
|
||||
|
||||
let x = 41;
|
||||
x.bar(Fn("foo"), 1);
|
||||
x.bar(foo, 1);
|
||||
x
|
||||
"#
|
||||
)?,
|
||||
|
@@ -77,6 +77,20 @@ fn test_fn_ptr() -> Result<(), Box<EvalAltResult>> {
|
||||
if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(..))
|
||||
));
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r#"
|
||||
fn foo(x) { x + 1 }
|
||||
let f = foo;
|
||||
let g = 42;
|
||||
g = foo;
|
||||
call(f, 39) + call(g, 1)
|
||||
"#
|
||||
)?,
|
||||
42
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@@ -104,6 +104,11 @@ fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
{
|
||||
assert_eq!(
|
||||
engine
|
||||
.eval_with_scope::<INT>(&mut scope, "fn foo(z) { y + z } let f = foo; f.call(x)")?,
|
||||
42
|
||||
);
|
||||
assert!(engine.compile("let f = |y| x * y;").is_err());
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
{
|
||||
|
Reference in New Issue
Block a user