Advertisement
Sanwi

OpenComputers: getComps

Jan 30th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. -- Lists all components attached to the computer, followed by their OpenPeripherals API. Press any key to cycle to the next component.
  2.  
  3. local component = require("component")
  4. local event = require("event")
  5.  
  6. local function findComps(type)
  7. local comps = {}
  8. local compNames = {}
  9.  
  10. for cAddress,cType in component.list(type) do
  11. -- Insert proxy methods table into comps table
  12. table.insert(comps, component.proxy(cAddress))
  13. -- Insert component type into compNames table
  14. table.insert(compNames, cType)
  15. end
  16. return comps, compNames
  17. end
  18.  
  19. local comps, compNames = findComps()
  20. for i=1, #comps do -- Iterate components
  21. print("\n"..compNames[i]..":")
  22. for k,v in pairs(comps[i]) do -- Iterate methods
  23. print(k) -- Print method name
  24. end
  25. print(" ")
  26. os.sleep(0.2)
  27. print("Press any key to continue")
  28. local _,_ = event.pull("key")
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement