diff --git a/clientmods/turtle/tlang.lua b/clientmods/turtle/tlang.lua index d5ab0b14e..0db95b3aa 100644 --- a/clientmods/turtle/tlang.lua +++ b/clientmods/turtle/tlang.lua @@ -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 diff --git a/clientmods/turtle/tlang_vm.lua b/clientmods/turtle/tlang_vm.lua index 9ab8cc46f..39a5d0d08 100644 --- a/clientmods/turtle/tlang_vm.lua +++ b/clientmods/turtle/tlang_vm.lua @@ -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