Rework function evaluation scope to handle tables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-12 17:56:47 +02:00
parent c022c91777
commit 3477ddd18c
7 changed files with 57 additions and 30 deletions

View File

@@ -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", {});

View File

@@ -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