Created
January 3, 2016 18:40
-
-
Save vk496/20c7244ec1c59f0d57a3 to your computer and use it in GitHub Desktop.
list all methods and values from object in LUA (https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/)
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
function print_r ( t ) | |
local print_r_cache={} | |
local function sub_print_r(t,indent) | |
if (print_r_cache[tostring(t)]) then | |
print(indent.."*"..tostring(t)) | |
else | |
print_r_cache[tostring(t)]=true | |
if (type(t)=="table") then | |
for pos,val in pairs(t) do | |
if (type(val)=="table") then | |
print(indent.."["..pos.."] => "..tostring(t).." {") | |
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8)) | |
print(indent..string.rep(" ",string.len(pos)+6).."}") | |
elseif (type(val)=="string") then | |
print(indent.."["..pos..'] => "'..val..'"') | |
else | |
print(indent.."["..pos.."] => "..tostring(val)) | |
end | |
end | |
else | |
print(indent..tostring(t)) | |
end | |
end | |
end | |
if (type(t)=="table") then | |
print(tostring(t).." {") | |
sub_print_r(t," ") | |
print("}") | |
else | |
sub_print_r(t," ") | |
end | |
print() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment