Posted 20 May 2012 - 06:05 PM
Why dosn't this code print "Event: <event>" when a event occurs?
Basicly what i'm trying to do is making a networking library that runs in the background and sends a event once there is data to read.
So far it works just great, but i can't seem to get it to run in the background.
The coroutine seems to yield permanently once os.pullEvent() or sleep() is called within the coroutine.
Basicly what i'm trying to do is making a networking library that runs in the background and sends a event once there is data to read.
So far it works just great, but i can't seem to get it to run in the background.
The coroutine seems to yield permanently once os.pullEvent() or sleep() is called within the coroutine.
--#!lua
local function coroutineloop()
local doloop = true
while doloop do
e, v1, v2, v3 = os.pullEvent()
print("Event: " .. e)
if e == "key" and v1 == 15 then doloop = false end -- Stop loop if tab key is pressed
end
end
--coroutineloop() -- This works just as expected
local cr = coroutine.create(coroutineloop)
coroutine.resume(cr)
print(cr)
while true do
--e, v1 = os.pullEvent()
--if e == "key" and v1 == 43 then coroutine.resume(cr) end -- Resume coroutine if pipe is pressed
sleep(10)
print(coroutine.status(cr))
end