* Nicer PrintTableToLog()
This commit is contained in:
Applevangelist 2023-12-07 16:08:47 +01:00
parent ff6704f123
commit 6903e252d2

View File

@ -443,22 +443,35 @@ end
--- Print a table to log in a nice format --- Print a table to log in a nice format
-- @param #table table The table to print -- @param #table table The table to print
-- @param #number indent Number of idents -- @param #number indent Number of indents
-- @return #string text Text created on the fly of the log output
function UTILS.PrintTableToLog(table, indent) function UTILS.PrintTableToLog(table, indent)
local text = "\n"
if not table then if not table then
env.warning("No table passed!") env.warning("No table passed!")
return return nil
end end
if not indent then indent = 0 end if not indent then indent = 0 end
for k, v in pairs(table) do for k, v in pairs(table) do
if string.find(k," ") then k='"'..k..'"'end
if type(v) == "table" then if type(v) == "table" then
env.info(string.rep(" ", indent) .. tostring(k) .. " = {") env.info(string.rep(" ", indent) .. tostring(k) .. " = {")
UTILS.PrintTableToLog(v, indent + 1) text = text ..string.rep(" ", indent) .. tostring(k) .. " = {\n"
env.info(string.rep(" ", indent) .. "}") text = text .. tostring(UTILS.PrintTableToLog(v, indent + 1)).."\n"
env.info(string.rep(" ", indent) .. "},")
text = text .. string.rep(" ", indent) .. "},\n"
else else
env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(v)) local value
if tostring(v) == "true" or tostring(v) == "false" or tonumber(v) ~= nil then
value=v
else
value = '"'..tostring(v)..'"'
end
env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n")
text = text .. string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n"
end end
end end
return text
end end
--- Returns table in a easy readable string representation. --- Returns table in a easy readable string representation.