turtle: add tlang scheduler

This commit is contained in:
cron 2020-11-05 19:11:17 +00:00
parent 91ef7215e7
commit 4c94ff4390
2 changed files with 36 additions and 3 deletions

View File

@ -2,6 +2,9 @@
turtle = {}
local mod_prefix = minetest.get_modpath(minetest.get_current_modname())
tlang = dofile(mod_prefix .. "/tlang.lua")
local iter = {}
local iter_storage = {}
@ -374,3 +377,28 @@ minetest.register_chatcommand("quarry", {
end
})
turtle.states = {}
function turtle.schedule(name, state)
turtle.states[#turtle.states] = {name = name, state = state}
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
for i, v in ipairs(dead) do
table.remove(turtle.states, v)
end
end
minetest.register_globalstep(turtle.run_states)

View File

@ -1,8 +1,13 @@
local tlang = {}
tlang.lex = dofile("tlang_lex.lua")
tlang.parse = dofile("tlang_parse.lua")
tlang.builtins, tlang.gassign, tlang.step = dofile("tlang_vm.lua")
local prefix = ""
if minetest ~= nil then
prefix = minetest.get_modpath(minetest.get_current_modname()) .. "/"
end
tlang.lex = dofile(prefix .. "tlang_lex.lua")
tlang.parse = dofile(prefix .. "tlang_parse.lua")
tlang.builtins, tlang.gassign, tlang.step = dofile(prefix .. "tlang_vm.lua")
-- TODO
--[[