Added error checking for using a local variable in global scope, and added optimization to method object parameter.

This commit is contained in:
Jeff Hutchinson 2021-04-17 14:31:27 -04:00
parent bfc0109485
commit bb12638ea5
2 changed files with 25 additions and 10 deletions

View file

@ -1682,7 +1682,16 @@ ConsoleValue CodeBlock::exec(U32 ip, const char* functionName, Namespace* thisNa
if (simObjectLookupValue.getType() == ConsoleValueType::cvInteger)
gEvalState.thisObject = Sim::findObject(static_cast<SimObjectId>(simObjectLookupValue.getInt()));
else
gEvalState.thisObject = Sim::findObject(simObjectLookupValue.getString());
{
SimObject *foundObject = Sim::findObject(simObjectLookupValue.getString());
// Optimization: If we're not an integer, let's make it so that the fast path exists
// on the first argument of the method call (speeds up future usage of %this, for example)
if (foundObject != NULL)
callArgv[1].setInt(static_cast<S64>(foundObject->getId()));
gEvalState.thisObject = foundObject;
}
if (gEvalState.thisObject == NULL)
{