add core.get_log()

This commit is contained in:
takase1121 2021-08-22 19:32:45 +08:00 committed by Francesco
parent cb639700b3
commit 7c3daa0f39
1 changed files with 17 additions and 0 deletions

View File

@ -874,6 +874,23 @@ function core.error(...)
end 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, ...) function core.try(fn, ...)
local err local err
local ok, res = xpcall(fn, function(msg) local ok, res = xpcall(fn, function(msg)