Coroutine tutorial made by BB.It's all just coroutine.yield
code for os.pullEvent:
function os.pullEvent( sFilter )
local eventData = { os.pullEventRaw( sFilter ) }
if eventData[1] == "terminate" then
error( "Terminated", 0 )
end
return table.unpack( eventData )
end
Code for os.pullEventRaw:
function os.pullEventRaw( sFilter )
return coroutine.yield( sFilter )
end
So os.pullEvent is really just coroutine.yield with extra fluff to allow for termination.
Sleep and rednet.receive:
function receive( sProtocolFilter, nTimeout )
--#snip. There was more stuff here to deal with starting the timer for your timeout and stuff, but right now it's fine.
while true do
local sEvent, p1, p2, p3 = os.pullEvent( sFilter )
if sEvent == "rednet_message" then
-- Return the first matching rednet_message
local nSenderID, message, sProtocol = p1, p2, p3
if sProtocolFilter == nil or sProtocol == sProtocolFilter then
return nSenderID, message, sProtocol
end
elseif sEvent == "timer" then
-- Return nil if we timeout
if p1 == timer then
return nil
end
end
end
end
Sleep:
function sleep( nTime )
local timer = os.startTimer( nTime or 0 )
repeat
local sEvent, param = os.pullEvent( "timer" )
until param == timer
end
Oh hey, os.pullEvent again in both, they're just pre built functions that utilize os.pullEvent for tasks you're probably going to want to do anyways.