[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Unsubscribe
- From: "michael.gogins@..." <michael.gogins@...>
- Date: Thu, 08 Dec 2011 06:25:51 -0500
T-Mobile. America’s First Nationwide 4G Network
----- Reply message -----
From: "Brian Maher" <brian@brimworks.com>
To: "Lua mailing list" <lua-l@lists.lua.org>
Subject: A Question of Style
Date: Wed, Dec 7, 2011 10:12 pm
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 <<