forked from Mirrors/openclonk
Use a null C4ScriptHost to parse DirectExec code
This mostly makes Parse_Expression use the case for functions in proplists instead of the other for local variable lookup.liquid_container
parent
ac9106d197
commit
5bb3d7cb77
|
@ -1027,29 +1027,29 @@ C4Value C4AulExec::DirectExec(C4PropList *p, const char *szScript, const char *s
|
|||
#endif
|
||||
// profiler
|
||||
StartDirectExec();
|
||||
C4ScriptHost * script = &::GameScript;
|
||||
if (p == ::ScriptEngine.GetPropList())
|
||||
script = NULL;
|
||||
C4PropListStatic * script = ::GameScript.GetPropList();
|
||||
if (p && p->IsStatic())
|
||||
script = p->IsStatic();
|
||||
else if (p && p->GetDef())
|
||||
script = &p->GetDef()->Script;
|
||||
script = p->GetDef();
|
||||
// Add a new function
|
||||
C4AulScriptFunc *pFunc = new C4AulScriptFunc(script ? script->GetPropList() : p->IsStatic(), script, 0, szScript);
|
||||
auto pFunc = std::make_unique<C4AulScriptFunc>(script, nullptr, nullptr, szScript);
|
||||
// Parse function
|
||||
try
|
||||
{
|
||||
pFunc->ParseFn(context);
|
||||
C4Value vRetVal(Exec(pFunc, p, NULL, fPassErrors));
|
||||
delete pFunc; pFunc = 0;
|
||||
pFunc->ParseFn(&::ScriptEngine, context);
|
||||
C4Value vRetVal(Exec(pFunc.get(), p, NULL, fPassErrors));
|
||||
// profiler
|
||||
StopDirectExec();
|
||||
return vRetVal;
|
||||
}
|
||||
catch (C4AulError &ex)
|
||||
{
|
||||
delete pFunc;
|
||||
if(fPassErrors)
|
||||
throw;
|
||||
ex.show();
|
||||
LogCallStack();
|
||||
StopDirectExec();
|
||||
return C4VNull;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,11 +130,11 @@ public:
|
|||
iStack(0),
|
||||
pLoopStack(NULL)
|
||||
{ }
|
||||
C4AulParse(C4AulScriptFunc * Fn, C4AulScriptContext* context, enum Type Type):
|
||||
Fn(Fn), Host(Fn->pOrgScript), pOrgScript(Fn->pOrgScript), Engine(pOrgScript->Engine),
|
||||
C4AulParse(C4AulScriptFunc * Fn, C4AulScriptContext* context, C4AulScriptEngine *Engine):
|
||||
Fn(Fn), Host(NULL), pOrgScript(NULL), Engine(Engine),
|
||||
SPos(Fn->Script), TokenSPos(SPos),
|
||||
TokenType(ATT_INVALID),
|
||||
Type(Type),
|
||||
Type(C4AulParse::PARSER),
|
||||
ContextToExecIn(context),
|
||||
fJump(false),
|
||||
iStack(0),
|
||||
|
@ -1227,11 +1227,11 @@ void C4AulParse::UnexpectedToken(const char * Expected)
|
|||
throw C4AulParseError(this, FormatString("%s expected, but found %s", Expected, GetTokenName(TokenType)).getData());
|
||||
}
|
||||
|
||||
void C4AulScriptFunc::ParseFn(C4AulScriptContext* context)
|
||||
void C4AulScriptFunc::ParseFn(C4AulScriptEngine *Engine, C4AulScriptContext* context)
|
||||
{
|
||||
ClearCode();
|
||||
// parse
|
||||
C4AulParse state(this, context, C4AulParse::PARSER);
|
||||
C4AulParse state(this, context, Engine);
|
||||
state.Parse_DirectExec();
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public:
|
|||
C4AulScriptFunc(C4PropListStatic * Parent, const C4AulScriptFunc &FromFunc); // copy script/code, etc from given func
|
||||
~C4AulScriptFunc();
|
||||
|
||||
void ParseFn(C4AulScriptContext* context = NULL);
|
||||
void ParseFn(C4AulScriptEngine *Engine, C4AulScriptContext* context = NULL);
|
||||
|
||||
virtual bool GetPublic() const { return true; }
|
||||
virtual int GetParCount() const { return ParCount; }
|
||||
|
|
|
@ -81,9 +81,9 @@ TEST(DirectExecTest, HostUnmodifedByParseTest)
|
|||
TestHost host2 = host;
|
||||
host.test_equality(host2);
|
||||
char szScript[] = "8*5";
|
||||
C4AulScriptFunc *pFunc = new C4AulScriptFunc(host.GetPropList(), host.GetScriptHost(), 0, szScript);
|
||||
C4AulScriptFunc *pFunc = new C4AulScriptFunc(host.GetPropList(), nullptr, nullptr, szScript);
|
||||
host.test_equality(host2);
|
||||
pFunc->ParseFn();
|
||||
pFunc->ParseFn(&::ScriptEngine);
|
||||
host.test_equality(host2);
|
||||
delete pFunc;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue