Skip to content

Instantly share code, notes, and snippets.

@saga
Created January 4, 2010 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saga/268361 to your computer and use it in GitHub Desktop.
Save saga/268361 to your computer and use it in GitHub Desktop.
Lua print table
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