[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Threads, tables and lua_ref.
- From: Sam Roberts <sroberts@...>
- Date: Tue, 24 Apr 2007 15:44:01 -0700
On Tue, Apr 24, 2007 at 02:20:10PM -0700, Leandro Pelorosso wrote:
> Hi. I'm trying to create lots of threds and i'm having
> troubles. I was wondering if someone could help me.
> If I'm going to create lots of threads I would like to
> keep their references somewhere else other than the
> stack. Where can I store them?.
> I know i can do this: luaL_ref(L, LUA_REGISTRYINDEX )
> where L represents the new thread. But doing this i'm
Unless the new thread has itself on its stack (unlikely, unless you
called lua_xmove()), you should be using the "L" that was passed to
> using the registry table and i want to use a new table
> created by me. I'm having troubles creating a new
> table. I can't get the new table's index to use as
> luaL_ref parameter.
int table_index = lua_gettop(L);
lua_State* thread_L = lua_newthread(L);
int thread_ref = luaL_ref(L, table_index);
... store the table at table_index somewhere?
table_index = where was it stored?
thread_ref = "" ?
lua_rawgeti(L, table_index, thread_ref)
lua_State* thread_L = lua_tothread(L, -1);
But you need to put the new table somewhere where you can find it, in
the registry, as a global, leave it on the stack, something, because
you'll need to supply an index to it before calling lua_rawgeti().
Why not just use the ref mechanism with the registry? The registry
exists pretty much as a convenient scratch table for this kind of thing.
Are you anticipating some kind of problem?