This commit is contained in:
Connor Olding 2015-11-21 20:01:40 -08:00
parent 051265ea3a
commit 176b8b32b0
3 changed files with 261 additions and 213 deletions

428
_G.yml
View File

@ -1,212 +1,236 @@
__root__: &t0x6f478
_VERSION: Lua 5.2
add_zeros: f0x73838
assert: f0x1fefc
collectgarbage: f0x1f930
dofile: f0x1fe7c
dump: f0x78770
error: f0x1f8c0
getaddr: f0x74c40
getmetatable: f0x1fe2c
ipairs: f0x1fd24
load: f0x1ff54
loadfile: f0x1fd80
loadstring: f0x1ff54
mixed_sorter: f0x76c28
module: f0x6fe20
next: f0x1f7ac
opairs: f0x74c88
order_keys: f0x74cd0
pairs: f0x1fd04
pcall: f0x1fb50
print: f0x1f66c
rawequal: f0x1f62c
rawget: f0x1f598
rawlen: f0x1f5d8
rawset: f0x1f54c
rawstr: f0x76460
require: f0x70b00
select: f0x1f444
setmetatable: f0x1fbc0
strpad: f0x73e60
tonumber: f0x1f25c
tostring: f0x1f234
type: f0x1f1f8
unpack: f0x26598
xpcall: f0x1fa84
_G: *t0x6f478
arg: &t0x736b8
"-1": /usr/bin/lua
0: ./run.lua
bit32: &t0x70190
arshift: f0x2022c
band: f0x20458
bnot: f0x20208
bor: f0x204c4
btest: f0x20434
bxor: f0x20478
extract: f0x203a4
lrotate: f0x20510
lshift: f0x20190
replace: f0x20338
rrotate: f0x201c4
rshift: f0x2015c
coroutine: &t0x6f998
create: f0x20844
resume: f0x20934
running: f0x20824
status: f0x206cc
wrap: f0x20888
yield: f0x20584
debug: &t0x717c8
debug: f0x20e44
gethook: f0x21470
getinfo: f0x21674
getlocal: f0x2132c
getmetatable: f0x20d88
getregistry: f0x209fc
getupvalue: f0x20aac
getuservalue: f0x20e0c
sethook: f0x2118c
setlocal: f0x21094
setmetatable: f0x20ab4
setupvalue: f0x20a8c
setuservalue: f0x20b58
traceback: f0x20ff8
upvalueid: f0x20ca0
upvaluejoin: f0x20cd8
io: &t0x70fe8
close: f0x21c94
flush: f0x22328
input: f0x22a28
lines: f0x22a44
open: f0x22b64
output: f0x22a0c
popen: f0x2238c
read: f0x222dc
stderr: file (0x76e4f9d8)
stdin: file (0x76e4fc98)
stdout: file (0x76e4fb38)
tmpfile: f0x22c70
type: f0x22890
write: f0x21ba8
math: &t0x72a10
abs: f0x22e48
acos: f0x234c8
asin: f0x234a4
atan: f0x2343c
atan2: f0x23460
ceil: f0x23418
cos: f0x233d0
cosh: f0x233f4
deg: f0x22e18
exp: f0x233ac
floor: f0x23030
fmod: f0x23368
frexp: f0x2332c
__root__: &t0xfff91348
_VERSION: Lua 5.1
add_zeros: f0xfff9bdb8
assert: fbuiltin#2
collectgarbage: fbuiltin#27
copy: f0xfff9be70
dofile: fbuiltin#25
dump: f0xfff91308
error: fbuiltin#19
gcinfo: fbuiltin#26
getaddr: f0xfff9be58
getfenv: fbuiltin#10
getmetatable: fbuiltin#8
ipairs: fbuiltin#7
load: fbuiltin#23
loadfile: fbuiltin#22
loadstring: fbuiltin#24
mixed_sorter: f0xfff9bdd0
module: f0xfff93598
newproxy: fbuiltin#28
next: fbuiltin#4
opairs: f0xfff9be00
order_keys: f0xfff9bde8
pairs: fbuiltin#5
pcall: fbuiltin#20
print: fbuiltin#29
rawequal: fbuiltin#14
rawget: fbuiltin#12
rawset: fbuiltin#13
rawstr: f0xfff9be40
require: f0xfff935d8
select: fbuiltin#16
setfenv: fbuiltin#11
setmetatable: fbuiltin#9
strpad: f0xfff9bda0
tonumber: fbuiltin#17
tostring: fbuiltin#18
type: fbuiltin#3
unpack: fbuiltin#15
xpcall: fbuiltin#21
_G: *t0xfff91348
arg: &t0xfff93728
"-1": luajit
0: run.lua
bit: &t0xfff962c0
arshift: fbuiltin#68
band: fbuiltin#71
bnot: fbuiltin#64
bor: fbuiltin#72
bswap: fbuiltin#65
bxor: fbuiltin#73
lshift: fbuiltin#66
rol: fbuiltin#69
ror: fbuiltin#70
rshift: fbuiltin#67
tobit: fbuiltin#63
tohex: fbuiltin#74
coroutine: &t0xfff92f38
create: fbuiltin#32
resume: fbuiltin#34
running: fbuiltin#31
status: fbuiltin#30
wrap: fbuiltin#36
yield: fbuiltin#33
debug: &t0xfff95d78
debug: fbuiltin#140
getfenv: fbuiltin#129
gethook: fbuiltin#139
getinfo: fbuiltin#131
getlocal: fbuiltin#132
getmetatable: fbuiltin#127
getregistry: fbuiltin#126
getupvalue: fbuiltin#134
setfenv: fbuiltin#130
sethook: fbuiltin#138
setlocal: fbuiltin#133
setmetatable: fbuiltin#128
setupvalue: fbuiltin#135
traceback: fbuiltin#141
upvalueid: fbuiltin#136
upvaluejoin: fbuiltin#137
io: &t0xfff942b0
close: fbuiltin#107
flush: fbuiltin#110
input: fbuiltin#111
lines: fbuiltin#113
open: fbuiltin#104
output: fbuiltin#112
popen: fbuiltin#105
read: fbuiltin#108
stderr: file (0x611a2cf0)
stdin: file (0x611a2c10)
stdout: file (0x611a2c80)
tmpfile: fbuiltin#106
type: fbuiltin#114
write: fbuiltin#109
jit: &t0xfff967f0
arch: x86
attach: fbuiltin#146
flush: fbuiltin#144
off: fbuiltin#143
on: fbuiltin#142
os: POSIX
status: fbuiltin#145
version: LuaJIT 2.1.0-beta1
version_num: 20100
opt: &t0xfff96ba8
start: fbuiltin#158
math: &t0xfff95250
abs: fbuiltin#37
acos: fbuiltin#47
asin: fbuiltin#46
atan: fbuiltin#48
atan2: fbuiltin#55
ceil: fbuiltin#39
cos: fbuiltin#44
cosh: fbuiltin#50
deg: f0xfff95a48
exp: fbuiltin#42
floor: fbuiltin#38
fmod: fbuiltin#57
frexp: fbuiltin#52
huge: inf
ldexp: f0x232ec
log: f0x2323c
log10: f0x232c8
max: f0x22fc4
min: f0x22f58
modf: f0x231f0
ldexp: fbuiltin#58
log: fbuiltin#54
log10: fbuiltin#41
max: fbuiltin#60
min: fbuiltin#59
mod: fbuiltin#57
modf: fbuiltin#53
pi: 3.1415926535898
pow: f0x231ac
rad: f0x22de8
random: f0x23054
randomseed: f0x22f3c
sin: f0x22ef4
sinh: f0x22f18
sqrt: f0x22eb4
tan: f0x22e6c
tanh: f0x22e90
os: &t0x70d90
clock: f0x237d8
date: f0x23ac0
difftime: f0x23758
execute: f0x23714
exit: f0x2369c
getenv: f0x23670
remove: f0x2363c
rename: f0x235ec
setlocale: f0x23580
time: f0x23930
tmpname: f0x23810
package: &t0x6fe90
config: "\
/\
;\
?\
!\
-\
"
cpath: /usr/lib/lua/5.2/?.so;/usr/lib/lua/5.2/loadall.so;./?.so
loadlib: f0x27808
path: /usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;/usr/lib/lua/5.2/?.lua;/usr/lib/lua/5.2/?/init.lua;./?.lua
searchpath: f0x27ad4
seeall: f0x273e0
searchers: *t0x705b0
loaded: &t0x6f948
pow: fbuiltin#56
rad: f0xfff95ad8
random: fbuiltin#61
randomseed: fbuiltin#62
sin: fbuiltin#43
sinh: fbuiltin#49
sqrt: fbuiltin#40
tan: fbuiltin#45
tanh: fbuiltin#51
os: &t0xfff94770
clock: fbuiltin#121
date: fbuiltin#122
difftime: fbuiltin#124
execute: fbuiltin#115
exit: fbuiltin#120
getenv: fbuiltin#119
remove: fbuiltin#116
rename: fbuiltin#117
setlocale: fbuiltin#125
time: fbuiltin#123
tmpname: fbuiltin#118
package: &t0xfff93288
config:
/
;
?
!
-
cpath: ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
loadlib: f0xfff93318
path: ./?.lua;/usr/local/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua
searchpath: f0xfff93358
seeall: f0xfff93398
loaded: &t0xfff92480
extra: true
_G: *t0x6f478
bit32: *t0x70190
coroutine: *t0x6f998
debug: *t0x717c8
io: *t0x70fe8
math: *t0x72a10
os: *t0x70d90
package: *t0x6fe90
string: *t0x70340
table: *t0x70b68
pt: &t0x78948
__call: f0x75128
inner: f0x76d00
outer: f0x74410
safekey: f0x77de8
safeval: f0x6f2d0
write: f0x6f360
__index: *t0x78948
__metatable: *t0x78948
loaders: &t0x705b0
1: f0x70620
2: f0x70648
3: f0x70670
4: f0x70698
preload: &t0x70720
string: &t0x70340
byte: f0x25234
char: f0x24768
dump: f0x254d4
find: f0x25db4
format: f0x24890
gmatch: f0x2470c
gsub: f0x25dbc
len: f0x2433c
lower: f0x2436c
match: f0x25dac
rep: f0x2416c
reverse: f0x23fb8
sub: f0x2518c
upper: f0x23ed8
t: &t0x74a30
_G: *t0xfff91348
bit: *t0xfff962c0
coroutine: *t0xfff92f38
debug: *t0xfff95d78
io: *t0xfff942b0
jit: *t0xfff967f0
"jit.opt": *t0xfff96ba8
math: *t0xfff95250
os: *t0xfff94770
package: *t0xfff93288
string: *t0xfff94be0
table: *t0xfff93638
pt: &t0xfff9be18
__call: f0xfff9be88
inner: f0xfff9bfb0
outer: f0xfff9bff0
safekey: f0xfff9beb8
safeval: f0xfff9bed0
write: f0xfff9bea0
__index: *t0xfff9be18
__metatable: *t0xfff9be18
loaders: &t0xfff933d8
1: f0xfff93428
2: f0xfff93448
3: f0xfff93468
4: f0xfff93488
preload: &t0xfff93700
ffi: f0xfff96c48
"jit.profile": f0xfff96af0
"jit.util": f0xfff96b30
"table.clear": f0xfff93e68
"table.new": f0xfff93e28
string: &t0xfff94be0
byte: fbuiltin#75
char: fbuiltin#76
dump: fbuiltin#82
find: fbuiltin#83
format: fbuiltin#88
gfind: fbuiltin#86
gmatch: fbuiltin#86
gsub: fbuiltin#87
len: f0xfff94e00
lower: fbuiltin#80
match: fbuiltin#84
rep: fbuiltin#78
reverse: fbuiltin#79
sub: fbuiltin#77
upper: fbuiltin#81
t: &t0xfff9a1c0
C: hello
D: *t0x74a30
A: &t0x74b78
D: *t0xfff9a1c0
A: &t0xfff9a978
a: beep
b: boop
c: burp
d: *t0x786c0
B: &t0x786c0
d: *t0xfff9a9a0
B: &t0xfff9a9a0
a: nude
b: dude
c: lewd
d: *t0x74b78
table: &t0x70b68
concat: f0x2691c
insert: f0x26688
maxn: f0x26818
pack: f0x26778
remove: f0x26498
sort: f0x26dec
unpack: f0x26598
d: *t0xfff9a978
table: &t0xfff93638
concat: fbuiltin#91
foreach: f0xfff93b70
foreachi: f0xfff93aa8
getn: f0xfff93c00
insert: fbuiltin#90
maxn: fbuiltin#89
remove: f0xfff93d90
sort: fbuiltin#92

