lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


A concise summary of the limitations (and the solution) can be found
at

http://luajit.luaforge.net/coco.html

On 3/20/07, Graham Wakefield <lists@grahamwakefield.net> wrote:
 From the manual:

"coroutine.yield (···)

Suspends the execution of the calling coroutine. The coroutine cannot
be running a C function, a metamethod, or an iterator. Any arguments
to yield are passed as extra results to resume."

The bit I don't understand is how a coroutine in Lua can call yield()
while it is running a C function?  A code example would help here.

The manual entry for lua_resume() doesn't mention anything about
yielding across C calls.

"lua_yield
int lua_yield  (lua_State *L, int nresults);
Yields a coroutine.

This function should only be called as the return expression of a C
function, as follows:

      return lua_yield (L, nresults);
When a C function calls lua_yield in that way, the running coroutine
suspends its execution, and the call to lua_resume that started this
coroutine returns. The parameter nresults is the number of values
from the stack that are passed as results to lua_resume."

What's not clear here is whether the 'running coroutine' is one
created in Lua, that called a C function ending in lua_yield, or
whether the running coroutine was a thread created in C via
lua_newthread, or whether either case is valid.

Perhaps 'not yielding across C calls' simply means that lua_yield
should not be called inside a C function, but only at the end as a
return value?


On Mar 19, 2007, at 5:36 PM, David Burgess wrote:

> lua_resume()->lua code->resume()->C function->pcall()->yield()
>
> I think I have this right. So when the coroutine starts running it
> might
> call a C function which might pcall some Lua code that yields. THis
> means that the yield() needs to cross a C/Lua boundary.
> The same problem occurs when starting with lua_resume() and then
> executing Lua pcall() which in turn may call lua_yield().
>
> db
>
> On 3/20/07, Graham Wakefield <lists@grahamwakefield.net> wrote:
>> I keep hearing this phrase, but what exactly does it mean? Thanks!
>>
>> On Mar 19, 2007, at 6:46 AM, Eike Decker wrote:
>>
>> > Only problem is, that lua coroutines can't yield across C calls
>>
>>