Attempt at improving the printing, but will delete anyway
This commit is contained in:
parent
524730d4e5
commit
6ba7c02381
@ -1,32 +1,34 @@
|
|||||||
-- Print anything - including nested tables
|
-- Print anything - including nested tables
|
||||||
-- Based on but modified from:
|
-- Based on but modified from:
|
||||||
-- http://lua-users.org/wiki/TableSerialization
|
-- http://lua-users.org/wiki/TableSerialization
|
||||||
module("TablePrinter", package.seeall)
|
--module("TablePrinter", package.seeall)
|
||||||
|
|
||||||
function TablePrinter.print (tt, indent, done)
|
local function printTable(tt, indent, done)
|
||||||
done = done or {}
|
done = done or {}
|
||||||
indent = indent or 0
|
indent = indent or 0
|
||||||
if tt == nil then
|
if tt == nil then
|
||||||
print("nil\n")
|
print("nil")
|
||||||
else
|
else
|
||||||
if type(tt) == "table" then
|
if type(tt) == "table" then
|
||||||
for key, value in pairs (tt) do
|
for key, value in pairs (tt) do
|
||||||
print(string.rep (" ", indent)) -- indent it
|
print(string.rep (" ", indent)) -- indent it
|
||||||
if type (value) == "table" and not done [value] then
|
if type (value) == "table" and not done [value] then
|
||||||
done [value] = true
|
done [value] = true
|
||||||
print(string.format("[%s] => table\n", tostring (key)));
|
print(string.format("[%s] => table", tostring (key)));
|
||||||
print(string.rep (" ", indent+4)) -- indent it
|
print(string.rep (" ", indent+4)) -- indent it
|
||||||
print("(\n");
|
print("(");
|
||||||
table_print (value, indent + 7, done)
|
printTable (value, indent + 7, done)
|
||||||
print(string.rep (" ", indent+4)) -- indent it
|
print(string.rep (" ", indent+4)) -- indent it
|
||||||
print(")\n");
|
print(")");
|
||||||
else
|
else
|
||||||
print(string.format("[%s] => %s\n",
|
print(string.format("[%s] => %s",
|
||||||
tostring (key), tostring(value)))
|
tostring (key), tostring(value)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print(tt .. "\n")
|
print(tt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return printTable
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user