[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A Question of Style
- From: Brian Maher <brian@...>
- Date: Wed, 7 Dec 2011 19:12:04 -0800
The specific case where yield doesn't work is if yield needs to "save"
the C stack frame (lua function calls C function which calls lua
function that calls yields). The lua_yield function (as mentioned in
the documentation) must be the last statement of your C function since
it won't preserve the C stack. There is more about this limitation
here (including how to overcome it):
http://coco.luajit.org/
Cheers,
-Brian
On Wed, Dec 7, 2011 at 9:07 AM, Enrico Colombini <erix@erix.it> wrote:
> On 07/12/2011 17.52, Sam Roberts wrote:
>>
>> You can't yield across a C call boundary. Not without luajit or coco.
>
>
> This is allowed (and works):
>
> -------------------------------------
> static int
> LuaWaitImageReady(lua_State *lua)
> {
> int tid = luaL_checkint(lua, 1);
> bool waitFinished = (lua_toboolean(lua, 2) != 0);
>
> if (Gale->WaitImageReady(tid, waitFinished))
> {
> //ready: return normally
> return 0;
> }
> else
> {
> //not ready: suspend coroutine --- yield from C side ---
> return lua_yield(lua, 0);
> }
> } //LuaWaitImageReady
> -------------------------------------
>
> The above function is called from a Lua coroutine.
>
> --
> Enrico
>
--
Brian Maher >> Glory to God <<