Minor refactor.
This commit is contained in:
parent
e66873bb83
commit
da3cce58d3
@ -1634,12 +1634,13 @@ fn parse_primary(
|
|||||||
Token::FloatConstant(x) => Expr::FloatConstant(Box::new(FloatWrapper(x, settings.pos))),
|
Token::FloatConstant(x) => Expr::FloatConstant(Box::new(FloatWrapper(x, settings.pos))),
|
||||||
Token::CharConstant(c) => Expr::CharConstant(Box::new((c, settings.pos))),
|
Token::CharConstant(c) => Expr::CharConstant(Box::new((c, settings.pos))),
|
||||||
Token::StringConstant(s) => Expr::StringConstant(Box::new((s.into(), settings.pos))),
|
Token::StringConstant(s) => Expr::StringConstant(Box::new((s.into(), settings.pos))),
|
||||||
Token::Identifier(s) => {
|
|
||||||
// prevents capturing of the function call
|
// Function call
|
||||||
#[cfg(not(feature = "no_closure"))]
|
Token::Identifier(s) if *next_token == Token::LeftParen || *next_token == Token::Bang => {
|
||||||
if *next_token == Token::LeftParen || *next_token == Token::Bang {
|
Expr::Variable(Box::new(((s, settings.pos), None, 0, None)))
|
||||||
state.allow_capture = false;
|
|
||||||
}
|
}
|
||||||
|
// Normal variable access
|
||||||
|
Token::Identifier(s) => {
|
||||||
let index = state.access_var(&s, settings.pos);
|
let index = state.access_var(&s, settings.pos);
|
||||||
Expr::Variable(Box::new(((s, settings.pos), None, 0, index)))
|
Expr::Variable(Box::new(((s, settings.pos), None, 0, index)))
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#![cfg(not(feature = "no_function"))]
|
#![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;
|
use std::any::TypeId;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
|
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",
|
"call_with_arg",
|
||||||
&[TypeId::of::<FnPtr>(), TypeId::of::<INT>()],
|
&[TypeId::of::<FnPtr>(), TypeId::of::<INT>()],
|
||||||
|engine: &Engine, lib: &Module, args: &mut [&mut Dynamic]| {
|
|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"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<INT>(
|
engine.eval::<INT>(
|
||||||
@ -77,11 +75,7 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
|||||||
"#
|
"#
|
||||||
)?);
|
)?);
|
||||||
|
|
||||||
let mut module = Module::new();
|
engine.register_fn("plus_one", |x: INT| x + 1);
|
||||||
|
|
||||||
module.set_fn_1("plus_one", |x: INT| Ok(x + 1));
|
|
||||||
|
|
||||||
engine.load_package(module);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<INT>(
|
engine.eval::<INT>(
|
||||||
|
Loading…
Reference in New Issue
Block a user