Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require("event")
- local modem = require("component").modem
- local class = {}
- local CODE_NANOMACHINES = "nanomachines"
- local PORT = 1
- function class.send(...)
- modem.broadcast(1, CODE_NANOMACHINES, ...)
- end
- function class.init(port)
- modem.close(PORT)
- PORT = port
- modem.open(PORT)
- class.send("setResponsePort", PORT)
- end
- function class.listen(callback)
- if (not modem.isOpen(PORT)) then
- modem.open(PORT)
- end
- event.listen("modem_message", function(_, _, _, _, _, header, ...)
- if (header == CODE_NANOMACHINES) then
- callback(...)
- end
- end)
- end
- function class.getPort()
- return PORT
- end
- return class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement