diff options
author | chai <chaifix@163.com> | 2021-11-15 13:53:59 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-15 13:53:59 +0800 |
commit | 942a030afd348ab2e02eac8054b43e3c3a72ea48 (patch) | |
tree | a13459f39a3d2f1b533fbd1b5ab523d7a621f673 /Tools/lua-snapshot/print_r.lua | |
parent | e307051a56a54c27f10438fd2025edf61d0dfeed (diff) |
*rename
Diffstat (limited to 'Tools/lua-snapshot/print_r.lua')
-rw-r--r-- | Tools/lua-snapshot/print_r.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Tools/lua-snapshot/print_r.lua b/Tools/lua-snapshot/print_r.lua new file mode 100644 index 0000000..3a4a710 --- /dev/null +++ b/Tools/lua-snapshot/print_r.lua @@ -0,0 +1,31 @@ +local print = print +local tconcat = table.concat +local tinsert = table.insert +local srep = string.rep +local type = type +local pairs = pairs +local tostring = tostring +local next = next + +local function print_r(root) + local cache = { [root] = "." } + local function _dump(t,space,name) + local temp = {} + for k,v in pairs(t) do + local key = tostring(k) + if cache[v] then + tinsert(temp,"+" .. key .. " {" .. cache[v].."}") + elseif type(v) == "table" then + local new_key = name .. "." .. key + cache[v] = new_key + tinsert(temp,"+" .. key .. _dump(v,space .. (next(t,k) and "|" or " " ).. srep(" ",#key),new_key)) + else + tinsert(temp,"+" .. key .. " [" .. tostring(v).."]") + end + end + return tconcat(temp,"\n"..space) + end + print(_dump(root, "","")) +end + +return print_r
\ No newline at end of file |