Savage_Me55iah

Peripherals identifier

Jun 26th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. local tArgs = {...}
  2. local location = tostring(tArgs[1]) or nil
  3. local directory = "Peripherals"
  4.  
  5. local sides = {["front"] = true, ["back"] = true, ["left"] = true, ["right"] = true, ["top"] = true, ["bottom"] = true}
  6.  
  7. if location == nil or not sides[location] then
  8.   error("Use: " .. shell.getRunningProgram() .. " <Valid side", 0)
  9. elseif not peripheral.isPresent(location) then
  10.   error("Pheripheral isn't found, check side", 0)
  11. end
  12.  
  13. local function source(command)
  14.   return peripheral.call(location, command)
  15. end
  16.  
  17. local function istable(elem)
  18.   if (type(elem) == "table") then
  19.     return true
  20.   end
  21. end
  22.  
  23. local type_p = peripheral.getType(location)
  24. local methods = peripheral.getMethods(location) or nil
  25. for k,v in pairs(methods) do
  26.   if tostring(v) == "getAdvancedMethodsData" then
  27.     methods_op = source("getAdvancedMethodsData")
  28.   end
  29. end
  30. if methods == nil then
  31.   print("Command <getmethods> failed")
  32. elseif methods_op == nil then
  33.   print("Failed to obtain methods_op")
  34. end
  35.  
  36. --if not fs.isDir(directory) then
  37. --  fs.makeDir(directory)
  38. --end
  39.  
  40. if fs.exists(type_p) then
  41.   fs.delete(type_p)
  42. end
  43.  
  44.   local output = io.open(type_p, 'w')
  45.   output:write("Savage_Me55iah's Peripheral aid for")
  46.   output:write("\n")
  47.   output:write("Peripheral Type: " .. type_p)
  48.   output:write("\n")
  49.   output:write("\n")
  50.   output:write("List of methods: ")
  51.   if methods ~= nil then
  52.     for k,v in pairs(methods) do
  53.       output:write("\n")
  54.       output:write(k .. ": " .. v)
  55.     end
  56.   end
  57.   if methods_op ~= nil then
  58.     output:write("\n")
  59.     output:write("\n")
  60.     output:write("Open Peripherals getAdvanceMethodsData >This was a pain to figure out!<")
  61.     output:write("\n")
  62.     for a,b in pairs(methods_op) do
  63.       output:write("\n")
  64.       if istable(b) then
  65.         output:write(a .. "-")
  66.              
  67.         for c,d in pairs(b) do
  68.           output:write("\n")
  69.           if istable(d) then
  70.          
  71.             output:write(c .. "-")
  72.             for e,f in pairs(d) do
  73.               output:write("\n")
  74.               if istable(d) then
  75.              
  76.                 output:write(e .. "-")
  77.                 for g,h in pairs(d) do
  78.                   output:write("\n")
  79.                   if istable(h) then
  80.                  
  81.                     output:write(g .. "-")
  82.                     for i,j in pairs(h) do
  83.                       output:write("\n")
  84.                       i, j = tostring(i), tostring(j)
  85.                       output:write(i .. ": " .. j)
  86.                     end
  87.                   else
  88.                     output:write(g .. ": " .. h)
  89.                   end
  90.                 end
  91.               else
  92.                 output:write(e .. ": " .. f)
  93.               end
  94.             end
  95.           else
  96.             output:write(c .. ": " .. d)
  97.           end
  98.         end
  99.       else      
  100.         output:write(a .. ": " .. b)
  101.       end
  102.       output:write("\n")
  103.       output:write("\n")
  104.       output:write("-------------")
  105.       output:write("\n")
  106.     end
  107.   end
  108.   output:close()
  109. --else
  110. --  error("List already exists, to view type: edit " .. directory .. "/" .. type_p, 0)
  111. --end
  112.  
  113. print("To view list anytime type: edit " .. type_p)
  114. print("Thank you for using Savage_Me55iah's Peripheral Aid")
  115. --print("Hit <y> to view any other key to exit")
  116. --e, char = os.pullEvent()
  117. --if char == "char y" then
  118. --shell.run("edit " .. type_p)
  119. --end
Advertisement
Add Comment
Please, Sign In to add comment