From 440dae68a11d1c3dcfaca7d5443fcb3a2009124c Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:13:22 -0700 Subject: [PATCH 01/12] Notify.suppress_for_function now actually returns results! --- worldeditadditions_core/utils/notify/notify.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worldeditadditions_core/utils/notify/notify.lua b/worldeditadditions_core/utils/notify/notify.lua index 6d63024..8a8ed0d 100644 --- a/worldeditadditions_core/utils/notify/notify.lua +++ b/worldeditadditions_core/utils/notify/notify.lua @@ -153,8 +153,9 @@ function Notify.suppress_for_function(name, func) -- If the player is already suppressed, cancel it unless it's a function if not check_clear_suppressed(name, suppress) then return false end suppress[name] = func - suppress[name]() + local success, result = suppress[name]() suppress[name] = nil + return success, result end --- WorldEdit compatibility From 644510a9caec390ffec511e6a96fdc361df98f38 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:22:09 -0700 Subject: [PATCH 02/12] documentation redo... again --- .../utils/notify/notify.lua | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/worldeditadditions_core/utils/notify/notify.lua b/worldeditadditions_core/utils/notify/notify.lua index 8a8ed0d..aa28e2a 100644 --- a/worldeditadditions_core/utils/notify/notify.lua +++ b/worldeditadditions_core/utils/notify/notify.lua @@ -60,10 +60,10 @@ end --- Send a notification of type `ntype` (for metatable). -- (Same as `Notify[ntype](name, message)`) --- @param table _self Provided automatically by Lua. You do not need to set this automatically - see example. --- @param string name The name of the player to send the notification to. --- @param string ntype The type of notification. --- @param string message The message to send. +-- @param _self table Provided automatically by Lua. You do not need to set this automatically - see example. +-- @param name string The name of the player to send the notification to. +-- @param ntype string The type of notification. +-- @param message string The message to send. -- @return table The Notify instance. -- @example Basic usage -- worldeditadditions_core.notify(player_name, "info", "All registered commands:\n....") @@ -80,11 +80,11 @@ end setmetatable(Notify, {__call = call}) --- Send a custom notification. --- @param string name The name of the player to send the notification to. --- @param string ntype The type of notification. --- @param string message The message to send. --- @param string? colour Optional. The colour of the notification. --- @param boolean? message_coloured Optional. Whether the message should be coloured. +-- @param name string The name of the player to send the notification to. +-- @param ntype string The type of notification. +-- @param message string The message to send. +-- @param colour string? Optional. The colour of the notification. +-- @param message_coloured boolean? Optional. Whether the message should be coloured. -- @return boolean True if all parameters are valid, false otherwise. -- @example Custom notification types -- Notify.custom(name, "custom", "This one is magenta!", "#FF00FF", true) @@ -96,8 +96,8 @@ end --- Register the aforementioned predefined notification types. --- @param string name The name of the player to send the notification to. --- @param string message The message to send. +-- @param name string The name of the player to send the notification to. +-- @param message string The message to send. -- @example -- Notify.error(name, "multi-line error!\n" .. debug.traceback()) -- Notify.warn(name, "This is the last coloured message type!") @@ -118,8 +118,8 @@ do end --- Local suppression status handler --- @param string name The name of the player to check. --- @param table suppress The table of suppressed players. +-- @param name string The name of the player to check. +-- @param suppress table The table of suppressed players. -- @return boolean True if the player is not suppressed or -- if the player is clear(ed), false otherwise. local check_clear_suppressed = function(name, suppress) @@ -133,8 +133,8 @@ local check_clear_suppressed = function(name, suppress) end --- Suppress a player's notifications. --- @param string name The name of the player to suppress. --- @param number > 1 time The number of seconds to suppress notifications for. +-- @param name string The name of the player to suppress. +-- @param time number > 1 The number of seconds to suppress notifications for. -- number < 1 immediately removes the suppression. function Notify.suppress_for_player(name, time) local suppress = globalstate.suppressed_players @@ -148,6 +148,9 @@ function Notify.suppress_for_player(name, time) end --- Suppress a player's notifications while function executes. +-- @param name string The name of the player to suppress. +-- @param func function The function to execute while the player is suppressed. +-- @returns bool, string Success, result of the executed function. function Notify.suppress_for_function(name, func) local suppress = globalstate.suppressed_players -- If the player is already suppressed, cancel it unless it's a function From c86319d94ef778a896c32bc96f8e467ebe0e84ba Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:22:34 -0700 Subject: [PATCH 03/12] wea_c.notify main changeover --- .../commands/meta/listentities.lua | 8 ++++---- worldeditadditions_commands/commands/meta/macro.lua | 2 +- worldeditadditions_commands/commands/meta/many.lua | 4 ++-- worldeditadditions_commands/commands/meta/multi.lua | 4 ++-- worldeditadditions_commands/commands/selectors/pos1-2.lua | 2 +- worldeditadditions_commands/commands/selectors/scloud.lua | 2 +- worldeditadditions_commands/commands/selectors/unmark.lua | 2 +- worldeditadditions_core/core/safe_function.lua | 2 +- worldeditadditions_core/core/safe_region.lua | 7 ++++--- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/worldeditadditions_commands/commands/meta/listentities.lua b/worldeditadditions_commands/commands/meta/listentities.lua index 538b964..46fe163 100644 --- a/worldeditadditions_commands/commands/meta/listentities.lua +++ b/worldeditadditions_commands/commands/meta/listentities.lua @@ -1,6 +1,6 @@ -- Lists all currently loaded entities. -local weac = worldeditadditions_core +local wea_c = worldeditadditions_core minetest.register_chatcommand("/listentities", { params = "", @@ -22,16 +22,16 @@ minetest.register_chatcommand("/listentities", { obj_name = "[LuaEntity:__UNKNOWN__]" end end - local pos = weac.Vector3.clone(obj:get_pos()) + local pos = wea_c.Vector3.clone(obj:get_pos()) table.insert(table_vals, { id, obj_name, tostring(pos) }) end - worldedit.player_notify(name, table.concat({ + wea_c.notify.info(name, table.concat({ "Currently loaded entities:", - weac.format.make_ascii_table(table_vals), + wea_c.format.make_ascii_table(table_vals), "", "Total "..tostring(#table_vals).." objects" }, "\n")) diff --git a/worldeditadditions_commands/commands/meta/macro.lua b/worldeditadditions_commands/commands/meta/macro.lua index 62ff894..35b4ec5 100644 --- a/worldeditadditions_commands/commands/meta/macro.lua +++ b/worldeditadditions_commands/commands/meta/macro.lua @@ -41,7 +41,7 @@ local function step(params) -- If we haven't run out of values call function again minetest.after(params.delay, step, params) -- Time is in seconds else - worldedit.player_notify(params.player_name, "The macro \"".. + wea_c.notify.ok(params.player_name, "The macro \"".. params.file.."\" was completed in " .. wea_c.format.human_time(params.time)) end diff --git a/worldeditadditions_commands/commands/meta/many.lua b/worldeditadditions_commands/commands/meta/many.lua index 53b7f30..bcc7e10 100644 --- a/worldeditadditions_commands/commands/meta/many.lua +++ b/worldeditadditions_commands/commands/meta/many.lua @@ -7,7 +7,7 @@ local function step(params) local start_time = wea_c.get_ms_time() local full_cmd = params.cmd_name.." "..params.args - worldedit.player_notify(params.name, string.format("[ many | /%s ] %d / %d (~%.2f%%) complete | last: %s, average: %s, ETA: ~%s", + wea_c.notify.info(params.name, string.format("[ many | /%s ] %d / %d (~%.2f%%) complete | last: %s, average: %s, ETA: ~%s", full_cmd, (params.i + 1), params.count, ((params.i + 1) / params.count)*100, @@ -53,7 +53,7 @@ local function step(params) table.insert(done_message, table.concat(message_parts, ", ")) end table.insert(done_message, ")") - worldedit.player_notify(params.name, table.concat(done_message, "")) + wea_c.notify.ok(params.name, table.concat(done_message, "")) end end diff --git a/worldeditadditions_commands/commands/meta/multi.lua b/worldeditadditions_commands/commands/meta/multi.lua index 8e70755..4dfbf42 100644 --- a/worldeditadditions_commands/commands/meta/multi.lua +++ b/worldeditadditions_commands/commands/meta/multi.lua @@ -29,7 +29,7 @@ minetest.register_chatcommand("/multi", { if not args then args = "" end -- print("command_name", command_name) - worldedit.player_notify(name, "#"..i..": "..command) + wea_c.notify.info(name, "#"..i..": "..command) local cmd = minetest.registered_chatcommands[command_name] if not cmd then @@ -61,6 +61,6 @@ minetest.register_chatcommand("/multi", { table.insert(done_message, table.concat(message_parts, ", ")) table.insert(done_message, ")") - worldedit.player_notify(name, table.concat(done_message, "")) + wea_c.notify.ok(name, table.concat(done_message, "")) end }) diff --git a/worldeditadditions_commands/commands/selectors/pos1-2.lua b/worldeditadditions_commands/commands/selectors/pos1-2.lua index 44c2732..d8e00e0 100644 --- a/worldeditadditions_commands/commands/selectors/pos1-2.lua +++ b/worldeditadditions_commands/commands/selectors/pos1-2.lua @@ -53,7 +53,7 @@ minetest.register_chatcommand("//pos", { func = function(name, params_text) local i = tonumber(params_text) if type(i) ~= "number" then - worldedit.player_notify(name, "Error: Invalid index number given.") + weac.notify.error(name, "Error: Invalid index number given.") return end i = math.floor(i) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index 07289b1..6dc75a9 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -13,7 +13,7 @@ minetest.register_on_punchnode(function(pos, node, puncher) if wea.add_pos[name] > 0 then wea.selection.add_point(name, pos) wea.add_pos[name] = wea.add_pos[name] - 1 - worldedit.player_notify(name, "You have "..wea.add_pos[name].." nodes left to punch") + wea_c.notify.info(name, "You have "..wea.add_pos[name].." nodes left to punch") else wea.add_pos[name] = nil end end end) diff --git a/worldeditadditions_commands/commands/selectors/unmark.lua b/worldeditadditions_commands/commands/selectors/unmark.lua index 90ac999..0c72e3b 100644 --- a/worldeditadditions_commands/commands/selectors/unmark.lua +++ b/worldeditadditions_commands/commands/selectors/unmark.lua @@ -28,7 +28,7 @@ local function do_unmark(name, params_text) if params_text == "all" then local removed = do_unmark_all() - worldedit.player_notify(name, "Hidden "..removed.." marker entities") + weac.notify.info(name, "Hidden "..removed.." marker entities") else -- Hide the WorldEditAdditions marker weac.pos.unmark(name) diff --git a/worldeditadditions_core/core/safe_function.lua b/worldeditadditions_core/core/safe_function.lua index 150e4fb..e6aa688 100644 --- a/worldeditadditions_core/core/safe_function.lua +++ b/worldeditadditions_core/core/safe_function.lua @@ -57,7 +57,7 @@ Please add any other additional specific system information here too if you thin }, "") print("DEBUG:player_notify player_name", player_name, "msg_compiled", msg_compiled) - worldedit.player_notify(player_name, msg_compiled) + weac.notify.error(player_name, msg_compiled) end diff --git a/worldeditadditions_core/core/safe_region.lua b/worldeditadditions_core/core/safe_region.lua index e85b011..2d5bc7b 100644 --- a/worldeditadditions_core/core/safe_region.lua +++ b/worldeditadditions_core/core/safe_region.lua @@ -5,6 +5,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ███████ ██ ██ ███████ ██████ ██ ██████ ██ ████ +local weac = worldeditadditions_core --- -- @module worldeditadditions_core local worldedit_command_y, worldedit_command_n @@ -41,7 +42,7 @@ minetest.override_chatcommand("/y", { if minetest.global_exists("worldedit") and worldedit_command_y ~= nil then worldedit_command_y(player_name) else - worldedit.player_notify(player_name, "There aren't any pending operations at the moment.") + weac.notify.info(player_name, "There aren't any pending operations at the moment.") end else pending_calls[player_name].func() @@ -58,10 +59,10 @@ minetest.override_chatcommand("/n", { if minetest.global_exists("worldedit") and worldedit_command_y ~= nil then worldedit_command_n(player_name) else - worldedit.player_notify(player_name, "There aren't any operations pending, so there's nothing to abort.") + weac.notify.info(player_name, "There aren't any operations pending, so there's nothing to abort.") end else - worldedit.player_notify(player_name, "Aborting captured command /"..pending_calls[player_name].cmdname..".") + weac.notify.info(player_name, "Aborting captured command /"..pending_calls[player_name].cmdname..".") pending_calls[player_name] = nil end end From 63bdbdfac9d5cbee10869e77374321d1cf6e146f Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:53:10 -0700 Subject: [PATCH 04/12] switched to unpack method --- worldeditadditions_core/utils/notify/notify.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_core/utils/notify/notify.lua b/worldeditadditions_core/utils/notify/notify.lua index aa28e2a..373058f 100644 --- a/worldeditadditions_core/utils/notify/notify.lua +++ b/worldeditadditions_core/utils/notify/notify.lua @@ -156,9 +156,9 @@ function Notify.suppress_for_function(name, func) -- If the player is already suppressed, cancel it unless it's a function if not check_clear_suppressed(name, suppress) then return false end suppress[name] = func - local success, result = suppress[name]() + local result_table = { suppress[name]() } suppress[name] = nil - return success, result + return wea_c.table.unpack(result_table) end --- WorldEdit compatibility From 0ffdb47b54b4af5d94f48020437331c5f6e531b8 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:57:55 -0700 Subject: [PATCH 05/12] more doc refixes --- .../utils/notify/validate.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/worldeditadditions_core/utils/notify/validate.lua b/worldeditadditions_core/utils/notify/validate.lua index dadba2a..91a29cc 100644 --- a/worldeditadditions_core/utils/notify/validate.lua +++ b/worldeditadditions_core/utils/notify/validate.lua @@ -13,8 +13,8 @@ end local validate = {} --- Validate name --- @param string name The name of the player to validate. --- @returns boolean True if the name is valid, false otherwise. +-- @param name string The name of the player to validate. +-- @returns boolean True if the name is valid, false otherwise. validate.name = function(name) if type(name) ~= "string" then log_error(tostring(name) .. " is a " .. type(name) .. " not a string.\n") @@ -30,13 +30,13 @@ validate.name = function(name) end --- Validate message --- @param string message The message to validate. --- @returns boolean True if the message is a string, false otherwise. +-- @param message string The message to validate. +-- @returns boolean True if the message is a string, false otherwise. validate.message = function(message) return type(message) == "string" end --- Validate colour --- @param string colour The colour to validate. --- @returns boolean True if the colour is valid, false otherwise. +-- @param colour string The colour to validate. +-- @returns boolean True if the colour is valid, false otherwise. validate.colour = function(colour) return ( type(colour) == "string" and colour:match("^#%x+$") and @@ -44,9 +44,9 @@ validate.colour = function(colour) end --- Validate all --- @param string name The name of the player to validate. --- @param string message The message to validate. --- @param string colour The colour to validate. +-- @param name string The name of the player to validate. +-- @param message string The message to validate. +-- @param colour string The colour to validate. -- @returns boolean, table|nil Returns the validation status, followed by details of the failure if bool == false. -- | Return arg | Meaning | -- |------------|---------| From ae5d18248f01d69b942aae49bf4312959425e8fd Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:49:14 -0700 Subject: [PATCH 06/12] sorted init and added handle_fn_result --- .../utils/format/handle_fn_result.lua | 25 +++++++++++++++++++ worldeditadditions_core/utils/format/init.lua | 5 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 worldeditadditions_core/utils/format/handle_fn_result.lua diff --git a/worldeditadditions_core/utils/format/handle_fn_result.lua b/worldeditadditions_core/utils/format/handle_fn_result.lua new file mode 100644 index 0000000..76b3a17 --- /dev/null +++ b/worldeditadditions_core/utils/format/handle_fn_result.lua @@ -0,0 +1,25 @@ +--- +-- @module worldeditadditions_core +local wea_c = worldeditadditions_core + +--- Handles the result of a function call. +--- @param ... any The full output of the function call. +local function handle_fn_result(...) + local result = { ... } + local ret = "" + local success = table.remove(result, 1) + if #result > 1 then + ret = wea_c.table.tostring(result) + elseif #result == 1 then + ret = tostring(result[1]) + else + ret = table.concat({ + "Function returned \"", + tostring(success), + "\" with no other output." + }, " ") + end + return success, ret +end + +return handle_fn_result \ No newline at end of file diff --git a/worldeditadditions_core/utils/format/init.lua b/worldeditadditions_core/utils/format/init.lua index 4e2b4ee..b9178f6 100644 --- a/worldeditadditions_core/utils/format/init.lua +++ b/worldeditadditions_core/utils/format/init.lua @@ -3,11 +3,12 @@ local wea_c = worldeditadditions_core wea_c.format = { array_2d = dofile(wea_c.modpath.."/utils/format/array_2d.lua"), + escape = dofile(wea_c.modpath.."/utils/format/escape.lua"), + handle_fn_result = dofile(wea_c.modpath.."/utils/format/handle_fn_result.lua"), human_size = dofile(wea_c.modpath.."/utils/format/human_size.lua"), human_time = dofile(wea_c.modpath.."/utils/format/human_time.lua"), - node_distribution = dofile(wea_c.modpath.."/utils/format/node_distribution.lua"), make_ascii_table = dofile(wea_c.modpath.."/utils/format/make_ascii_table.lua"), map = dofile(wea_c.modpath.."/utils/format/map.lua"), - escape = dofile(wea_c.modpath.."/utils/format/escape.lua") + node_distribution = dofile(wea_c.modpath.."/utils/format/node_distribution.lua") } From 0076010f35edde62bc5f45f132b945d9d92a135f Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:50:57 -0700 Subject: [PATCH 07/12] WE compatibility for Notify --- worldeditadditions_core/utils/notify/notify.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/worldeditadditions_core/utils/notify/notify.lua b/worldeditadditions_core/utils/notify/notify.lua index 373058f..617eb71 100644 --- a/worldeditadditions_core/utils/notify/notify.lua +++ b/worldeditadditions_core/utils/notify/notify.lua @@ -1,4 +1,5 @@ --- A player notification system for worldeditadditions. +-- @module worldeditadditions_core.notify local wea_c = worldeditadditions_core -- Helper functions @@ -162,10 +163,11 @@ function Notify.suppress_for_function(name, func) end --- WorldEdit compatibility --- if worldedit and type(worldedit.player_notify) == "function" then --- worldedit.player_notify = function(name, message, ntype) --- Notify(name, ntype, message) --- end --- end +if worldedit and type(worldedit.player_notify) == "function" then + worldedit.player_notify = function(name, message, ntype) + if not ntype then ntype = "info" end + Notify(name, ntype, message) + end +end return Notify \ No newline at end of file From 0915a83151c9855bcc485e5ca2ad9b4bff54a8d1 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:51:18 -0700 Subject: [PATCH 08/12] notify suppression test --- .../commands/test/tests/init.lua | 5 ++--- .../test/tests/notify_suppress.test.lua | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/worldeditadditions_commands/commands/test/tests/init.lua b/worldeditadditions_commands/commands/test/tests/init.lua index d2efccc..2461f73 100644 --- a/worldeditadditions_commands/commands/test/tests/init.lua +++ b/worldeditadditions_commands/commands/test/tests/init.lua @@ -3,8 +3,8 @@ local test_id_paths = { "credits.test.lua", "notify.test.lua", "notify_bad.test.lua", - -- "notify_suppress.test.lua", - -- "stacktrace.test.lua", + "notify_suppress.test.lua", + "stacktrace.test.lua", } -- Helper functions @@ -13,7 +13,6 @@ local update = function(a,k,v) a[k] = v end -- Test loader local test_loader = function (path) for _, v in ipairs(test_id_paths) do dofile(path .. v) end - return ret end return test_loader \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua b/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua index e69de29..f1da0e3 100644 --- a/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua +++ b/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua @@ -0,0 +1,20 @@ +local Notify = worldeditadditions_core.notify +worldeditadditions.normalize_test("suppress", { + params = "N/A", + description = "Tests notification suppression system.", + func = function(name, params_table) + Notify.suppress_for_player(name, 5) + Notify.warn(name, "This message should not be shown.") + Notify.suppress_for_player(name, -1) + Notify.ok(name, "This message should be shown.") + local result = Notify.suppress_for_function(name, function() + Notify.error(name, "This message should not be shown.") + return true + end) + if not result then + Notify.error(name, "Error: suppress_for_function did not call function.") + else + Notify.ok(name, "suppress_for_function called function.") + end + end +}) \ No newline at end of file From 9efaecc13a6b4c1f6fdd48b5a0edc4158953ff75 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:02:49 -0700 Subject: [PATCH 09/12] first usage of handle_fn_result --- worldeditadditions_commands/commands/test/test.lua | 4 +++- worldeditadditions_core/utils/format/handle_fn_result.lua | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_commands/commands/test/test.lua b/worldeditadditions_commands/commands/test/test.lua index 13092cc..8130275 100644 --- a/worldeditadditions_commands/commands/test/test.lua +++ b/worldeditadditions_commands/commands/test/test.lua @@ -59,6 +59,8 @@ wea_c.register_command("test", { tests[params_text[1]]:help()}, " ") end end - return tests[subcommand](name, params_text) + return wea_c.format.handle_fn_result( + tests[subcommand](name, params_text) + ) end }) \ No newline at end of file diff --git a/worldeditadditions_core/utils/format/handle_fn_result.lua b/worldeditadditions_core/utils/format/handle_fn_result.lua index 76b3a17..51662d1 100644 --- a/worldeditadditions_core/utils/format/handle_fn_result.lua +++ b/worldeditadditions_core/utils/format/handle_fn_result.lua @@ -17,7 +17,7 @@ local function handle_fn_result(...) "Function returned \"", tostring(success), "\" with no other output." - }, " ") + }, "") end return success, ret end From 8ef1d348d27e2c401814a9138c47321c0a8df553 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:06:10 -0700 Subject: [PATCH 10/12] added anti-nil safety measure --- worldeditadditions_core/utils/format/handle_fn_result.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_core/utils/format/handle_fn_result.lua b/worldeditadditions_core/utils/format/handle_fn_result.lua index 51662d1..0ad81b6 100644 --- a/worldeditadditions_core/utils/format/handle_fn_result.lua +++ b/worldeditadditions_core/utils/format/handle_fn_result.lua @@ -19,7 +19,7 @@ local function handle_fn_result(...) "\" with no other output." }, "") end - return success, ret + return success or false, ret end return handle_fn_result \ No newline at end of file From 67e1e957d4db1ef32c45e46312834fdadda7a81e Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:11:04 -0700 Subject: [PATCH 11/12] tidy up init.lua --- worldeditadditions_commands/commands/test/tests/init.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/worldeditadditions_commands/commands/test/tests/init.lua b/worldeditadditions_commands/commands/test/tests/init.lua index 2461f73..2535672 100644 --- a/worldeditadditions_commands/commands/test/tests/init.lua +++ b/worldeditadditions_commands/commands/test/tests/init.lua @@ -7,9 +7,6 @@ local test_id_paths = { "stacktrace.test.lua", } --- Helper functions -local update = function(a,k,v) a[k] = v end - -- Test loader local test_loader = function (path) for _, v in ipairs(test_id_paths) do dofile(path .. v) end From f6b072237bbfcf2cb8b797316741671179eb9182 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:12:53 -0700 Subject: [PATCH 12/12] tweak to test handling --- .../commands/test/tests/credits.test.lua | 1 + .../commands/test/tests/notify.test.lua | 1 + .../commands/test/tests/notify_bad.test.lua | 1 + .../commands/test/tests/notify_suppress.test.lua | 4 ++-- worldeditadditions_core/utils/format/handle_fn_result.lua | 5 ++++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/worldeditadditions_commands/commands/test/tests/credits.test.lua b/worldeditadditions_commands/commands/test/tests/credits.test.lua index 1b0f79d..ba41f92 100644 --- a/worldeditadditions_commands/commands/test/tests/credits.test.lua +++ b/worldeditadditions_commands/commands/test/tests/credits.test.lua @@ -23,5 +23,6 @@ worldeditadditions.normalize_test("credits", { end end send_credits(1) + return true, "Thank you!" end }) \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/tests/notify.test.lua b/worldeditadditions_commands/commands/test/tests/notify.test.lua index b0d433d..dfbe1f8 100644 --- a/worldeditadditions_commands/commands/test/tests/notify.test.lua +++ b/worldeditadditions_commands/commands/test/tests/notify.test.lua @@ -9,5 +9,6 @@ worldeditadditions.normalize_test("notify", { Notify.ok(name, message) Notify.info(name, message) Notify.custom(name, "@" .. name, "Good Job", "#FF00D7") + return true end }) \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua b/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua index 8e9c374..615783b 100644 --- a/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua +++ b/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua @@ -23,5 +23,6 @@ worldeditadditions.normalize_test("notifybad", { Notify.warn(name, "Invalid color test:") Notify.custom(name, "bad", message, "#FF00") -- Bad colour + return true, "Test complete." end }) \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua b/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua index f1da0e3..5d4f40b 100644 --- a/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua +++ b/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua @@ -12,9 +12,9 @@ worldeditadditions.normalize_test("suppress", { return true end) if not result then - Notify.error(name, "Error: suppress_for_function did not call function.") + return false, "Error: suppress_for_function did not call function." else - Notify.ok(name, "suppress_for_function called function.") + return true, "suppress_for_function called function." end end }) \ No newline at end of file diff --git a/worldeditadditions_core/utils/format/handle_fn_result.lua b/worldeditadditions_core/utils/format/handle_fn_result.lua index 0ad81b6..5bc5eb7 100644 --- a/worldeditadditions_core/utils/format/handle_fn_result.lua +++ b/worldeditadditions_core/utils/format/handle_fn_result.lua @@ -11,7 +11,10 @@ local function handle_fn_result(...) if #result > 1 then ret = wea_c.table.tostring(result) elseif #result == 1 then - ret = tostring(result[1]) + if type(result[1]) == "table" then + ret = "Function returned table:\n" .. + wea_c.table.tostring(result[1]) + else ret = tostring(result[1]) end else ret = table.concat({ "Function returned \"",