Savage_Me55iah

Peripherals identifier

May 4th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 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. function source(command)
  14.   return peripheral.call(location, command)
  15. end
  16.  
  17. local type = source("getType")
  18. if not (local methods = source("getMethods")) then
  19.   error("Command <getmethods> failed", 1)
  20. end
  21.  
  22. if not fs.isDir(directory) then
  23.   fs.makeDir(directory)
  24. end
  25.  
  26. if not fs.exsists(directory, "/", type) then
  27.   output = io.open(directory .. "/" .. type, 'w')
  28.   output:write("Savage_Me55iah's Peripheral aid for")
  29.   output:write("\n")
  30.   output:write("Peripheral Type: " .. type)
  31.   output:write("\n")
  32.   output:write("\n")
  33.   output:write("List of methods: ")
  34.   for k,v in pairs(methods) do
  35.     output:write("\n")
  36.     output:write(k .. ": " .. v)
  37.   end
  38.   output:close()
  39. else
  40.   error("List already exsists, to view type: edit " .. directory .. "/" .. type, 0)
  41. end
  42.  
  43. print("To view list anytime type: edit " .. directory .. "/" .. type)
  44. print("Thank you for using Savage_Me55iah's Peripheral Aid")
Advertisement
Add Comment
Please, Sign In to add comment