You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
931 B

local network = require("network")
local component = require("component")
local event = {}
local addr_num = 0
function event.listen(event, callback)
if event ~= "modem_message" then
error("Event '"..event"' is not supported!")
end
addr = "A"..addr_num
addr_num = addr_num + 1
function ev_callback(ev, local_addr, ...)
-- Inject local address so the check passes
component.modem.address = local_addr
callback(ev, local_addr, ...)
end
network.register(addr, ev_callback)
end
function event.ignore(event, callback)
if event ~= "modem_message" then
error("Event '"..event"' is not supported!")
end
network.deregister(network.get_scene())
end
function event.pullFiltered(timeout, filter)
while true do
local msg = table.pack(network.pull())
if msg == nil then
return nil
elseif filter(table.unpack(msg)) then
return table.unpack(msg)
end
end
end
return event