Merge branch 'master' into plugins

This commit is contained in:
Stephen Chung
2020-08-14 11:45:52 +08:00
5 changed files with 130 additions and 25 deletions

View File

@@ -611,9 +611,9 @@ impl Module {
) -> u64 {
let f = move |_: &Engine, _: &Module, args: &mut FnCallArgs| {
let b = mem::take(args[1]).cast::<B>();
let mut a = args[0].write_lock::<A>().unwrap();
let a = &mut args[0].write_lock::<A>().unwrap();
func(&mut a, b).map(Dynamic::from)
func(a, b).map(Dynamic::from)
};
let arg_types = [TypeId::of::<A>(), TypeId::of::<B>()];
self.set_fn(name, Public, &arg_types, Func::from_method(Box::new(f)))
@@ -735,9 +735,9 @@ impl Module {
let f = move |_: &Engine, _: &Module, args: &mut FnCallArgs| {
let b = mem::take(args[1]).cast::<B>();
let c = mem::take(args[2]).cast::<C>();
let mut a = args[0].write_lock::<A>().unwrap();
let a = &mut args[0].write_lock::<A>().unwrap();
func(&mut a, b, c).map(Dynamic::from)
func(a, b, c).map(Dynamic::from)
};
let arg_types = [TypeId::of::<A>(), TypeId::of::<B>(), TypeId::of::<C>()];
self.set_fn(name, Public, &arg_types, Func::from_method(Box::new(f)))
@@ -769,9 +769,9 @@ impl Module {
let f = move |_: &Engine, _: &Module, args: &mut FnCallArgs| {
let b = mem::take(args[1]).cast::<B>();
let c = mem::take(args[2]).cast::<C>();
let mut a = args[0].write_lock::<A>().unwrap();
let a = &mut args[0].write_lock::<A>().unwrap();
func(&mut a, b, c).map(Dynamic::from)
func(a, b, c).map(Dynamic::from)
};
let arg_types = [TypeId::of::<A>(), TypeId::of::<B>(), TypeId::of::<C>()];
self.set_fn(
@@ -892,9 +892,9 @@ impl Module {
let b = mem::take(args[1]).cast::<B>();
let c = mem::take(args[2]).cast::<C>();
let d = mem::take(args[3]).cast::<D>();
let mut a = args[0].write_lock::<A>().unwrap();
let a = &mut args[0].write_lock::<A>().unwrap();
func(&mut a, b, c, d).map(Dynamic::from)
func(a, b, c, d).map(Dynamic::from)
};
let arg_types = [
TypeId::of::<A>(),

View File

@@ -414,7 +414,8 @@ struct ParseState<'e> {
/// Tracks a list of external variables (variables that are not explicitly declared in the scope).
#[cfg(not(feature = "no_closure"))]
externals: HashMap<String, Position>,
/// An indicator that disables variable capturing into externals one single time.
/// An indicator that disables variable capturing into externals one single time
/// up until the nearest consumed Identifier token.
/// If set to false the next call to `access_var` will not capture the variable.
/// All consequent calls to `access_var` will not be affected
#[cfg(not(feature = "no_closure"))]
@@ -1637,6 +1638,11 @@ fn parse_primary(
// Function call
Token::Identifier(s) if *next_token == Token::LeftParen || *next_token == Token::Bang => {
// Once the identifier consumed we must enable next variables capturing
#[cfg(not(feature = "no_closure"))]
{
state.allow_capture = true;
}
Expr::Variable(Box::new(((s, settings.pos), None, 0, None)))
}
// Normal variable access