lua-users home
lua-l archive

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



Sorry if I misunderstand, but isn't this all you want?

lua_getfield(MainState, LUA_GLOBALSINDEX, "ThreadTable");
lua_pushnil(MainState);
lua_rawseti(MainState, -2, refID);
lua_pop(MainState, 1); /* ThreadTable */

I asked the question poorly, the code to release the coroutine isn't the problem.
The placement of that code is, i have multiple entry point back to my co routines from different systems that utilize yeild/resume to implement functionality.
Do you need to check the state of the thread after ever lua_resume call? and then do code like you suggest?
Or is there a way to do it more generically then that, I'm leaning towards the latter.

Sorry for the confusing question, and thank you for the replies.

On Tue, Oct 6, 2009 at 6:08 PM, Patrick Donnelly <batrick@batbytes.com> wrote:
On Tue, Oct 6, 2009 at 9:48 PM, Chris Gagnon <cgagnon@zindagigames.com> wrote:
> Apologizes for the partial email, what a way to introduce myself ;o)
>
> Lets assume we have a MainState, and a "ThreadTable" in the global table
>
> lua_getfield(MainState, LUA_GLOBALSINDEX, "ThreadTable");
> lua_State *thread = lua_newthread(MainState);
> int refID = luaL_ref(MainState, -2);
> lua_pop(MainState,1);
[...]
> The problem i'm running into is how do I remove my reference/anchor, when
> the coroutine is simply done.

Sorry if I misunderstand, but isn't this all you want?

lua_getfield(MainState, LUA_GLOBALSINDEX, "ThreadTable");
lua_pushnil(MainState);
lua_rawseti(MainState, -2, refID);
lua_pop(MainState, 1); /* ThreadTable */

--
-Patrick Donnelly

"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."

- Benjamin Franklin