This commit is contained in:
2026-04-06 13:57:46 -07:00
commit 03c441edfb
11 changed files with 857 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
local backend = {}
local network = require("entrypointlib")
local loop = coroutine.create(network.loop)
local filter = nil
-- some black magic bs that i pulled from https://gist.github.com/MCJack123/473475f07b980d57dd2bd818026c97e8
local env = getfenv(rednet.run)
env.os = setmetatable({
pullEventRaw = function ()
local ev = table.pack(coroutine.yield())
if filter == nil or filter == ev[1] then
_,filter = coroutine.resume(loop,table.unpack(ev, 1, ev.n))
end
return table.unpack(ev, 1, ev.n)
end
},{__index=env.os})
local target = nil
function backend.setTarget(id)
target = id
end
function backend.sendMessage(msg, id)
if not (id or target) then error("failed to imply or specify target id",2) end
network.send(msg,id or target)
end
function backend.receiveMessage()
local _,msg,id,hops
repeat
_,msg,id,hops = os.pullEvent("network_packet")
until id == (target or id)
return msg,id
end
return backend