Advertisement
Guest User

Untitled

a guest
Oct 27th, 2011
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. -- A function in Lua similar to PHP's print_r, from http://luanet.net/lua/function/print_r
  2.  
  3. function print_r ( t )
  4. local print_r_cache={}
  5. local function sub_print_r(t,indent)
  6. if (print_r_cache[tostring(t)]) then
  7. print(indent.."*"..tostring(t))
  8. else
  9. print_r_cache[tostring(t)]=true
  10. if (type(t)=="table") then
  11. for pos,val in pairs(t) do
  12. if (type(val)=="table") then
  13. print(indent.."["..pos.."] => "..tostring(t).." {")
  14. sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
  15. print(indent..string.rep(" ",string.len(pos)+6).."}")
  16. else
  17. print(indent.."["..pos.."] => "..tostring(val))
  18. end
  19. end
  20. else
  21. print(indent..tostring(t))
  22. end
  23. end
  24. end
  25. sub_print_r(t," ")
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement