Rework function evaluation scope to handle tables
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -86,13 +86,15 @@ TEST_CASE( "Define script function and return", "[integration]" ) {
|
||||
|
||||
TEST_CASE( "Functions can call themselves", "[integration]" ) {
|
||||
Script* script = Script::Create(
|
||||
"val = 0\n"
|
||||
"function add() \n"
|
||||
"if val < 5 then\n"
|
||||
"val = val + 1\n"
|
||||
"add()\n"
|
||||
"end\n"
|
||||
"end");
|
||||
R"(
|
||||
val = 0
|
||||
function add()
|
||||
if val < 5 then
|
||||
val = val + 1
|
||||
add()
|
||||
end
|
||||
end
|
||||
)");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
script->CallFunction("add", {});
|
||||
|
||||
@@ -62,6 +62,24 @@ table = {
|
||||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE( "Complex table with function", "[integration]" ) {
|
||||
Script* script = Script::Create(
|
||||
R"(
|
||||
table = {
|
||||
local foo = 'test'
|
||||
function getFoo()
|
||||
return foo
|
||||
end
|
||||
}
|
||||
result = table["getFoo"]()
|
||||
)");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
auto variable = script->GetVariable("result");
|
||||
REQUIRE(variable != nullptr);
|
||||
delete script;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user