Last active
March 28, 2018 10:36
-
-
Save gering/d371ab7ccfbd74ed53e147a2a24ba2a9 to your computer and use it in GitHub Desktop.
Print a Lua 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
function tprint(t, s) | |
for k, v in pairs(t) do | |
local kfmt = '["' .. tostring(k) ..'"]' | |
if type(k) ~= 'string' then | |
kfmt = '[' .. k .. ']' | |
end | |
local vfmt = '"'.. tostring(v) ..'"' | |
if type(v) == 'table' then | |
tprint(v, (s or '')..kfmt) | |
else | |
if type(v) ~= 'string' then | |
vfmt = tostring(v) | |
end | |
print(type(t)..(s or '')..kfmt..' = '..vfmt) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment