gists/print_tables/run.lua

42 lines
629 B
Lua
Raw Permalink Normal View History

2014-08-20 17:44:41 -07:00
#!/usr/bin/lua
local pt = require('pt')
2014-08-20 17:59:36 -07:00
t = {
2016-12-11 04:56:57 -08:00
A = 'hello',
B = {
2014-08-20 17:59:36 -07:00
a = 'beep',
b = 'boop',
c = 'burp',
},
2016-12-11 04:56:57 -08:00
C = {
2014-08-20 17:59:36 -07:00
a = 'nude',
b = 'dude',
c = 'lewd',
},
2016-12-11 04:56:57 -08:00
D = 'goodbye',
2014-08-20 17:59:36 -07:00
}
2016-12-11 04:56:57 -08:00
t.B.d = t.C
t.C.d = t.B
t.E = t
2014-08-20 17:59:36 -07:00
2014-08-20 17:44:41 -07:00
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
2015-11-21 20:01:40 -08:00
seen = pt{t, writer=writer, seen=seen}
2014-08-20 17:44:41 -07:00
file:close()
return seen
end
2015-11-21 20:01:40 -08:00
pt{t}
2014-08-25 22:51:45 -07:00
dump(_G, '_G.yml')