Remove extra print() calls and copy Luacontroller's print behavior (#127)

This commit is contained in:
1F616EMO~nya 2024-07-03 13:34:18 +08:00 committed by GitHub
parent 71fe60014f
commit 5919f432ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 8 deletions

View File

@ -211,7 +211,7 @@ function pipeworks.scan_pipe_surroundings(pos)
pzm = 1 pzm = 1
end end
print("stage 2 returns "..pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp.. minetest.log("info", "stage 2 returns "..pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp..
" for nodes surrounding "..minetest.get_node(pos).name.." at "..minetest.pos_to_string(pos)) " for nodes surrounding "..minetest.get_node(pos).name.." at "..minetest.pos_to_string(pos))
return pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp return pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp
end end

View File

@ -87,3 +87,7 @@ pipeworks_entity_update_interval (Entity Update Interval) float 0 0 0.8
# if set to true, items passing through teleport tubes will log log where they came from and where they went. # if set to true, items passing through teleport tubes will log log where they came from and where they went.
pipeworks_log_teleport_tubes (Log Teleport Tubes) bool false pipeworks_log_teleport_tubes (Log Teleport Tubes) bool false
# Behavior of print() inside a lua tube. By default, this emits a message into actionstream.
# Set it to noop if you wish to disable that behavior.
pipeworks_lua_tube_print_behavior (Behavior of print in Lua Tube) enum log log,noop

View File

@ -229,12 +229,14 @@ end
------------------------- -------------------------
local function safe_print(param) local function safe_print(param)
if (minetest.settings:get("pipeworks_lua_tube_print_behavior") or "log") == "log" then
local string_meta = getmetatable("") local string_meta = getmetatable("")
local sandbox = string_meta.__index local sandbox = string_meta.__index
string_meta.__index = string -- Leave string sandbox temporarily string_meta.__index = string -- Leave string sandbox temporarily
print(dump(param)) minetest.log("action", string.format("[pipeworks.tubes.lua] print(%s)", dump(param)))
string_meta.__index = sandbox -- Restore string sandbox string_meta.__index = sandbox -- Restore string sandbox
end end
end
local function safe_date() local function safe_date()
return(os.date("*t",os.time())) return(os.date("*t",os.time()))
@ -603,7 +605,7 @@ local function save_memory(pos, meta, mem)
meta:set_string("lc_memory", memstring) meta:set_string("lc_memory", memstring)
meta:mark_as_private("lc_memory") meta:mark_as_private("lc_memory")
else else
print("Error: lua_tube memory overflow. "..memsize_max.." bytes available, " minetest.log("info", "lua_tube memory overflow. "..memsize_max.." bytes available, "
..#memstring.." required. Controller overheats.") ..#memstring.." required. Controller overheats.")
burn_controller(pos) burn_controller(pos)
end end

View File

@ -281,7 +281,6 @@ if pipeworks.enable_node_breaker then
-- Don't mechanically wear out tool -- Don't mechanically wear out tool
if stack:get_wear() ~= old_stack:get_wear() and stack:get_count() == old_stack:get_count() if stack:get_wear() ~= old_stack:get_wear() and stack:get_count() == old_stack:get_count()
and (item_def.wear_represents == nil or item_def.wear_represents == "mechanical_wear") then and (item_def.wear_represents == nil or item_def.wear_represents == "mechanical_wear") then
print("replaced")
fakeplayer:set_wielded_item(old_stack) fakeplayer:set_wielded_item(old_stack)
end end
elseif not stack:is_empty() then elseif not stack:is_empty() then