awsumben13, on 01 February 2013 - 05:27 AM, said:
so can you tell me how to get coroutines to work?
I don't even know what coroutine.yield does :l
Try looking through the parallel API, and look in bios.lua to see what os.pullEvent does. I'm not sure what you mean "get[ting] coroutines to work". They work fine, you're just using them incorrectly. Your coroutine manager needs to be yielding to retrieve events, then passing those events to your coroutines as it resumes them (like parallel does). In its simplest form:
--we first need a table of coroutines in coroutineTable.
while #coroutineTable > 0 do
--get the next event.
local event = {coroutine.yield()} --this is what os.pullEvent eventually calls, so we will just use it directly for clarity.
for i = 1, #coroutineTable do
--for every coroutine we have, resume it and give it the current event.
coroutine.resume(coroutineTable[i], unpack(event))
end
--now we remove dead coroutines.
for i = #coroutineTable, 1, -1 do
if coroutine.status(coroutineTable[i]) == "dead" then
table.remove(coroutineTable, i)
end
end
end