You will want to have a good understanding of
-os.pullEvent
-coroutines
-functions
-variables
-etc.
before continuing.
Step 1: Make some looping code in a function
Example:
function foo() while true do local event = { os.pullEvent( "modem_message" ) } --#do stuff with it end endNow, while this code does not seem particularly useful, it can be. You may want to "network" several devices together and listen for the specific events they send.
Step 2: Backup os.pullEventRaw() and create a coroutine
local oldPull = os.pullEventRaw --#note the lack of parentheses local coFoo = coroutine.create( foo ) --#note "foo" does not have parentheses
Step 3: Overwrite os.pullEventRaw()
function os.pullEventRaw( sFilter ) while true do local event = { oldPull() } --#note I am using the backup if coroutine.status( coFoo ) == "suspended" then --#we to make sure it is not our function (now a coroutine) calling it. coroutine.resume( coFoo, unpack( event ) ) --#unpack( tbl ) returns the contents of the table. end if sFilter == event[ 1 ] or not sFilter then --#if the event is the correct type, or there is no filter; return unpack( event ) end end end
If you wished, you could even have this iterate through different coroutines. I suspect you could also write a function to insert additional coroutines into the program, but I think it would be highly unnecessary.
Questions? Comments?