2021-04-26 21:04:01 -03:00
|
|
|
-- recursive dump function
|
|
|
|
|
function dumpLevel(input, level)
|
2023-09-10 10:17:19 -07:00
|
|
|
local indent = ""
|
2021-04-26 21:04:01 -03:00
|
|
|
|
|
|
|
|
for i = 1, level do
|
2023-09-10 10:17:19 -07:00
|
|
|
indent = indent .. " "
|
2021-04-26 21:04:01 -03:00
|
|
|
end
|
|
|
|
|
|
2023-09-10 10:17:19 -07:00
|
|
|
if type(input) == "table" then
|
|
|
|
|
local str = "{ \n"
|
2021-04-26 21:04:01 -03:00
|
|
|
local lines = {}
|
|
|
|
|
|
|
|
|
|
for k, v in pairs(input) do
|
2023-09-10 10:17:19 -07:00
|
|
|
if type(k) ~= "number" then
|
2021-04-26 21:04:01 -03:00
|
|
|
k = '"' .. k .. '"'
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-10 10:17:19 -07:00
|
|
|
if type(v) == "string" then
|
2021-04-26 21:04:01 -03:00
|
|
|
v = '"' .. v .. '"'
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-10 10:17:19 -07:00
|
|
|
table.insert(lines, indent .. " [" .. k .. "] = " .. dumpLevel(v, level + 1))
|
2021-04-26 21:04:01 -03:00
|
|
|
end
|
2023-09-10 10:17:19 -07:00
|
|
|
return str .. table.concat(lines, ",\n") .. "\n" .. indent .. "}"
|
2021-04-26 21:04:01 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return tostring(input)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Return a string representation of input for debugging purposes
|
|
|
|
|
function dump(input)
|
|
|
|
|
return dumpLevel(input, 0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Call the dump function and print it to console
|
|
|
|
|
function pdump(input)
|
|
|
|
|
local dump_str = dump(input)
|
2023-08-21 07:27:33 -03:00
|
|
|
logger.debug(dump_str)
|
2021-04-26 21:04:01 -03:00
|
|
|
return dump_str
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Call the dump function with a title and print it beautifully to the console
|
|
|
|
|
function tdump(title, input)
|
2023-09-10 10:17:19 -07:00
|
|
|
local title_fill = ""
|
2021-04-26 21:04:01 -03:00
|
|
|
for i = 1, title:len() do
|
2023-09-10 10:17:19 -07:00
|
|
|
title_fill = title_fill .. "="
|
2021-04-26 21:04:01 -03:00
|
|
|
end
|
|
|
|
|
|
2023-09-10 10:17:19 -07:00
|
|
|
local header_str = "\n====" .. title_fill .. "====\n"
|
|
|
|
|
header_str = header_str .. "=== " .. title .. " ===\n"
|
|
|
|
|
header_str = header_str .. "====" .. title_fill .. "====\n"
|
2021-04-26 21:04:01 -03:00
|
|
|
|
|
|
|
|
local dump_str = dump(input)
|
2023-09-10 10:17:19 -07:00
|
|
|
local footer_str = "\n====" .. title_fill .. "====\n"
|
2021-04-26 21:04:01 -03:00
|
|
|
|
2023-08-21 07:27:33 -03:00
|
|
|
logger.debug(header_str .. dump_str .. footer_str)
|
2021-04-26 21:04:01 -03:00
|
|
|
|
|
|
|
|
return dump_str
|
|
|
|
|
end
|