Skip to content

Instantly share code, notes, and snippets.

@vk496
Created January 3, 2016 18:40
Show Gist options
  • Save vk496/20c7244ec1c59f0d57a3 to your computer and use it in GitHub Desktop.
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/)
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