From 5919f432aee78178d61551881e1644b48b561202 Mon Sep 17 00:00:00 2001 From: 1F616EMO~nya Date: Wed, 3 Jul 2024 13:34:18 +0800 Subject: [PATCH] Remove extra `print()` calls and copy Luacontroller's print behavior (#127) --- autoplace_pipes.lua | 2 +- settingtypes.txt | 4 ++++ tubes/lua.lua | 14 ++++++++------ wielder.lua | 1 - 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/autoplace_pipes.lua b/autoplace_pipes.lua index ec4b27e..fc3d7d0 100644 --- a/autoplace_pipes.lua +++ b/autoplace_pipes.lua @@ -211,7 +211,7 @@ function pipeworks.scan_pipe_surroundings(pos) pzm = 1 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)) return pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp end diff --git a/settingtypes.txt b/settingtypes.txt index 6d8e3ad..8508892 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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. 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 diff --git a/tubes/lua.lua b/tubes/lua.lua index 7a76fe9..ec09829 100644 --- a/tubes/lua.lua +++ b/tubes/lua.lua @@ -229,11 +229,13 @@ end ------------------------- local function safe_print(param) - local string_meta = getmetatable("") - local sandbox = string_meta.__index - string_meta.__index = string -- Leave string sandbox temporarily - print(dump(param)) - string_meta.__index = sandbox -- Restore string sandbox + if (minetest.settings:get("pipeworks_lua_tube_print_behavior") or "log") == "log" then + local string_meta = getmetatable("") + local sandbox = string_meta.__index + string_meta.__index = string -- Leave string sandbox temporarily + minetest.log("action", string.format("[pipeworks.tubes.lua] print(%s)", dump(param))) + string_meta.__index = sandbox -- Restore string sandbox + end end local function safe_date() @@ -603,7 +605,7 @@ local function save_memory(pos, meta, mem) meta:set_string("lc_memory", memstring) meta:mark_as_private("lc_memory") 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.") burn_controller(pos) end diff --git a/wielder.lua b/wielder.lua index ef26a97..00dc6b7 100644 --- a/wielder.lua +++ b/wielder.lua @@ -281,7 +281,6 @@ if pipeworks.enable_node_breaker then -- Don't mechanically wear out tool 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 - print("replaced") fakeplayer:set_wielded_item(old_stack) end elseif not stack:is_empty() then