Created
January 4, 2010 06:42
-
-
Save saga/268361 to your computer and use it in GitHub Desktop.
Lua print table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local tconcat = table.concat | |
local tinsert = table.insert | |
local srep = string.rep | |
function print_table(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 | |
--local r_table = {} | |
--findindir ([[D:\EDSCAB_DEV_FEATURE_DAE\sswei\RSNetWorx\RSNW-VSS1\EDS]], "0001000C005C0100.eds", r_table, true) | |
--print("------ OK\n") | |
--for key, val in ipairs(r_table) do | |
-- print(val) | |
--end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment