Skip to content

Instantly share code, notes, and snippets.

@darltrash
Forked from hashmal/gist:874792
Last active April 2, 2021 22:49
Show Gist options
  • Save darltrash/b10d2aaaba402eeb20679bec835683a1 to your computer and use it in GitHub Desktop.
Save darltrash/b10d2aaaba402eeb20679bec835683a1 to your computer and use it in GitHub Desktop.
[Lua] Print table contents recursively
-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function tprint (tbl, indent)
local indent = indent or 0
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
else
print(formatting .. tostring(v))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment