turtle/tlang: add else to if, fix end of scope error

This commit is contained in:
cron 2020-11-06 17:06:32 +00:00 committed by Schmappie Eldress
parent 4be2c31314
commit 88c675193a
2 changed files with 34 additions and 1 deletions

View File

@ -157,7 +157,29 @@ local function test()
1 2 test
]]
tlang.exec(repeat_test)
local ifelse_test = [[
{
{
'if' print
} {
'else' print
} if
} `ifprint =
1 ifprint
0 ifprint
]]
local nest_run = [[
{
{
'innermost' print
} run
} run
'work' print
]]
tlang.exec(ifelse_test)
end
if minetest == nil then

View File

@ -190,6 +190,8 @@ local function getnext(state)
if pc.sg == 0 then
state.code_stack[pc.pos] = nil
end
return getnext(state)
end
local current
@ -355,6 +357,15 @@ tlang.builtins["if"] = function(state)
tlang.push_raw(state, tos)
tlang.call_tos(state)
end
elseif tos1.type == "code" then
local tos2 = statepop_num(state)
if tos2.value ~= 0 then
tlang.push_raw(state, tos1)
tlang.call_tos(state)
else
tlang.push_raw(state, tos)
tlang.call_tos(state)
end
end
end