Skip to content

Instantly share code, notes, and snippets.

@neerolyte
Created January 20, 2012 01:27
Show Gist options
  • Save neerolyte/1644379 to your computer and use it in GitHub Desktop.
Save neerolyte/1644379 to your computer and use it in GitHub Desktop.
half baked print_r in lua
function pp (o)
local typ = type(o)
if typ == "boolean" or typ == "number" then
return o
elseif typ == "string" then
return string.format( "%q", o)
elseif typ == "table" then
local t = { "{"}
for k, v in pairs ( o ) do
local nice = "[" .. pp(k) .. "]" .. " = " .. pp(v) .. ";"
table.insert( t, nice )
end
table.insert( t, "}" )
return table.concat( t, "\n")
elseif typ == "function" then
return string.dump(o)
else
error("Unknown type: " .. typ)
end
end
print(pp({"1","a"}))
--print(pp(_G))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment