mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-09-27 23:00:29 +02:00
Allow Luacontroller programs to request the use of lightweight interrupts
This commit is contained in:
parent
737f366741
commit
157bc1d6d0
|
@ -271,8 +271,9 @@ local get_interrupt
|
||||||
if mesecon.setting("luacontroller_lightweight_interrupts", false) then
|
if mesecon.setting("luacontroller_lightweight_interrupts", false) then
|
||||||
-- use node timer
|
-- use node timer
|
||||||
get_interrupt = function(pos, itbl, send_warning)
|
get_interrupt = function(pos, itbl, send_warning)
|
||||||
return (function(time, iid)
|
return (function(time, iid, lightweight)
|
||||||
if type(time) ~= "number" then error("Delay must be a number") end
|
if type(time) ~= "number" then error("Delay must be a number") end
|
||||||
|
if lightweight == false then error("Non-lightweight interrupts are disabled on this server") end
|
||||||
if iid ~= nil then send_warning("Interrupt IDs are disabled on this server") end
|
if iid ~= nil then send_warning("Interrupt IDs are disabled on this server") end
|
||||||
table.insert(itbl, function() minetest.get_node_timer(pos):start(time) end)
|
table.insert(itbl, function() minetest.get_node_timer(pos):start(time) end)
|
||||||
end)
|
end)
|
||||||
|
@ -282,10 +283,14 @@ else
|
||||||
-- itbl: Flat table of functions to run after sandbox cleanup, used to prevent various security hazards
|
-- itbl: Flat table of functions to run after sandbox cleanup, used to prevent various security hazards
|
||||||
get_interrupt = function(pos, itbl, send_warning)
|
get_interrupt = function(pos, itbl, send_warning)
|
||||||
-- iid = interrupt id
|
-- iid = interrupt id
|
||||||
local function interrupt(time, iid)
|
local function interrupt(time, iid, lightweight)
|
||||||
-- NOTE: This runs within string metatable sandbox, so don't *rely* on anything of the form (""):y
|
-- NOTE: This runs within string metatable sandbox, so don't *rely* on anything of the form (""):y
|
||||||
-- Hence the values get moved out. Should take less time than original, so totally compatible
|
-- Hence the values get moved out. Should take less time than original, so totally compatible
|
||||||
if type(time) ~= "number" then error("Delay must be a number") end
|
if type(time) ~= "number" then error("Delay must be a number") end
|
||||||
|
if lightweight then
|
||||||
|
if iid ~= nil then send_warning("Interrupt IDs cannot be used with lightweight interrupts") end
|
||||||
|
table.insert(itbl, function() minetest.get_node_timer(pos):start(time) end)
|
||||||
|
else
|
||||||
table.insert(itbl, function ()
|
table.insert(itbl, function ()
|
||||||
-- Outside string metatable sandbox, can safely run this now
|
-- Outside string metatable sandbox, can safely run this now
|
||||||
local luac_id = minetest.get_meta(pos):get_int("luac_id")
|
local luac_id = minetest.get_meta(pos):get_int("luac_id")
|
||||||
|
@ -301,6 +306,7 @@ else
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return interrupt
|
return interrupt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user