add option to disable printing inside a luacontroller

This commit is contained in:
flux 2023-02-19 15:34:01 -08:00
parent 2589b391e5
commit 9777a259e0
No known key found for this signature in database
GPG Key ID: 9333B27816848A15
2 changed files with 11 additions and 5 deletions

View File

@ -203,11 +203,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 mesecon.setting("luacontroller_print_behavior", "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("[mesecons_luacontroller] print(%s)", dump(param)))
string_meta.__index = sandbox -- Restore string sandbox
end
end
local function safe_date()

View File

@ -28,6 +28,10 @@ mesecon.luacontroller_memsize (Controller memory limit) int 100000 10000 1000000
# IID is ignored and at most one interrupt may be queued if this setting is enabled.
mesecon.luacontroller_lightweight_interrupts (Lightweight interrupts) bool false
# behavior of "print" inside a luacontroller. by default, this emits a message into debug.txt.
# set it to noop if you wish to disable that behavior.
mesecon.luacontroller_print_behavior (behavior of print) enum log log,noop
[mesecons_mvps]
# In pre-existing world, MVPS may not be labelled with the owner.