From 6890624f3db04b95be1ba10e83cf433d62a8df75 Mon Sep 17 00:00:00 2001 From: fluxionary <25628292+fluxionary@users.noreply.github.com> Date: Thu, 23 Feb 2023 08:16:35 -0800 Subject: [PATCH] Add option to disable printing inside a luacontroller (#633) Co-authored-by: DS --- mesecons_luacontroller/init.lua | 12 +++++++----- settingtypes.txt | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua index 2eba817..72bee24 100644 --- a/mesecons_luacontroller/init.lua +++ b/mesecons_luacontroller/init.lua @@ -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() diff --git a/settingtypes.txt b/settingtypes.txt index 5627440..688baf2 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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 actionstream. +# 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.