mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
Fix foreach over non-existant objects
This commit is contained in:
parent
f405666cbc
commit
c6047b24eb
2 changed files with 41 additions and 0 deletions
|
|
@ -2121,6 +2121,8 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi
|
||||||
Con::errorf(ConsoleLogEntry::General, "No SimSet object '%s'", stack[_STK].getString());
|
Con::errorf(ConsoleLogEntry::General, "No SimSet object '%s'", stack[_STK].getString());
|
||||||
Con::errorf(ConsoleLogEntry::General, "Did you mean to use 'foreach$' instead of 'foreach'?");
|
Con::errorf(ConsoleLogEntry::General, "Did you mean to use 'foreach$' instead of 'foreach'?");
|
||||||
ip = failIp;
|
ip = failIp;
|
||||||
|
// Pop the iterated value
|
||||||
|
_STK--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -540,6 +540,45 @@ TEST_F(ScriptTest, ForEachLoop)
|
||||||
)");
|
)");
|
||||||
|
|
||||||
ASSERT_EQ(forEachNestedReturn.getInt(), 42);
|
ASSERT_EQ(forEachNestedReturn.getInt(), 42);
|
||||||
|
|
||||||
|
|
||||||
|
ConsoleValue forEachNonExistantObject = RunScript(R"(
|
||||||
|
$counter = 0;
|
||||||
|
foreach ($obj in NonExistantSimSet)
|
||||||
|
{
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $counter;
|
||||||
|
)");
|
||||||
|
|
||||||
|
ASSERT_EQ(forEachNonExistantObject.getInt(), 0);
|
||||||
|
|
||||||
|
|
||||||
|
ConsoleValue forEachOnZero = RunScript(R"(
|
||||||
|
$counter = 0;
|
||||||
|
foreach ($obj in 0)
|
||||||
|
{
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $counter;
|
||||||
|
)");
|
||||||
|
|
||||||
|
ASSERT_EQ(forEachOnZero.getInt(), 0);
|
||||||
|
|
||||||
|
|
||||||
|
ConsoleValue forEachOnEmptyString = RunScript(R"(
|
||||||
|
$counter = 0;
|
||||||
|
foreach ($obj in "")
|
||||||
|
{
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $counter;
|
||||||
|
)");
|
||||||
|
|
||||||
|
ASSERT_EQ(forEachOnEmptyString.getInt(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ScriptTest, TorqueScript_Array_Testing)
|
TEST_F(ScriptTest, TorqueScript_Array_Testing)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue