From ab2b4a4dffe70d066a0bd29a63cc2506a4c22810 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 20 Aug 2014 17:35:32 -0700 Subject: [PATCH 01/10] --- .dummy | 1 + 1 file changed, 1 insertion(+) create mode 100644 .dummy diff --git a/.dummy b/.dummy new file mode 100644 index 0000000..945c9b4 --- /dev/null +++ b/.dummy @@ -0,0 +1 @@ +. \ No newline at end of file From 62866ee36cce397476b67cf6b8d3e8d2587e1dc1 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 20 Aug 2014 17:44:41 -0700 Subject: [PATCH 02/10] dear pesky plumbers --- !_G.yml | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ .dummy | 1 - extra.lua | 38 +++++++++++ pt.lua | 118 ++++++++++++++++++++++++++++++++ run.lua | 22 ++++++ 5 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 !_G.yml delete mode 100644 .dummy create mode 100755 extra.lua create mode 100755 pt.lua create mode 100755 run.lua diff --git a/!_G.yml b/!_G.yml new file mode 100644 index 0000000..6da4a2f --- /dev/null +++ b/!_G.yml @@ -0,0 +1,199 @@ +__root__: &t0xc4e478 + _VERSION: "Lua 5.2" + add_zeros: f0xc56f38 + assert: f0x1fefc + collectgarbage: f0x1f930 + dofile: f0x1fe7c + dump: f0xc578c0 + error: f0x1f8c0 + getaddr: f0xc53f00 + getmetatable: f0x1fe2c + ipairs: f0x1fd24 + load: f0x1ff54 + loadfile: f0x1fd80 + loadstring: f0x1ff54 + mixed_sorter: f0xc56ef0 + module: f0xc4ee20 + next: f0x1f7ac + opairs: f0xc53630 + order_keys: f0xc56ea8 + pairs: f0x1fd04 + pcall: f0x1fb50 + print: f0x1f66c + rawequal: f0x1f62c + rawget: f0x1f598 + rawlen: f0x1f5d8 + rawset: f0x1f54c + rawstr: f0xc56e60 + require: f0xc4fb00 + select: f0x1f444 + setmetatable: f0x1fbc0 + strpad: f0xc52890 + tonumber: f0x1f25c + tostring: f0x1f234 + type: f0x1f1f8 + unpack: f0x26598 + xpcall: f0x1fa84 + _G: *t0xc4e478 + arg: &t0xc526b8 + "-1": "/usr/bin/lua" + 0: "./run.lua" + bit32: &t0xc4f190 + 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: &t0xc4e998 + create: f0x20844 + resume: f0x20934 + running: f0x20824 + status: f0x206cc + wrap: f0x20888 + yield: f0x20584 + debug: &t0xc507c8 + 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: &t0xc4ffe8 + close: f0x21c94 + flush: f0x22328 + input: f0x22a28 + lines: f0x22a44 + open: f0x22b64 + output: f0x22a0c + popen: f0x2238c + read: f0x222dc + stderr: "file (0x76ee69d8)" + stdin: "file (0x76ee6c98)" + stdout: "file (0x76ee6b38)" + tmpfile: f0x22c70 + type: f0x22890 + write: f0x21ba8 + math: &t0xc51a10 + 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 + huge: inf + ldexp: f0x232ec + log: f0x2323c + log10: f0x232c8 + max: f0x22fc4 + min: f0x22f58 + modf: f0x231f0 + pi: 3.1415926535898 + pow: f0x231ac + rad: f0x22de8 + random: f0x23054 + randomseed: f0x22f3c + sin: f0x22ef4 + sinh: f0x22f18 + sqrt: f0x22eb4 + tan: f0x22e6c + tanh: f0x22e90 + os: &t0xc4fd90 + clock: f0x237d8 + date: f0x23ac0 + difftime: f0x23758 + execute: f0x23714 + exit: f0x2369c + getenv: f0x23670 + remove: f0x2363c + rename: f0x235ec + setlocale: f0x23580 + time: f0x23930 + tmpname: f0x23810 + package: &t0xc4ee90 + 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: *t0xc4f5b0 + loaded: &t0xc4e948 + extra: true + _G: *t0xc4e478 + bit32: *t0xc4f190 + coroutine: *t0xc4e998 + debug: *t0xc507c8 + io: *t0xc4ffe8 + math: *t0xc51a10 + os: *t0xc4fd90 + package: *t0xc4ee90 + string: *t0xc4f340 + table: *t0xc4fb68 + pt: &t0xc56a90 + __call: f0xc52a58 + inner: f0xc55c50 + outer: f0xc55ce8 + safekey: f0xc57890 + safeval: f0xc578a8 + write: f0xc56f08 + __index: *t0xc56a90 + __metatable: *t0xc56a90 + loaders: &t0xc4f5b0 + 1: f0xc4f620 + 2: f0xc4f648 + 3: f0xc4f670 + 4: f0xc4f698 + preload: &t0xc4f720 + string: &t0xc4f340 + 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 + table: &t0xc4fb68 + concat: f0x2691c + insert: f0x26688 + maxn: f0x26818 + pack: f0x26778 + remove: f0x26498 + sort: f0x26dec + unpack: f0x26598 diff --git a/.dummy b/.dummy deleted file mode 100644 index 945c9b4..0000000 --- a/.dummy +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file diff --git a/extra.lua b/extra.lua new file mode 100755 index 0000000..68e7afb --- /dev/null +++ b/extra.lua @@ -0,0 +1,38 @@ +function strpad(num, count, pad) + num = tostring(num) + return (pad:rep(count)..num):sub(#num) +end + +function add_zeros(num, count) + return strpad(num, count - 1, '0') +end + +function mixed_sorter(a, b) + a = type(a) == 'number' and add_zeros(a, 16) or tostring(a) + b = type(b) == 'number' and add_zeros(b, 16) or tostring(b) + return a < b +end + +-- loosely based on http://lua-users.org/wiki/SortedIteration +-- the original didn't make use of closures for who knows why +function order_keys(t) + local oi = {} + for key in pairs(t) do + table.insert(oi, key) + end + table.sort(oi, mixed_sorter) + return oi +end + +function opairs(t, cache) + local oi = cache and cache[t] or order_keys(t) + if cache then + cache[t] = oi + end + local i = 0 + return function() + i = i + 1 + local key = oi[i] + if key then return key, t[key] end + end +end diff --git a/pt.lua b/pt.lua new file mode 100755 index 0000000..1350456 --- /dev/null +++ b/pt.lua @@ -0,0 +1,118 @@ +require('extra') + +local pt = {} +pt.__index = pt +setmetatable(pt, pt) + +function rawstr(v) + if v == nil then return 'nil' end + local mt = getmetatable(v) + local ts = mt and rawget(mt, '__tostring') + if not ts then return tostring(v) end + mt.__tostring = nil + local s = tostring(v) + mt.__tostring = ts + return s +end + +function getaddr(t) + return rawstr(t):sub(#type(t) + 3) +end + +function pt.__call(pt, t, writer, seen) + -- print a table as semi-valid YAML + -- with references to prevent recursion/duplication + local self = {} + setmetatable(self, pt) + self.seen = seen or {} + self.queued = {} + self.writer = writer or io.write + self:inner('__root__', t, '') + return self.seen +end + +function pt:write(...) + self.writer(...) +end + +function pt.safekey(k) + if type(k) == 'table' then + return 't'..getaddr(k) + end + local s = tostring(k) + s = s:gsub('[\r\n]', '') + return s:find('[^%w_]') and ('%q'):format(s) or s +end + +function pt.safeval(v, indent) + if type(v) == 'function' then + return 'f'..getaddr(v) + end + local s = tostring(v) + if type(v) == 'number' then + return s + end + s = s:find('[\r\n]') and ('\n'..s):gsub('[\r\n]', '\n'..indent..' ') or s + return s:find('[^%w_]') and ('%q'):format(s) or s +end + +function pt:inner(k, v, indent) + if type(v) ~= 'table' then + 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 self.seen[addr] or self.queued[addr] then + self:write(': *t', addr, '\n') + return + end + + self.seen[addr] = true + + self:write(': &t', addr, '\n') + self:outer(v, indent..' ') +end + +function pt:outer(t, indent) + if type(t) ~= "table" then + self:write(indent, pt.safeval(t, indent), '\n') + return + end + + local ours = {} + local not_ours = {} + + 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 + self.queued[addr] = true + ours[k] = v + else + not_ours[k] = v + end + else + self:inner(k, v, indent) + end + end + + for k,v in opairs(not_ours) do + self:inner(k, v, indent) + end + + for k,v in opairs(ours) do + self.queued[getaddr(v)] = nil + self:inner(k, v, indent) + end + + local mt = getmetatable(t) + if mt ~= nil then + self:inner('__metatable', mt, indent) + end +end + +return pt diff --git a/run.lua b/run.lua new file mode 100755 index 0000000..345bc65 --- /dev/null +++ b/run.lua @@ -0,0 +1,22 @@ +#!/usr/bin/lua +local pt = require('pt') + +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, seen) + + file:close() + return seen +end + +dump(_G, '!_G.yml') From 124ec51da35a0e112b0f4d853589c897066e5a3c Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 20 Aug 2014 17:59:36 -0700 Subject: [PATCH 03/10] basic testing table --- !_G.yml | 117 +++++++++++++++++++++++++++++++------------------------- run.lua | 18 +++++++++ 2 files changed, 83 insertions(+), 52 deletions(-) diff --git a/!_G.yml b/!_G.yml index 6da4a2f..ea27486 100644 --- a/!_G.yml +++ b/!_G.yml @@ -1,22 +1,22 @@ -__root__: &t0xc4e478 +__root__: &t0x8ec478 _VERSION: "Lua 5.2" - add_zeros: f0xc56f38 + add_zeros: f0x8ec3f0 assert: f0x1fefc collectgarbage: f0x1f930 dofile: f0x1fe7c - dump: f0xc578c0 + dump: f0x8f1410 error: f0x1f8c0 - getaddr: f0xc53f00 + getaddr: f0x8f4c30 getmetatable: f0x1fe2c ipairs: f0x1fd24 load: f0x1ff54 loadfile: f0x1fd80 loadstring: f0x1ff54 - mixed_sorter: f0xc56ef0 - module: f0xc4ee20 + mixed_sorter: f0x8f1c28 + module: f0x8ece20 next: f0x1f7ac - opairs: f0xc53630 - order_keys: f0xc56ea8 + opairs: f0x8f4da0 + order_keys: f0x8f4cc0 pairs: f0x1fd04 pcall: f0x1fb50 print: f0x1f66c @@ -24,21 +24,21 @@ __root__: &t0xc4e478 rawget: f0x1f598 rawlen: f0x1f5d8 rawset: f0x1f54c - rawstr: f0xc56e60 - require: f0xc4fb00 + rawstr: f0x8f4c78 + require: f0x8edb00 select: f0x1f444 setmetatable: f0x1fbc0 - strpad: f0xc52890 + strpad: f0x8f34e8 tonumber: f0x1f25c tostring: f0x1f234 type: f0x1f1f8 unpack: f0x26598 xpcall: f0x1fa84 - _G: *t0xc4e478 - arg: &t0xc526b8 + _G: *t0x8ec478 + arg: &t0x8f06b8 "-1": "/usr/bin/lua" 0: "./run.lua" - bit32: &t0xc4f190 + bit32: &t0x8ed190 arshift: f0x2022c band: f0x20458 bnot: f0x20208 @@ -51,14 +51,14 @@ __root__: &t0xc4e478 replace: f0x20338 rrotate: f0x201c4 rshift: f0x2015c - coroutine: &t0xc4e998 + coroutine: &t0x8ec998 create: f0x20844 resume: f0x20934 running: f0x20824 status: f0x206cc wrap: f0x20888 yield: f0x20584 - debug: &t0xc507c8 + debug: &t0x8ee7c8 debug: f0x20e44 gethook: f0x21470 getinfo: f0x21674 @@ -75,7 +75,7 @@ __root__: &t0xc4e478 traceback: f0x20ff8 upvalueid: f0x20ca0 upvaluejoin: f0x20cd8 - io: &t0xc4ffe8 + io: &t0x8edfe8 close: f0x21c94 flush: f0x22328 input: f0x22a28 @@ -84,13 +84,13 @@ __root__: &t0xc4e478 output: f0x22a0c popen: f0x2238c read: f0x222dc - stderr: "file (0x76ee69d8)" - stdin: "file (0x76ee6c98)" - stdout: "file (0x76ee6b38)" + stderr: "file (0x76e559d8)" + stdin: "file (0x76e55c98)" + stdout: "file (0x76e55b38)" tmpfile: f0x22c70 type: f0x22890 write: f0x21ba8 - math: &t0xc51a10 + math: &t0x8efa10 abs: f0x22e48 acos: f0x234c8 asin: f0x234a4 @@ -121,7 +121,7 @@ __root__: &t0xc4e478 sqrt: f0x22eb4 tan: f0x22e6c tanh: f0x22e90 - os: &t0xc4fd90 + os: &t0x8edd90 clock: f0x237d8 date: f0x23ac0 difftime: f0x23758 @@ -133,7 +133,7 @@ __root__: &t0xc4e478 setlocale: f0x23580 time: f0x23930 tmpname: f0x23810 - package: &t0xc4ee90 + package: &t0x8ece90 config: "\ /\ ;\ @@ -146,35 +146,35 @@ __root__: &t0xc4e478 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: *t0xc4f5b0 - loaded: &t0xc4e948 + searchers: *t0x8ed5b0 + loaded: &t0x8ec948 extra: true - _G: *t0xc4e478 - bit32: *t0xc4f190 - coroutine: *t0xc4e998 - debug: *t0xc507c8 - io: *t0xc4ffe8 - math: *t0xc51a10 - os: *t0xc4fd90 - package: *t0xc4ee90 - string: *t0xc4f340 - table: *t0xc4fb68 - pt: &t0xc56a90 - __call: f0xc52a58 - inner: f0xc55c50 - outer: f0xc55ce8 - safekey: f0xc57890 - safeval: f0xc578a8 - write: f0xc56f08 - __index: *t0xc56a90 - __metatable: *t0xc56a90 - loaders: &t0xc4f5b0 - 1: f0xc4f620 - 2: f0xc4f648 - 3: f0xc4f670 - 4: f0xc4f698 - preload: &t0xc4f720 - string: &t0xc4f340 + _G: *t0x8ec478 + bit32: *t0x8ed190 + coroutine: *t0x8ec998 + debug: *t0x8ee7c8 + io: *t0x8edfe8 + math: *t0x8efa10 + os: *t0x8edd90 + package: *t0x8ece90 + string: *t0x8ed340 + table: *t0x8edb68 + pt: &t0x8f5be8 + __call: f0x8f12a0 + inner: f0x8f5a10 + outer: f0x8f4de0 + safekey: f0x8f1dc0 + safeval: f0x8ec230 + write: f0x8f3890 + __index: *t0x8f5be8 + __metatable: *t0x8f5be8 + loaders: &t0x8ed5b0 + 1: f0x8ed620 + 2: f0x8ed648 + 3: f0x8ed670 + 4: f0x8ed698 + preload: &t0x8ed720 + string: &t0x8ed340 byte: f0x25234 char: f0x24768 dump: f0x254d4 @@ -189,7 +189,20 @@ __root__: &t0xc4e478 reverse: f0x23fb8 sub: f0x2518c upper: f0x23ed8 - table: &t0xc4fb68 + t: &t0x8f1bd0 + C: hello + D: *t0x8f1bd0 + A: &t0x8f1d98 + a: beep + b: boop + c: burp + d: *t0x8f5f90 + B: &t0x8f5f90 + a: nude + b: dude + c: lewd + d: *t0x8f1d98 + table: &t0x8edb68 concat: f0x2691c insert: f0x26688 maxn: f0x26818 diff --git a/run.lua b/run.lua index 345bc65..141c9f9 100755 --- a/run.lua +++ b/run.lua @@ -1,6 +1,23 @@ #!/usr/bin/lua local pt = require('pt') +t = { + A = { + a = 'beep', + b = 'boop', + c = 'burp', + }, + B = { + a = 'nude', + b = 'dude', + c = 'lewd', + }, + C = 'hello', +} +t.A.d = t.B +t.B.d = t.A +t.D = t + function dump(t, fn, seen) if t == nil then return end @@ -19,4 +36,5 @@ function dump(t, fn, seen) return seen end +pt(t) dump(_G, '!_G.yml') From 051265ea3a67c01fbf9a4f2f20f91019a7826ddf Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 25 Aug 2014 22:51:45 -0700 Subject: [PATCH 04/10] smarter string quoting --- !_G.yml => _G.yml | 126 +++++++++++++++++++++++----------------------- pt.lua | 3 +- run.lua | 2 +- 3 files changed, 66 insertions(+), 65 deletions(-) rename !_G.yml => _G.yml (64%) diff --git a/!_G.yml b/_G.yml similarity index 64% rename from !_G.yml rename to _G.yml index ea27486..0f0e5a9 100644 --- a/!_G.yml +++ b/_G.yml @@ -1,22 +1,22 @@ -__root__: &t0x8ec478 - _VERSION: "Lua 5.2" - add_zeros: f0x8ec3f0 +__root__: &t0x6f478 + _VERSION: Lua 5.2 + add_zeros: f0x73838 assert: f0x1fefc collectgarbage: f0x1f930 dofile: f0x1fe7c - dump: f0x8f1410 + dump: f0x78770 error: f0x1f8c0 - getaddr: f0x8f4c30 + getaddr: f0x74c40 getmetatable: f0x1fe2c ipairs: f0x1fd24 load: f0x1ff54 loadfile: f0x1fd80 loadstring: f0x1ff54 - mixed_sorter: f0x8f1c28 - module: f0x8ece20 + mixed_sorter: f0x76c28 + module: f0x6fe20 next: f0x1f7ac - opairs: f0x8f4da0 - order_keys: f0x8f4cc0 + opairs: f0x74c88 + order_keys: f0x74cd0 pairs: f0x1fd04 pcall: f0x1fb50 print: f0x1f66c @@ -24,21 +24,21 @@ __root__: &t0x8ec478 rawget: f0x1f598 rawlen: f0x1f5d8 rawset: f0x1f54c - rawstr: f0x8f4c78 - require: f0x8edb00 + rawstr: f0x76460 + require: f0x70b00 select: f0x1f444 setmetatable: f0x1fbc0 - strpad: f0x8f34e8 + strpad: f0x73e60 tonumber: f0x1f25c tostring: f0x1f234 type: f0x1f1f8 unpack: f0x26598 xpcall: f0x1fa84 - _G: *t0x8ec478 - arg: &t0x8f06b8 - "-1": "/usr/bin/lua" - 0: "./run.lua" - bit32: &t0x8ed190 + _G: *t0x6f478 + arg: &t0x736b8 + "-1": /usr/bin/lua + 0: ./run.lua + bit32: &t0x70190 arshift: f0x2022c band: f0x20458 bnot: f0x20208 @@ -51,14 +51,14 @@ __root__: &t0x8ec478 replace: f0x20338 rrotate: f0x201c4 rshift: f0x2015c - coroutine: &t0x8ec998 + coroutine: &t0x6f998 create: f0x20844 resume: f0x20934 running: f0x20824 status: f0x206cc wrap: f0x20888 yield: f0x20584 - debug: &t0x8ee7c8 + debug: &t0x717c8 debug: f0x20e44 gethook: f0x21470 getinfo: f0x21674 @@ -75,7 +75,7 @@ __root__: &t0x8ec478 traceback: f0x20ff8 upvalueid: f0x20ca0 upvaluejoin: f0x20cd8 - io: &t0x8edfe8 + io: &t0x70fe8 close: f0x21c94 flush: f0x22328 input: f0x22a28 @@ -84,13 +84,13 @@ __root__: &t0x8ec478 output: f0x22a0c popen: f0x2238c read: f0x222dc - stderr: "file (0x76e559d8)" - stdin: "file (0x76e55c98)" - stdout: "file (0x76e55b38)" + stderr: file (0x76e4f9d8) + stdin: file (0x76e4fc98) + stdout: file (0x76e4fb38) tmpfile: f0x22c70 type: f0x22890 write: f0x21ba8 - math: &t0x8efa10 + math: &t0x72a10 abs: f0x22e48 acos: f0x234c8 asin: f0x234a4 @@ -121,7 +121,7 @@ __root__: &t0x8ec478 sqrt: f0x22eb4 tan: f0x22e6c tanh: f0x22e90 - os: &t0x8edd90 + os: &t0x70d90 clock: f0x237d8 date: f0x23ac0 difftime: f0x23758 @@ -133,7 +133,7 @@ __root__: &t0x8ec478 setlocale: f0x23580 time: f0x23930 tmpname: f0x23810 - package: &t0x8ece90 + package: &t0x6fe90 config: "\ /\ ;\ @@ -141,40 +141,40 @@ __root__: &t0x8ec478 !\ -\ " - cpath: "/usr/lib/lua/5.2/?.so;/usr/lib/lua/5.2/loadall.so;./?.so" + 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" + 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: *t0x8ed5b0 - loaded: &t0x8ec948 + searchers: *t0x705b0 + loaded: &t0x6f948 extra: true - _G: *t0x8ec478 - bit32: *t0x8ed190 - coroutine: *t0x8ec998 - debug: *t0x8ee7c8 - io: *t0x8edfe8 - math: *t0x8efa10 - os: *t0x8edd90 - package: *t0x8ece90 - string: *t0x8ed340 - table: *t0x8edb68 - pt: &t0x8f5be8 - __call: f0x8f12a0 - inner: f0x8f5a10 - outer: f0x8f4de0 - safekey: f0x8f1dc0 - safeval: f0x8ec230 - write: f0x8f3890 - __index: *t0x8f5be8 - __metatable: *t0x8f5be8 - loaders: &t0x8ed5b0 - 1: f0x8ed620 - 2: f0x8ed648 - 3: f0x8ed670 - 4: f0x8ed698 - preload: &t0x8ed720 - string: &t0x8ed340 + _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 @@ -189,20 +189,20 @@ __root__: &t0x8ec478 reverse: f0x23fb8 sub: f0x2518c upper: f0x23ed8 - t: &t0x8f1bd0 + t: &t0x74a30 C: hello - D: *t0x8f1bd0 - A: &t0x8f1d98 + D: *t0x74a30 + A: &t0x74b78 a: beep b: boop c: burp - d: *t0x8f5f90 - B: &t0x8f5f90 + d: *t0x786c0 + B: &t0x786c0 a: nude b: dude c: lewd - d: *t0x8f1d98 - table: &t0x8edb68 + d: *t0x74b78 + table: &t0x70b68 concat: f0x2691c insert: f0x26688 maxn: f0x26818 diff --git a/pt.lua b/pt.lua index 1350456..f5116c4 100755 --- a/pt.lua +++ b/pt.lua @@ -53,7 +53,8 @@ function pt.safeval(v, indent) return s end s = s:find('[\r\n]') and ('\n'..s):gsub('[\r\n]', '\n'..indent..' ') or s - return s:find('[^%w_]') and ('%q'):format(s) or s + local safe = ('%q'):format(s) + return s == safe:sub(2, -2) and s or safe end function pt:inner(k, v, indent) diff --git a/run.lua b/run.lua index 141c9f9..5e9e49d 100755 --- a/run.lua +++ b/run.lua @@ -37,4 +37,4 @@ function dump(t, fn, seen) end pt(t) -dump(_G, '!_G.yml') +dump(_G, '_G.yml') From 176b8b32b00e13c20120385321de94ada9a00465 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 21 Nov 2015 20:01:40 -0800 Subject: [PATCH 05/10] . --- _G.yml | 428 ++++++++++++++++++++++++++++++-------------------------- pt.lua | 42 ++++-- run.lua | 4 +- 3 files changed, 261 insertions(+), 213 deletions(-) diff --git a/_G.yml b/_G.yml index 0f0e5a9..110388b 100644 --- a/_G.yml +++ b/_G.yml @@ -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 diff --git a/pt.lua b/pt.lua index f5116c4..5f16f1b 100755 --- a/pt.lua +++ b/pt.lua @@ -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 diff --git a/run.lua b/run.lua index 5e9e49d..5468bcf 100755 --- a/run.lua +++ b/run.lua @@ -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') From 6fb6d3ba629fce35345232d4a60753e1ff0cafee Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 11 Dec 2016 03:54:59 -0800 Subject: [PATCH 06/10] . --- extra.lua | 34 +++++++++++++++++++++++++++++----- pt.lua | 9 +++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/extra.lua b/extra.lua index 68e7afb..c0aa538 100755 --- a/extra.lua +++ b/extra.lua @@ -1,13 +1,13 @@ -function strpad(num, count, pad) +local function strpad(num, count, pad) num = tostring(num) return (pad:rep(count)..num):sub(#num) end -function add_zeros(num, count) +local function add_zeros(num, count) return strpad(num, count - 1, '0') end -function mixed_sorter(a, b) +local function mixed_sorter(a, b) a = type(a) == 'number' and add_zeros(a, 16) or tostring(a) b = type(b) == 'number' and add_zeros(b, 16) or tostring(b) return a < b @@ -15,7 +15,7 @@ end -- loosely based on http://lua-users.org/wiki/SortedIteration -- the original didn't make use of closures for who knows why -function order_keys(t) +local function order_keys(t) local oi = {} for key in pairs(t) do table.insert(oi, key) @@ -24,7 +24,7 @@ function order_keys(t) return oi end -function opairs(t, cache) +local function opairs(t, cache) local oi = cache and cache[t] or order_keys(t) if cache then cache[t] = oi @@ -36,3 +36,27 @@ function opairs(t, cache) if key then return key, t[key] end end end + +local function traverse(path) + if not path then return end + local parent = _G + local key + for w in path:gfind("[%w_]+") do + if key then + parent = rawget(parent, key) + if type(parent) ~= 'table' then return end + end + key = w + end + if not key then return end + return {parent=parent, key=key} +end + +return { + strpad = strpad, + add_zeros = add_zeros, + mixed_sorter = mixed_sorter, + order_keys = order_keys, + opairs = opairs, + traverse = traverse, +} diff --git a/pt.lua b/pt.lua index 5f16f1b..19c7e4c 100755 --- a/pt.lua +++ b/pt.lua @@ -1,10 +1,11 @@ -require 'extra' +local extra = require 'extra' +local opairs = extra.opairs local pt = {} pt.__index = pt setmetatable(pt, pt) -function rawstr(v) +local function rawstr(v) if v == nil then return 'nil' end local mt = getmetatable(v) local ts = mt and rawget(mt, '__tostring') @@ -15,11 +16,11 @@ function rawstr(v) return s end -function getaddr(t) +local function getaddr(t) return rawstr(t):sub(#type(t) + 3) end -function copy(t) +local function copy(t) -- shallow copy if type(t) ~= 'table' then return end local new = {} From c76f1729755743729fd901ee39ff329cef998cf9 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 11 Dec 2016 04:02:36 -0800 Subject: [PATCH 07/10] . --- init.lua | 2 ++ pt.lua | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 init.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e60915d --- /dev/null +++ b/init.lua @@ -0,0 +1,2 @@ +local path = string.gsub(..., "[^.]+$", "") +return require(path.."pt") diff --git a/pt.lua b/pt.lua index 19c7e4c..6fe9ef9 100755 --- a/pt.lua +++ b/pt.lua @@ -1,4 +1,5 @@ -local extra = require 'extra' +local path = string.gsub(..., "[^.]+$", "") +local extra = require(path.."extra") local opairs = extra.opairs local pt = {} From af75dcc7c51fc2eb826c66a4fd83caa93e016ca3 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 11 Dec 2016 04:56:57 -0800 Subject: [PATCH 08/10] . --- extra.lua | 13 +++++++--- pt.lua | 74 ++++++++++++++++++++++++++++++++++++++++++------------- run.lua | 13 +++++----- 3 files changed, 74 insertions(+), 26 deletions(-) diff --git a/extra.lua b/extra.lua index c0aa538..fb5982b 100755 --- a/extra.lua +++ b/extra.lua @@ -1,3 +1,10 @@ +local insert = table.insert +local pairs = pairs +local rawget = rawget +local sort = table.sort +local tostring = tostring +local type = type + local function strpad(num, count, pad) num = tostring(num) return (pad:rep(count)..num):sub(#num) @@ -18,9 +25,9 @@ end local function order_keys(t) local oi = {} for key in pairs(t) do - table.insert(oi, key) + insert(oi, key) end - table.sort(oi, mixed_sorter) + sort(oi, mixed_sorter) return oi end @@ -33,7 +40,7 @@ local function opairs(t, cache) return function() i = i + 1 local key = oi[i] - if key then return key, t[key] end + if key ~= nil then return key, t[key] end end end diff --git a/pt.lua b/pt.lua index 6fe9ef9..6eea391 100755 --- a/pt.lua +++ b/pt.lua @@ -25,8 +25,8 @@ local function copy(t) -- shallow copy if type(t) ~= 'table' then return end local new = {} - for key, value in pairs(t) do - new[key] = value + for k,v in pairs(t) do + new[k] = v end return new end @@ -43,7 +43,10 @@ function pt.__call(pt, args) self.depth = args.depth or 16 self.writer = args.writer or io.write self.skeleton = args.skeleton or false + self.outer = args.alt_order and self.outer_old or self.outer + self.indent = args.indent or ' ' self.queued = {} + self.cache = {} self:inner('__root__', t, '') return self.seen end @@ -61,7 +64,7 @@ function pt.safekey(k) return s:find('[^%w_]') and ('%q'):format(s) or s end -function pt.safeval(v, indent) +function pt.safeval(v, indentation, indent) if type(v) == 'function' then return 'f'..getaddr(v) end @@ -69,25 +72,28 @@ function pt.safeval(v, indent) if type(v) == 'number' then return s end - s = s:find('[\r\n]') and ('\n'..s):gsub('[\r\n]', '\n'..indent..' ') or s + -- TODO: move newline/indentation handling to another function? + if s:find('[\r\n]') then + s = ('\n'..s):gsub('[\r\n]', '\n'..indentation..indent) + end --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) +function pt:inner(k, v, indentation) if type(v) ~= 'table' then if self.skeleton then return end - self:write(indent, pt.safekey(k), ': ') - self:write(pt.safeval(v, indent), '\n') + self:write(indentation, pt.safekey(k), ': ') + self:write(pt.safeval(v, indentation, self.indent), '\n') return end local addr = getaddr(v) - self:write(indent, pt.safekey(k)) + self:write(indentation, pt.safekey(k)) - if #indent > self.depth or self.skipped[addr] then + if #indentation > self.depth or self.skipped[addr] then --self.skipped[addr] = true -- TODO: extra logics self:write(': #t', addr, '\n') return @@ -101,12 +107,13 @@ function pt:inner(k, v, indent) self.seen[addr] = true self:write(': &t', addr, '\n') - self:outer(v, indent..' ') + self:outer(v, indentation..self.indent) end -function pt:outer(t, indent) +function pt:outer_old(t, indentation) if type(t) ~= "table" then - self:write(indent, pt.safeval(t, indent), '\n') + local s = pt.safeval(t, indentation, self.indent) + self:write(indentation, s, '\n') return end @@ -116,29 +123,62 @@ 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] and not self.skipped[addr] then + if not (self.queued[addr] or self.seen[addr] or self.skipped[addr]) then self.queued[addr] = true ours[k] = v else not_ours[k] = v end else - self:inner(k, v, indent) + self:inner(k, v, indentation) end end for k,v in opairs(not_ours) do - self:inner(k, v, indent) + self:inner(k, v, indentation) end for k,v in opairs(ours) do self.queued[getaddr(v)] = nil - self:inner(k, v, indent) + self:inner(k, v, indentation) end local mt = getmetatable(t) if mt ~= nil then - self:inner('__metatable', mt, indent) + self:inner('__metatable', mt, indentation) + end +end + +function pt:outer(t, indentation) + if type(t) ~= "table" then + local s = pt.safeval(t, indentation, self.indent) + self:write(indentation, s, '\n') + return + end + + local ours = {} + + for k,v in opairs(t, self.cache) do + if type(v) == 'table' then + local addr = getaddr(v) + if not (self.queued[addr] or self.seen[addr] or self.skipped[addr]) then + self.queued[addr] = true + ours[k] = addr + end + end + end + + local mt = getmetatable(t) + if mt ~= nil then + self:inner('__metatable', mt, indentation) + end + + for k,v in opairs(t, self.cache) do + local addr = ours[k] + if addr then + self.queued[addr] = nil + end + self:inner(k, v, indentation) end end diff --git a/run.lua b/run.lua index 5468bcf..63f3c00 100755 --- a/run.lua +++ b/run.lua @@ -2,21 +2,22 @@ local pt = require('pt') t = { - A = { + A = 'hello', + B = { a = 'beep', b = 'boop', c = 'burp', }, - B = { + C = { a = 'nude', b = 'dude', c = 'lewd', }, - C = 'hello', + D = 'goodbye', } -t.A.d = t.B -t.B.d = t.A -t.D = t +t.B.d = t.C +t.C.d = t.B +t.E = t function dump(t, fn, seen) if t == nil then return end From 959be1635080b5cf0f0639711612aed2d178f0c8 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 11 Dec 2016 05:22:03 -0800 Subject: [PATCH 09/10] . --- pt.lua | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/pt.lua b/pt.lua index 6eea391..821634f 100755 --- a/pt.lua +++ b/pt.lua @@ -44,10 +44,12 @@ function pt.__call(pt, args) self.writer = args.writer or io.write self.skeleton = args.skeleton or false self.outer = args.alt_order and self.outer_old or self.outer + self.noncanon = args.noncanon or false self.indent = args.indent or ' ' self.queued = {} self.cache = {} - self:inner('__root__', t, '') + self.canonicalized = {} + self:inner('__root', t, '') return self.seen end @@ -55,7 +57,12 @@ function pt:write(...) self.writer(...) end -function pt.safekey(k) +function pt:safecanon(k) + local s = tostring(k) + return s:gsub('[^%w_]', '_') +end + +function pt:safekey(k) if type(k) == 'table' then return 't'..getaddr(k) end @@ -64,7 +71,7 @@ function pt.safekey(k) return s:find('[^%w_]') and ('%q'):format(s) or s end -function pt.safeval(v, indentation, indent) +function pt:safeval(v, indentation) if type(v) == 'function' then return 'f'..getaddr(v) end @@ -74,7 +81,7 @@ function pt.safeval(v, indentation, indent) end -- TODO: move newline/indentation handling to another function? if s:find('[\r\n]') then - s = ('\n'..s):gsub('[\r\n]', '\n'..indentation..indent) + s = ('\n'..s):gsub('[\r\n]', '\n'..indentation..self.indent) end --local safe = ('%q'):format(s) --return s == safe:sub(2, -2) and s or safe @@ -85,34 +92,45 @@ end function pt:inner(k, v, indentation) if type(v) ~= 'table' then if self.skeleton then return end - self:write(indentation, pt.safekey(k), ': ') - self:write(pt.safeval(v, indentation, self.indent), '\n') + self:write(indentation, self:safekey(k), ': ') + self:write(self:safeval(v, indentation), '\n') return end local addr = getaddr(v) - self:write(indentation, pt.safekey(k)) + self:write(indentation, self:safekey(k)) + + local canon + if not self.noncanon and type(k) ~= 'table' then + canon = self.canonicalized[addr] + if canon == nil then + canon = self:safecanon(k)..'_t'..addr + self.canonicalized[addr] = canon + end + else + canon = 't'..addr + end if #indentation > self.depth or self.skipped[addr] then --self.skipped[addr] = true -- TODO: extra logics - self:write(': #t', addr, '\n') + self:write(': #', canon, '\n') return end if self.seen[addr] or self.queued[addr] then - self:write(': *t', addr, self.seen_elsewhere[addr] and ' #\n' or '\n') + self:write(': *', canon, self.seen_elsewhere[addr] and ' #\n' or '\n') return end self.seen[addr] = true - self:write(': &t', addr, '\n') + self:write(': &', canon, '\n') self:outer(v, indentation..self.indent) end function pt:outer_old(t, indentation) if type(t) ~= "table" then - local s = pt.safeval(t, indentation, self.indent) + local s = self:safeval(t, indentation) self:write(indentation, s, '\n') return end @@ -151,7 +169,7 @@ end function pt:outer(t, indentation) if type(t) ~= "table" then - local s = pt.safeval(t, indentation, self.indent) + local s = self:safeval(t, indentation) self:write(indentation, s, '\n') return end From 2c824ad30b04e81f95f634d65c6ace25505b7f33 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 11 Dec 2016 05:23:17 -0800 Subject: [PATCH 10/10] _G --- _G.yml | 402 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 206 insertions(+), 196 deletions(-) diff --git a/_G.yml b/_G.yml index 110388b..52da894 100644 --- a/_G.yml +++ b/_G.yml @@ -1,236 +1,246 @@ -__root__: &t0xfff91348 +__root: &__root_t0x4004f960 + _G: *__root_t0x4004f960 _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 + arg: &arg_t0x40055cc8 "-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 + assert: fbuiltin#2 + bit: &bit_t0x40054d58 + arshift: fbuiltin#70 + band: fbuiltin#73 + bnot: fbuiltin#66 + bor: fbuiltin#74 + bswap: fbuiltin#67 + bxor: fbuiltin#75 + lshift: fbuiltin#68 + rol: fbuiltin#71 + ror: fbuiltin#72 + rshift: fbuiltin#69 + tobit: fbuiltin#65 + tohex: fbuiltin#76 + collectgarbage: fbuiltin#27 + coroutine: &coroutine_t0x40051730 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 + debug: &debug_t0x40054740 + debug: fbuiltin#145 + getfenv: fbuiltin#134 + gethook: fbuiltin#144 + getinfo: fbuiltin#136 + getlocal: fbuiltin#137 + getmetatable: fbuiltin#132 + getregistry: fbuiltin#131 + getupvalue: fbuiltin#139 + setfenv: fbuiltin#135 + sethook: fbuiltin#143 + setlocal: fbuiltin#138 + setmetatable: fbuiltin#133 + setupvalue: fbuiltin#140 + traceback: fbuiltin#146 + upvalueid: fbuiltin#141 + upvaluejoin: fbuiltin#142 + dofile: fbuiltin#25 + dump: f0x4005dd40 + error: fbuiltin#19 + gcinfo: fbuiltin#26 + getfenv: fbuiltin#10 + getmetatable: fbuiltin#8 + io: &io_t0x40052a90 + close: fbuiltin#112 + flush: fbuiltin#115 + input: fbuiltin#116 + lines: fbuiltin#118 + open: fbuiltin#109 + output: fbuiltin#117 + popen: fbuiltin#110 + read: fbuiltin#113 + stderr: file (0x7ff9dd21f500) + stdin: file (0x7ff9dd21e8a0) + stdout: file (0x7ff9dd21f5e0) + tmpfile: fbuiltin#111 + type: fbuiltin#119 + write: fbuiltin#114 + ipairs: fbuiltin#7 + jit: &jit_t0x40055318 + arch: x64 + attach: fbuiltin#151 + flush: fbuiltin#149 + off: fbuiltin#148 + on: fbuiltin#147 + opt: &opt_t0x40055bd8 + start: fbuiltin#163 + os: Linux + status: fbuiltin#150 + util: &util_t0x400556a0 + funcbc: fbuiltin#153 + funcinfo: fbuiltin#152 + funck: fbuiltin#154 + funcuvname: fbuiltin#155 + ircalladdr: fbuiltin#162 + traceexitstub: fbuiltin#161 + traceinfo: fbuiltin#156 + traceir: fbuiltin#157 + tracek: fbuiltin#158 + tracemc: fbuiltin#160 + tracesnap: fbuiltin#159 + version: LuaJIT 2.0.4 + version_num: 20004 + load: fbuiltin#23 + loadfile: fbuiltin#22 + loadstring: fbuiltin#24 + math: &math_t0x40053b60 abs: fbuiltin#37 acos: fbuiltin#47 asin: fbuiltin#46 atan: fbuiltin#48 - atan2: fbuiltin#55 + atan2: fbuiltin#57 ceil: fbuiltin#39 cos: fbuiltin#44 cosh: fbuiltin#50 - deg: f0xfff95a48 + deg: fbuiltin#54 exp: fbuiltin#42 floor: fbuiltin#38 - fmod: fbuiltin#57 + fmod: fbuiltin#59 frexp: fbuiltin#52 huge: inf - ldexp: fbuiltin#58 - log: fbuiltin#54 + ldexp: fbuiltin#60 + log: fbuiltin#56 log10: fbuiltin#41 - max: fbuiltin#60 - min: fbuiltin#59 - mod: fbuiltin#57 + max: fbuiltin#62 + min: fbuiltin#61 + mod: fbuiltin#59 modf: fbuiltin#53 pi: 3.1415926535898 - pow: fbuiltin#56 - rad: f0xfff95ad8 - random: fbuiltin#61 - randomseed: fbuiltin#62 + pow: fbuiltin#58 + rad: fbuiltin#55 + random: fbuiltin#63 + randomseed: fbuiltin#64 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 + module: f0x40051ee0 + newproxy: fbuiltin#28 + next: fbuiltin#4 + os: &os_t0x40052fd0 + clock: fbuiltin#126 + date: fbuiltin#127 + difftime: fbuiltin#129 + execute: fbuiltin#120 + exit: fbuiltin#125 + getenv: fbuiltin#124 + remove: fbuiltin#121 + rename: fbuiltin#122 + setlocale: fbuiltin#130 + time: fbuiltin#128 + tmpname: fbuiltin#123 + package: &package_t0x40051ac8 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: *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: *t0xfff9a1c0 - A: &t0xfff9a978 + cpath: /home/notwa/opt/local/lib/?.so;/home/notwa/.luarocks/lib/lua/5.1/?.so;/home/notwa/opt/local/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so + loaded: &loaded_t0x40050b38 + _G: *__root_t0x4004f960 + bit: *bit_t0x40054d58 + coroutine: *coroutine_t0x40051730 + debug: *debug_t0x40054740 + extra: &extra_t0x4005cd30 + add_zeros: f0x4005db58 + mixed_sorter: f0x4005db98 + opairs: f0x4005cca8 + order_keys: f0x4005b2f8 + strpad: f0x4004f8b8 + traverse: f0x4005cce8 + io: *io_t0x40052a90 + jit: *jit_t0x40055318 + "jit.opt": *opt_t0x40055bd8 + "jit.util": *util_t0x400556a0 + math: *math_t0x40053b60 + os: *os_t0x40052fd0 + package: *package_t0x40051ac8 + pt: &pt_t0x4005ce20 + __metatable: *pt_t0x4005ce20 + __call: f0x4005dc98 + __index: *pt_t0x4005ce20 + inner: f0x4005dde0 + outer: f0x4005dd18 + outer_old: f0x4005dc00 + safecanon: f0x4005dd60 + safekey: f0x4005dd80 + safeval: f0x4005ddc0 + write: f0x4005dcd8 + string: *string_t0x400534b0 + table: *table_t0x400522f8 + loaders: &loaders_t0x40051c38 + 1: f0x40051c88 + 2: f0x40051cb0 + 3: f0x40051cd8 + 4: f0x40051d00 + loadlib: f0x40051b58 + path: /home/notwa/.luarocks/share/lua/5.1/?.lua;/home/notwa/.luarocks/share/lua/5.1/?/init.lua;/home/notwa/opt/local/share/lua/5.1/?.lua;/home/notwa/opt/local/share/lua/5.1/?/init.lua;./?.lua;/home/notwa/opt/local/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua + preload: &preload_t0x400520c0 + ffi: f0x40055c80 + searchpath: f0x40051ba0 + seeall: f0x40051bf0 + pairs: fbuiltin#5 + pcall: fbuiltin#20 + print: fbuiltin#29 + rawequal: fbuiltin#14 + rawget: fbuiltin#12 + rawset: fbuiltin#13 + require: f0x40051f28 + select: fbuiltin#16 + setfenv: fbuiltin#11 + setmetatable: fbuiltin#9 + string: &string_t0x400534b0 + byte: fbuiltin#78 + char: fbuiltin#79 + dump: fbuiltin#85 + find: fbuiltin#86 + format: fbuiltin#91 + gfind: fbuiltin#89 + gmatch: fbuiltin#89 + gsub: fbuiltin#90 + len: fbuiltin#77 + lower: fbuiltin#83 + match: fbuiltin#87 + rep: fbuiltin#81 + reverse: fbuiltin#82 + sub: fbuiltin#80 + upper: fbuiltin#84 + t: &t_t0x4005e298 + A: hello + B: &B_t0x4005e328 a: beep b: boop c: burp - d: *t0xfff9a9a0 - B: &t0xfff9a9a0 + d: *d_t0x4005e550 + C: &d_t0x4005e550 a: nude b: dude c: lewd - d: *t0xfff9a978 - table: &t0xfff93638 - concat: fbuiltin#91 - foreach: f0xfff93b70 - foreachi: f0xfff93aa8 - getn: f0xfff93c00 - insert: fbuiltin#90 - maxn: fbuiltin#89 - remove: f0xfff93d90 - sort: fbuiltin#92 + d: *B_t0x4005e328 + D: goodbye + E: *t_t0x4005e298 + table: &table_t0x400522f8 + concat: fbuiltin#98 + foreach: fbuiltin#93 + foreachi: fbuiltin#92 + getn: fbuiltin#94 + insert: fbuiltin#96 + maxn: fbuiltin#95 + remove: fbuiltin#97 + sort: fbuiltin#99 + tonumber: fbuiltin#17 + tostring: fbuiltin#18 + type: fbuiltin#3 + unpack: fbuiltin#15 + xpcall: fbuiltin#21