Advertisement
Guest User

devices

a guest
Jan 14th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. component = require("component")
  2. event = require("event")
  3. serialization = require("serialization")
  4.  
  5. local config = {}
  6.  
  7. function addDeviceEvent(device, eventName)
  8.   if config[device] == nil then
  9.     config[device] = {}
  10.     config[device].events = {}
  11.   end
  12.  
  13.   if config[device].events == nil then
  14.     table.insert(config[device].events, eventName)
  15.   end
  16. end
  17.  
  18. function eventHandler(event, device, ...)
  19.     local args = {...}
  20.  
  21.     print("new event: " .. event .. " from device: " .. device)
  22.    
  23.     addDeviceEvent(device, event)
  24.  
  25.     for i=1,#args do
  26.       if args[i] ~= nil then
  27.         io.write(" (" .. args[i] .. " ) ")
  28.       end
  29.     end
  30.     print("")    
  31. end
  32.  
  33. local stopme = false
  34.  
  35. while not stopme do
  36.   local args = { event.pull(math.huge) }
  37.   if args[1] == "interrupted"
  38.     then stopme = true
  39.     else eventHandler(table.unpack(args))  
  40.   end
  41. end
  42.  
  43.  
  44. for i=1,#config do
  45.   print(config[i])
  46.   for j=1,#config[i].events do
  47.     print(config[i].events[j])
  48.   end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement