Make functions be able to call themselves
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-06-08 16:02:21 +02:00
parent 7d75131822
commit 7ed53193de
6 changed files with 49 additions and 29 deletions

View File

@@ -84,5 +84,24 @@ TEST_CASE( "Define script function and return", "[integration]" ) {
delete script;
}
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");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
script->CallFunction("add", {});
auto variable = script->GetVariable("val");
REQUIRE(variable->GetType()->GetClass() == TypeClass::Number);
REQUIRE(variable->EvaluateInteger() == 5);
delete script;
}
#endif