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] 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") }