gists/print_tables/run.lua
2018-10-11 16:45:34 +02:00

41 lines
629 B
Lua
Executable file

#!/usr/bin/lua
local pt = require('pt')
t = {
A = 'hello',
B = {
a = 'beep',
b = 'boop',
c = 'burp',
},
C = {
a = 'nude',
b = 'dude',
c = 'lewd',
},
D = 'goodbye',
}
t.B.d = t.C
t.C.d = t.B
t.E = t
function dump(t, fn, seen)
if t == nil then return end
local file = io.open(fn, "w")
if not file then
io.write("Failed opening ", fn, "\n")
return
end
local writer = function(...)
file:write(...)
end
seen = pt{t, writer=writer, seen=seen}
file:close()
return seen
end
pt{t}
dump(_G, '_G.yml')