2022-12-07 18:26:11 +00:00
|
|
|
function table.len(t)
|
|
|
|
local count = 0
|
|
|
|
for _ in pairs(t) do count = count + 1 end
|
|
|
|
return count
|
|
|
|
end
|
|
|
|
|
2022-12-07 18:30:22 +00:00
|
|
|
function table.pprint(t, options, ident, total_count)
|
2022-12-07 18:26:11 +00:00
|
|
|
local ident = ident or 0
|
|
|
|
local total_count = total_count or 0
|
2022-12-07 18:30:22 +00:00
|
|
|
|
|
|
|
local options = options or {}
|
|
|
|
local print_function = options.call or print
|
2022-12-07 18:26:11 +00:00
|
|
|
if type(t) == 'table' then
|
|
|
|
local count = 0
|
|
|
|
for k, v in pairs(t) do
|
2022-12-07 18:30:22 +00:00
|
|
|
print_function(string.rep('\t', ident) .. k)
|
2022-12-07 18:26:11 +00:00
|
|
|
count = count + 1
|
2022-12-07 18:30:22 +00:00
|
|
|
total_count = table.pprint(v, options, ident + 1, total_count)
|
2022-12-07 18:26:11 +00:00
|
|
|
end
|
|
|
|
if count == 0 then
|
|
|
|
--print('<empty table>')
|
|
|
|
end
|
|
|
|
else
|
2022-12-07 18:30:22 +00:00
|
|
|
print_function(string.rep('\t', ident) .. tostring(t))
|
2022-12-07 18:26:11 +00:00
|
|
|
total_count = total_count + 1
|
|
|
|
end
|
|
|
|
return total_count
|
|
|
|
end
|