Skip to content

Instantly share code, notes, and snippets.

@feihuroger
Forked from rangercyh/print_lua_table.lua
Created June 3, 2014 07:27
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 feihuroger/b26b1cd0399a7d7cc131 to your computer and use it in GitHub Desktop.
Save feihuroger/b26b1cd0399a7d7cc131 to your computer and use it in GitHub Desktop.
function print_lua_table (lua_table, indent)
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print(formatting)
print_lua_table(v, indent + 1)
print(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
print(formatting..szValue..",")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment