[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Use of Lua corotines in games
- From: Graham Wakefield <lists@...>
- Date: Mon, 19 Mar 2007 21:53:40 -0700
From the manual:
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.
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
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
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().
On 3/20/07, Graham Wakefield <firstname.lastname@example.org> 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