42
pt.lua
View File

@ -1,4 +1,4 @@
require('extra')
require 'extra'
local pt = {}
pt.__index = pt
@ -19,14 +19,29 @@ function getaddr(t)
return rawstr(t):sub(#type(t) + 3)
end
function pt.__call(pt, t, writer, seen)
function copy(t)
-- shallow copy
if type(t) ~= 'table' then return end
local new = {}
for key, value in pairs(t) do
new[key] = value
end
return new
end
function pt.__call(pt, args)
-- print a table as semi-valid YAML
-- with references to prevent recursion/duplication
local t = args.table or args[1]
local self = {}
setmetatable(self, pt)
self.seen = seen or {}
self.seen = copy(args.seen) or {}
self.skipped = copy(args.skipped) or {}
self.seen_elsewhere = args.seen or {}
self.depth = args.depth or 16
self.writer = args.writer or io.write
self.skeleton = args.skeleton or false
self.queued = {}
self.writer = writer or io.write
self:inner('__root__', t, '')
return self.seen
end
@ -53,22 +68,31 @@ function pt.safeval(v, indent)
return s
end
s = s:find('[\r\n]') and ('\n'..s):gsub('[\r\n]', '\n'..indent..' ') or s
local safe = ('%q'):format(s)
return s == safe:sub(2, -2) and s or safe
--local safe = ('%q'):format(s)
--return s == safe:sub(2, -2) and s or safe
-- TODO: finish matching valid characters
return s:find('[^%w_()[]{}.]') and ('%q'):format(s) or s
end
function pt:inner(k, v, indent)
if type(v) ~= 'table' then
if self.skeleton then return end
self:write(indent, pt.safekey(k), ': ')
self:write(pt.safeval(v, indent), '\n')
return
end
local addr = getaddr(v)
self:write(indent, pt.safekey(k))
if #indent > self.depth or self.skipped[addr] then
--self.skipped[addr] = true -- TODO: extra logics
self:write(': #t', addr, '\n')
return
end
if self.seen[addr] or self.queued[addr] then
self:write(': *t', addr, '\n')
self:write(': *t', addr, self.seen_elsewhere[addr] and ' #\n' or '\n')
return
end
@ -90,7 +114,7 @@ function pt:outer(t, indent)
for k,v in opairs(t) do
if type(v) == 'table' then
local addr = getaddr(v)
if not self.queued[addr] and not self.seen[addr] then
if not self.queued[addr] and not self.seen[addr] and not self.skipped[addr] then
self.queued[addr] = true
ours[k] = v
else

View File

@ -30,11 +30,11 @@ function dump(t, fn, seen)
local writer = function(...)
file:write(...)
end
seen = pt(t, writer, seen)
seen = pt{t, writer=writer, seen=seen}
file:close()
return seen
end
pt(t)
pt{t}
dump(_G, '_G.yml')