turtle: fix tlang integration

This commit is contained in:
cron 2020-11-05 19:53:35 +00:00 committed by Schmappie Eldress
parent 16fafaa193
commit 632eb7e286
2 changed files with 26 additions and 15 deletions

View File

@ -278,25 +278,32 @@ minetest.register_chatcommand("quarry", {
turtle.states = {}
turtle.states_available = false
function turtle.schedule(name, state)
turtle.states[#turtle.states] = {name = name, state = state}
turtle.states[#turtle.states + 1] = {name = name, state = state}
turtle.states_available = true
end
function turtle.run_states()
local dead = {}
for i, v in ipairs(turtle.states) do
local ret = tlang.step(v.state)
if ret ~= true then
if type(ret) == "string" then
minetest.display_chat_message("Turtle/tlang ERROR in " .. v.name .. ": " .. ret)
end
dead[#dead] = i
end
end
function turtle.run_states(dtime)
if turtle.states_available then
local dead = {}
for i, v in ipairs(dead) do
table.remove(turtle.states, v)
for i, v in ipairs(turtle.states) do
local ret = tlang.step(v.state)
if ret ~= true then
if type(ret) == "string" then
minetest.display_chat_message("Turtle/tlang ERROR in " .. v.name .. ": " .. ret)
end
dead[#dead + 1] = i
end
end
for i, v in ipairs(dead) do
table.remove(turtle.states, v)
end
turtle.states_available = #turtle.states ~= 0
end
end

View File

@ -292,7 +292,11 @@ end
function builtins.print(state)
local value = statepop(state)
print(value.value)
if minetest then
minetest.display_chat_message("Tlang: " .. tostring(value.value))
else
print(value.value)
end
end
function builtins.dup(state)