Created
January 20, 2012 01:27
-
-
Save neerolyte/1644379 to your computer and use it in GitHub Desktop.
half baked print_r in lua
This file contains hidden or 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 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