[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Threads, tables and lua_ref.
- From: Leandro Pelorosso <vertexar@...>
- Date: Tue, 24 Apr 2007 16:01:34 -0700 (PDT)
I'm going to create a lot of threads, and then I will
resume one after another. I want to have a table with
just the threads I create in order to iterate the
elements of it to revive them. If I use the registry
table then i should use a linked list to have easy
access to all the threads, because the registry will
have also another kind of data. That's why I want a
new table :)
Thanks a lot for your reply Sam!, i will try that
later when I get home. :-D
ps. sorry about my crappy english. :/
--- Sam Roberts <firstname.lastname@example.org> wrote:
> 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
> > troubles. I was wondering if someone could help
> > If I'm going to create lots of threads I would
> like to
> > keep their references somewhere else other than
> > 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
> 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
> > 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
> 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?
Sign our Guestbook!
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around