This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
GreenGene's profile picture

coroutine

Started by GreenGene, 13 December 2014 - 11:00 PM
GreenGene #1
Posted 14 December 2014 - 12:00 AM
Can anyone please explain what the API
coroutine is thanks!
Lemmmy #2
Posted 14 December 2014 - 12:04 AM
This link will help you in your travels
Bomb Bloke #3
Posted 14 December 2014 - 12:37 AM
http://www.computercraft.info/wiki/Coroutine_%28API%29
wieselkatze #4
Posted 14 December 2014 - 12:38 AM
As your question isn't really clear, I would give this a look.
AgentE382 #5
Posted 14 December 2014 - 03:42 AM
You can also check out the Coroutines chapter of Programming in Lua: http://www.lua.org/pil/9.1.html It explains coroutines pretty well. There's also an explanation section in the Lua Reference Manual: http://www.lua.org/manual/5.1/manual.html#2.11

EDIT: You might also want to check out the Coroutines Tutorial: http://lua-users.org/wiki/CoroutinesTutorial

The Computercraft Wiki link Bomb Bloke gave is equivalent to this section in the Reference Manual: http://www.lua.org/manual/5.1/manual.html#5.2

Note that the ComputerCraft function os.pullEventRaw is actually coroutine.yield. The ComputerCraft function os.pullEvent is a wrapper function for coroutine.yield that checks for terminate events, instead of letting you handle them yourself.

EDIT: If you're willing to read an academic paper on the subject, you can read the Coroutines in Lua paper here: http://www.inf.puc-rio.br/~roberto/docs/corosblp.pdf
Edited on 14 December 2014 - 05:32 AM
GreenGene #6
Posted 14 December 2014 - 04:04 PM
You can also check out the Coroutines chapter of Programming in Lua: http://www.lua.org/pil/9.1.html It explains coroutines pretty well. There's also an explanation section in the Lua Reference Manual: http://www.lua.org/m...anual.html#2.11

EDIT: You might also want to check out the Coroutines Tutorial: http://lua-users.org...outinesTutorial

The Computercraft Wiki link Bomb Bloke gave is equivalent to this section in the Reference Manual: http://www.lua.org/m...manual.html#5.2

Note that the ComputerCraft function os.pullEventRaw is actually coroutine.yield. The ComputerCraft function os.pullEvent is a wrapper function for coroutine.yield that checks for terminate events, instead of letting you handle them yourself.

EDIT: If you're willing to read an academic paper on the subject, you can read the Coroutines in Lua paper here: http://www.inf.puc-r...cs/corosblp.pdf

Thanks!