turtle: fix tlang integration
This commit is contained in:
parent
16fafaa193
commit
632eb7e286
@ -278,26 +278,33 @@ minetest.register_chatcommand("quarry", {
|
|||||||
|
|
||||||
|
|
||||||
turtle.states = {}
|
turtle.states = {}
|
||||||
|
turtle.states_available = false
|
||||||
|
|
||||||
function turtle.schedule(name, state)
|
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
|
end
|
||||||
|
|
||||||
function turtle.run_states()
|
function turtle.run_states(dtime)
|
||||||
|
if turtle.states_available then
|
||||||
local dead = {}
|
local dead = {}
|
||||||
|
|
||||||
for i, v in ipairs(turtle.states) do
|
for i, v in ipairs(turtle.states) do
|
||||||
local ret = tlang.step(v.state)
|
local ret = tlang.step(v.state)
|
||||||
if ret ~= true then
|
if ret ~= true then
|
||||||
if type(ret) == "string" then
|
if type(ret) == "string" then
|
||||||
minetest.display_chat_message("Turtle/tlang ERROR in " .. v.name .. ": " .. ret)
|
minetest.display_chat_message("Turtle/tlang ERROR in " .. v.name .. ": " .. ret)
|
||||||
end
|
end
|
||||||
dead[#dead] = i
|
dead[#dead + 1] = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, v in ipairs(dead) do
|
for i, v in ipairs(dead) do
|
||||||
table.remove(turtle.states, v)
|
table.remove(turtle.states, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
turtle.states_available = #turtle.states ~= 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(turtle.run_states)
|
minetest.register_globalstep(turtle.run_states)
|
||||||
|
@ -292,8 +292,12 @@ end
|
|||||||
function builtins.print(state)
|
function builtins.print(state)
|
||||||
local value = statepop(state)
|
local value = statepop(state)
|
||||||
|
|
||||||
|
if minetest then
|
||||||
|
minetest.display_chat_message("Tlang: " .. tostring(value.value))
|
||||||
|
else
|
||||||
print(value.value)
|
print(value.value)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function builtins.dup(state)
|
function builtins.dup(state)
|
||||||
statepush(state, statepeek(state))
|
statepush(state, statepeek(state))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user