DaikiKaminari

print_all_attributes

Nov 25th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local t = peripheral.getMethods("left")
  2. local mon = peripheral.find("monitor")
  3. term.redirect(mon)
  4.  
  5. function print_r(t)  
  6.     local print_r_cache={}
  7.     local function sub_print_r(t,indent)
  8.         if (print_r_cache[tostring(t)]) then
  9.             print(indent.."*"..tostring(t))
  10.         else
  11.             print_r_cache[tostring(t)]=true
  12.             if (type(t)=="table") then
  13.                 for pos,val in pairs(t) do
  14.                     if (type(val)=="table") then
  15.                         print(indent.."["..pos.."] => "..tostring(t).." {")
  16.                         sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
  17.                         print(indent..string.rep(" ",string.len(pos)+6).."}")
  18.                     elseif (type(val)=="string") then
  19.                         print(indent.."["..pos..'] => "'..val..'"')
  20.                     else
  21.                         print(indent.."["..pos.."] => "..tostring(val))
  22.                     end
  23.                 end
  24.             else
  25.                 print(indent..tostring(t))
  26.             end
  27.         end
  28.     end
  29.     if (type(t)=="table") then
  30.         print(tostring(t).." {")
  31.         sub_print_r(t,"  ")
  32.         print("}")
  33.     else
  34.         sub_print_r(t,"  ")
  35.     end
  36.     print()
  37. end
  38.  
  39. print_r(t)
Add Comment
Please, Sign In to add comment