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.

45 lines
1.1 KiB

network = require("network")
event = {}
addr_num = 0
last_msg = nil
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, addr1, addr2, port, dist, msg)
last_msg = {
ev=ev,
addr1=addr1,
addr2=addr2,
port=port,
dist=dist,
msg=msg,
}
callback(ev, addr1, addr2, port, dist, msg)
end
network.register(addr, ev_callback)
end
function event.ignore(event, callback)
if event ~= "modem_message" then
error("Event '"..event"' is not supported!")
end
error("Not implemented yet")
end
function event.pull(event, callback)
-- Just return the last message and hope it is the
-- right one ...
if last_msg == nil then
error("No previous message found")
end
return last_msg.ev, last_msg.addr1, last_msg.addr2, last_msg.port, last_msg.dist, last_msg.msg
end
return event