Posted 31 December 2015 - 08:49 PM
I'm trying to make a processManager of sorts and when I override os.pullEventRaw() the computer just shuts off immediately which gives me no time to see of any kind of error etc and then when i right click on the computer again it just boots back into craftOS. Any help appreciated.
--processManager.lua
pullEventRaw_Backup = os.pullEventRaw
local function _init_()
if not _PM_RUN_STATUS then
print('loading api')
_PM_RUN_STATUS=1
--define coroutines
co_func = coroutine.create(func)
return
end
end
local function func()
print('func is running')
local received = {}
for i=1,#interface.tInterfaceWrap do
local event = {os.pullEventRaw()}
if event and event[2] == "modem_message" and event[6] then
table.insert(received,event[6])
end
end
return received
end
function _G.os.pullEventRaw(sFilter)
print('os.pullEventRaw is called')
while true do
local event = {pullEventRaw_Backup()}
print('event pulled')
if coroutine.status(co_func) == "suspended" then
print('resuming coroutine')
coroutine.resume(co_func, table.unpack(event))
end
if sFilter == event[1] or not sFilter then
return table.unpack(event)
end
end
end
_init_()
CORRECT ANSWER HERE
--processManager.lua
function _init_()
if not _PM_RUN_STATUS then
_PM_RUN_STATUS=1
return
end
end
function func()
while true do
local received
for i=1,#interface.tInterfaceWrap do
local event = {os.pullEventRaw()}
if event and event[2] == "modem_message" and event[4] == interface.channel and interface.tInterfaceState[event[3]] == 'up' and event[6] then
table.insert(received,event[6])
end
end
coroutine.yield(received)
end
end
local pullEventRaw_Backup = os.pullEventRaw
local co_func = coroutine.create(func)
function os.pullEventRaw(sFilter)
while true do
local event = {pullEventRaw_Backup()}
if coroutine.status(co_func) == "suspended" then
coroutine.resume(co_func, table.unpack(event))
end
--Return any events
if sFilter == event[1] or not sFilter then
return table.unpack(event)
end
end
end
_init_()
Edited on 07 March 2016 - 01:28 AM