Advertisement
Guest User

print_r

a guest
Oct 29th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. function print_r ( t )
  2.     local print_r_cache={}
  3.     local function sub_print_r(t,indent)
  4.         if (print_r_cache[tostring(t)]) then
  5.             print(indent.."*"..tostring(t))
  6.         else
  7.             print_r_cache[tostring(t)]=true
  8.             if (type(t)=="table") then
  9.                 for pos,val in pairs(t) do
  10.                     if (type(val)=="table") then
  11.                         print(indent.."["..pos.."] => "..tostring(t).." {")
  12.                         sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
  13.                         print(indent..string.rep(" ",string.len(pos)+6).."}")
  14.                     else
  15.                         print(indent.."["..pos.."] => "..tostring(val))
  16.                     end
  17.                 end
  18.             else
  19.                 print(indent..tostring(t))
  20.             end
  21.         end
  22.     end
  23.     sub_print_r(t,"  ")
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement