buttery inventory bug fix

server cleanup bug fix
SaferLua extension for coroutine controllers to come...
This commit is contained in:
Joachim Stolberg 2018-07-07 13:16:35 +02:00
parent f414f7d9ac
commit 77f5c86e54
3 changed files with 42 additions and 7 deletions

@ -73,6 +73,9 @@ local function compile(pos, text, label, err_clbk)
end end
end end
-------------------------------------------------------------------------------
-- Standard init/loop controller
-------------------------------------------------------------------------------
function safer_lua.init(pos, init, loop, environ, err_clbk) function safer_lua.init(pos, init, loop, environ, err_clbk)
if #init > safer_lua.MaxCodeSize then if #init > safer_lua.MaxCodeSize then
err_clbk(pos, "init() Code size limit exceeded") err_clbk(pos, "init() Code size limit exceeded")
@ -124,3 +127,33 @@ function safer_lua.run_loop(pos, elapsed, code, err_clbk)
end end
return true return true
end end
-------------------------------------------------------------------------------
-- Endless/Coroutine controller
-------------------------------------------------------------------------------
local function thread(code)
while true do
code()
local env = getfenv(code)
if calc_used_mem_size(env) > safer_lua.MaxTableSize then
err_clbk("Memory limit exceeded")
return false
end
coroutine.yield()
end
end
function safer_lua.co_create(pos, init, loop, environ, err_clbk)
local code = safer_lua.init(pos, init, loop, environ, err_clbk)
return coroutine.create(thread), code
end
function safer_lua.co_resume(pos, co, code, err_clbk)
local res, err = coroutine.resume(co, code)
if not res then
err = err:gsub("%[string .+%]:", "loop() ")
err_clbk(pos, err)
return false
end
return true
end

@ -31,7 +31,7 @@ local function on_timer(pos, elapsed)
return true return true
end end
local function register_battery(ext, percent) local function register_battery(ext, percent, nici)
minetest.register_node("sl_controller:battery"..ext, { minetest.register_node("sl_controller:battery"..ext, {
description = "Battery "..ext, description = "Battery "..ext,
inventory_image = 'sl_controller_battery_inventory.png', inventory_image = 'sl_controller_battery_inventory.png',
@ -90,17 +90,17 @@ local function register_battery(ext, percent)
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {choppy=1, cracky=1, crumbly=1}, groups = {choppy=1, cracky=1, crumbly=1, not_in_creative_inventory=nici},
drop = "", drop = "",
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
}) })
end end
register_battery("", 1.0) register_battery("", 1.0, 0)
register_battery("75", 0.75) register_battery("75", 0.75, 1)
register_battery("50", 0.5) register_battery("50", 0.5, 1)
register_battery("25", 0.25) register_battery("25", 0.25, 1)
minetest.register_node("sl_controller:battery_empty", { minetest.register_node("sl_controller:battery_empty", {
description = "Battery", description = "Battery",

@ -73,7 +73,9 @@ minetest.register_node("sl_controller:server", {
if minetest.is_protected(pos, puncher:get_player_name()) then if minetest.is_protected(pos, puncher:get_player_name()) then
return return
end end
local meta = minetest.get_meta(pos)
local number = meta:get_string("number")
tubelib.set_data(number, "memory", nil)
minetest.node_dig(pos, node, puncher, pointed_thing) minetest.node_dig(pos, node, puncher, pointed_thing)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,