Created
December 15, 2012 05:22
-
-
Save jasonbradley/4291505 to your computer and use it in GitHub Desktop.
PHP print_r for Lua
This file contains 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
Util.print_r = function(t, indent, done) | |
done = done or {} | |
indent = indent or '' | |
local nextIndent -- Storage for next indentation value | |
for key, value in pairs (t) do | |
if type (value) == "table" and not done [value] then | |
nextIndent = nextIndent or | |
(indent .. string.rep(' ',string.len(tostring (key))+2)) | |
-- Shortcut conditional allocation | |
done [value] = true | |
print (indent .. "[" .. tostring (key) .. "] => Table {"); | |
print (nextIndent .. "{"); | |
print_r (value, nextIndent .. string.rep(' ',2), done) | |
print (nextIndent .. "}"); | |
else | |
print (indent .. "[" .. tostring (key) .. "] => " .. tostring (value).."") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment