Youen Toupin <youen.tou...@wanadoo.fr> wrote:
(19/05/2009 19:22)

>lostgallifreyan a écrit :
>> When I was looking at it I was wondering where and how I'd pass a returned 
>> value if I had to, which sort of fits with what you just said. I've never 
>> used a co-routine yet, but if I do, is it right to consider it purely as a 
>> sub-routine that happens to use a separate thread, and not to concern myself 
>> with the underlying methods that make it so?
>>   
>A coroutine is not a thread, it will not run in parallel of anything 
>else. It is similar to a thread because when you call coroutine.yield(), 
>it will resume the execution of the main thread, the coroutine is 
>paused, its callstack is preserved. Then you can call coroutine.resume( 
>yourCoroutine ) to resume the execution of the coroutine just after the 
>call to coroutine.yield. For example, if you call coroutine.yield() very 
>often, and resume the coroutine from a main loop, this will give a 
>parallel-like execution of the main loop and the coroutine.
>

I only recently adapted to the message loop. :) I'm not yet sure how I can use 
co-routines, though I think they're native to Lua, so would it be useful to 
make something that behaves like a message loop in Lua? Before I start 
exploring them, I really need to know what might make them indispensible, 
either impossible by other ways, or at least not done as well otherwise. I'm 
also unsure how it shows parallel-like behaviour if it does not run parallel to 
anything else, except in the sense of multiplexing, which is what 
multi-threading is also.

>I'm not sure to understand your question about the return value, but if 
>you want to pass a return value from a coroutine to the main thread, you 
>can. It is the last coroutine.resume called by the main thread that will 
>get the result. You can not get the result at the location where you 
>initially started the coroutine however.
>

Understood. I think. So not at all like a subroutine or called function that 
passes back values. I guess one way is a global that gets examined periodically 
by other code for any value a co-routine puts in it might be a useful trick.


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to