diff --git a/src/parser.rs b/src/parser.rs index 8c9c2940..cc0b91c8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1634,12 +1634,13 @@ fn parse_primary( Token::FloatConstant(x) => Expr::FloatConstant(Box::new(FloatWrapper(x, settings.pos))), Token::CharConstant(c) => Expr::CharConstant(Box::new((c, settings.pos))), Token::StringConstant(s) => Expr::StringConstant(Box::new((s.into(), settings.pos))), + + // Function call + Token::Identifier(s) if *next_token == Token::LeftParen || *next_token == Token::Bang => { + Expr::Variable(Box::new(((s, settings.pos), None, 0, None))) + } + // Normal variable access Token::Identifier(s) => { - // prevents capturing of the function call - #[cfg(not(feature = "no_closure"))] - if *next_token == Token::LeftParen || *next_token == Token::Bang { - state.allow_capture = false; - } let index = state.access_var(&s, settings.pos); Expr::Variable(Box::new(((s, settings.pos), None, 0, index))) } diff --git a/tests/closures.rs b/tests/closures.rs index bbc91653..d7684540 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -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> { - 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::(), TypeId::of::()], |engine: &Engine, lib: &Module, args: &mut [&mut Dynamic]| { @@ -15,9 +16,6 @@ fn test_fn_ptr_curry_call() -> Result<(), Box> { }, ); - let mut engine = Engine::new(); - engine.load_package(module); - #[cfg(not(feature = "no_object"))] assert_eq!( engine.eval::( @@ -77,11 +75,7 @@ fn test_closures() -> Result<(), Box> { "# )?); - let mut module = Module::new(); - - module.set_fn_1("plus_one", |x: INT| Ok(x + 1)); - - engine.load_package(module); + engine.register_fn("plus_one", |x: INT| x + 1); assert_eq!( engine.eval::(