lua: add a Debug.dump_table() utility function

Prints a table recursively with print()
This commit is contained in:
George Kiagiadakis
2021-04-08 12:01:23 +03:00
parent 4399512891
commit 21dccd5edb

View File

@@ -69,6 +69,27 @@ local function Constraint (spec)
return debug.setmetatable(spec, { __name = "Constraint" })
end
local function dump_table(t, indent)
local indent_str = ""
indent = indent or 1
for i = 1, indent, 1 do
indent_str = indent_str .. "\t"
end
for k, v in pairs(t) do
if (type(v) == "table") then
print (indent_str .. tostring(k) .. ": ")
dump_table(v, indent + 1)
else
print (indent_str .. tostring(k) .. ": " .. tostring(v))
end
end
end
local Debug = {
dump_table = dump_table,
}
local Id = {
INVALID = 0xffffffff,
ANY = 0xffffffff,
@@ -116,6 +137,7 @@ local Feature = {
}
SANDBOX_EXPORT = {
Debug = Debug,
Id = Id,
Features = Features,
Feature = Feature,