From a6198ddf1bb0cec6c9f4b2ece0e4a06929ca1097 Mon Sep 17 00:00:00 2001 From: twanvl Date: Wed, 21 Jul 2010 16:35:23 +0000 Subject: [PATCH] correct scope handling for closures, this was broken after the change to not make calls open a scope. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1444 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/script/context.cpp | 5 +++-- src/script/value.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/script/context.cpp b/src/script/context.cpp index 54f4f7d9..88c601a9 100644 --- a/src/script/context.cpp +++ b/src/script/context.cpp @@ -144,7 +144,8 @@ ScriptValueP Context::eval(const Script& script, bool useScope) { : (Variable)-1; Profiler prof(timer, function); #endif - // get function and call + // get function and call. + // there is no need to open a new scope for this function, since we already did so for the arguments stack.back() = stack.back()->eval(*this, false); // finish profiling #if USE_SCRIPT_PROFILING @@ -387,7 +388,7 @@ class ScriptCompose : public ScriptValue { // execute b Variable fun = ctx.lookupVariableValue(b); Profiler prof(timer,fun); - return b->eval(ctx); + return b->eval(ctx, openScope); } #else // Always open a scope for a; variables it makes need to be diff --git a/src/script/value.cpp b/src/script/value.cpp index afa9de15..9961ae4e 100644 --- a/src/script/value.cpp +++ b/src/script/value.cpp @@ -527,7 +527,8 @@ ScriptValueP ScriptClosure::dependencies(Context& ctx, const Dependency& dep) co } void ScriptClosure::applyBindings(Context& ctx) const { FOR_EACH_CONST(b, bindings) { - if (ctx.getVariableScope(b.first) != 1) { + if (ctx.getVariableScope(b.first) != 0) { + // variables passed as arguments (i.e. in scope 0) override these default bindings ctx.setVariable(b.first, b.second); } }