fix dump for more complex structures

This commit is contained in:
Daniel Poelzleithner 2022-11-09 22:41:04 +01:00
parent cda98d6ba9
commit 9b81bb1785
1 changed files with 10 additions and 3 deletions

View File

@ -52,11 +52,18 @@ readdir = lsyncd.readdir
function dump(tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(k) ~= "string" then
k = tostring(k)
end
local formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
dump(v, indent+1)
elseif type(v) == 'boolean' then
if indent > 3 then
print("dump: Already 3 deep, skip")
else
dump(v, indent+1)
end
elseif type(v) ~= 'string' then
print(formatting .. tostring(v))
else
print(formatting .. v)