Advertisement
Argiope42

debug

Oct 15th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. function dumpvar(data)
  2.     -- cache of tables already printed, to avoid infinite recursive loops
  3.     local tablecache = {}
  4.     local buffer = ""
  5.     local padder = "    "
  6.  
  7.     local function _dumpvar(d, depth)
  8.         local t = type(d)
  9.         local str = tostring(d)
  10.         if (t == "table") then
  11.             if (tablecache[str]) then
  12.                 -- table already dumped before, so we dont
  13.                 -- dump it again, just mention it
  14.                 buffer = buffer.."<"..str..">\n"
  15.             else
  16.                 tablecache[str] = (tablecache[str] or 0) + 1
  17.                 buffer = buffer.."("..str..") {\n"
  18.                 for k, v in pairs(d) do
  19.                     buffer = buffer..string.rep(padder, depth+1).."["..k.."] => "
  20.                     _dumpvar(v, depth+1)
  21.                 end
  22.                 buffer = buffer..string.rep(padder, depth).."}\n"
  23.             end
  24.         elseif (t == "number") then
  25.             buffer = buffer.."("..t..") "..str.."\n"
  26.         else
  27.             buffer = buffer.."("..t..") \""..str.."\"\n"
  28.         end
  29.     end
  30.     _dumpvar(data, 0)
  31.     return buffer
  32. end
  33.  
  34. local success, data = turtle.inspect();
  35.  
  36. if success then
  37.     print(dumpvar(data));
  38. end
  39.  
  40. local data2 = turtle.getItemDetail();
  41. print(dumpvar(data2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement