Advertisement
Guest User

Untitled

a guest
Aug 26th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local function print_r (t, name, indent)
  2.   local tableList = {}
  3.   local function table_r (t, name, indent, full)
  4.     local id = not full and name
  5.         or type(name)~="number" and tostring(name) or '['..name..']'
  6.     local tag = indent .. id .. ' = '
  7.     local out = {}      -- result
  8.     if type(t) == "table" then
  9.       if tableList[t] ~= nil then table.insert(out, tag .. '{} -- ' .. tableList[t] .. ' (self reference)')
  10.       else
  11.         tableList[t]= full and (full .. '.' .. id) or id
  12.         if next(t) then -- Table not empty
  13.           table.insert(out, tag .. '{')
  14.           for key,value in pairs(t) do
  15.             table.insert(out,table_r(value,key,indent .. '|  ',tableList[t]))
  16.           end
  17.           table.insert(out,indent .. '},')
  18.         else table.insert(out,tag .. '{}') end
  19.       end
  20.     else
  21.       local val = type(t)~="number" and type(t)~="boolean" and '"'..tostring(t)..'"' or tostring(t)
  22.       table.insert(out, tag .. val .. ',')
  23.     end
  24.     return table.concat(out, '\n')
  25.   end
  26.   return table_r(t,name or 'Value',indent or '')
  27. end
  28.  
  29. function pr (t, name)
  30.   print('[' .. type(t) .. '] ' .. print_r(t,name))
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement