From 7c3daa0f39de24cea3ddc5345d23be2aa0dfbbdc Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sun, 22 Aug 2021 19:32:45 +0800 Subject: [PATCH] add core.get_log() --- data/core/init.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/core/init.lua b/data/core/init.lua index 4af35921..c71322d1 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -874,6 +874,23 @@ function core.error(...) end +function core.get_log(i) + if i == nil then + local r = {} + for _, item in ipairs(core.log_items) do + table.insert(r, core.get_log(item)) + end + return table.concat(r, "\n") + end + local item = type(i) == "number" and core.log_items[i] or i + local text = string.format("[%s] %s at %s", os.date(nil, item.time), item.text, item.at) + if item.info then + text = string.format("%s\n%s\n", text, item.info) + end + return text +end + + function core.try(fn, ...) local err local ok, res = xpcall(fn, function(msg)