Skip to content

Instantly share code, notes, and snippets.

@gering
Last active March 28, 2018 10:36
Show Gist options
  • Save gering/d371ab7ccfbd74ed53e147a2a24ba2a9 to your computer and use it in GitHub Desktop.
Save gering/d371ab7ccfbd74ed53e147a2a24ba2a9 to your computer and use it in GitHub Desktop.
Print a Lua table
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