Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. local comp = require("component")
  2. local thread = require("thread")
  3.  
  4. local modem = comp.modem
  5. local port = 1
  6.  
  7. local PING = "ping"
  8. local devices = {}
  9.  
  10. local commands = {
  11.   collect = function()
  12.    
  13.     local collect_thread = thread.create(function()
  14.       print("Collecting devices...")
  15.       modem.broadcast(port, PING)
  16.       while true do
  17.         local _, _, remoteAddress, _, _, payload = event.pull("modem_message")
  18.         table.insert(devices, remoteAddress)
  19.       end
  20.     end)
  21.  
  22.     os.sleep(5)
  23.     collect_thread:kill()
  24.   end
  25. }
  26.  
  27. while true do
  28.   local input = io.read()
  29.  
  30.   if input == "quit" or input == "q" then os.exit(0) end
  31.  
  32.   if commands[input] == nil then
  33.     print("Command not found!")
  34.   else
  35.     pcall(commands[input])
  36.     print()
  37.   end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement