[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: About lua_newthread
- From: Julien Hamaide <julien.hamaide@...>
- Date: Wed, 07 Jun 2006 18:09:40 +0200
Tom Miles a écrit :
Sorry about the the thread necromancy, but I have just encountered
this situation in the project I am currently working on. I am running
several threads from my main thread, all of which are just loaded with
functions to call in an event based system. At various intervals I
want to "unload" these functions and load a new set, so I want to shut
down the thread. I therefore need to remove references to my thread
from the stack as per the suggestion, however, when I iterate through
the stack all that is on there is a userdata of indeterminate origin,
not a thread. (Having said that, I've just discovered that if I do
lua_touserdata() and compare it to the address of the state returned
with lua_newthread(), then they are the same, so I have found my
thread - but there seems to be a little bug there as it isn't of type
Can you show us how you initialize your thread??
On a similar note, is there a way of removing a non integer index from
a table? I use the thread as a key in a table to match it up to a
game object, and when that object is destroyed I want to remove the
entry in the table as well.
If you use a weak value table, the entry will be deleted when the object
Just put "v" in field __mode of the metatable of your table. If you want
weak key, just put "k".
10Tacle Studios Belgium
Thanks for any help.
[mailto:firstname.lastname@example.org]*On Behalf Of* Raymond Jacobs
*Sent:* 18 May 2006 16:20
*To:* Lua list
*Subject:* Re: About lua_newthread
When you are done with a thread (when lua_resume returns and it's
not a yield), you should remove the thread directly from the
stack, this will remove the reference to it and it can then be
garbage collected (its a pain I know =/).
another method which I've not yet done but should work, is to
create a new thread, create a lua reference to it (using lua_ref)
then pop it off the stack immediately (so it doesn't get buried),
and later when you are done with it, destroy the reference
(lua_unref) and that should allow it to be GC'd
hope that helps,
Ethereal Darkness Interactive
On 5/18/06, *mos* <email@example.com <mailto:firstname.lastname@example.org>>
in lua5.1 manual:
lua_State *lua_newthread (lua_State *L);
There is no explicit function to close or to destroy a thread.
subject to garbage collection, like any Lua object
I don't understand this , for example like Npc in a game
I bind each npc with a lua_State by lua_newthread
but the npc will die and i should close the lua_State ,
but I can
what can I do ? or some better suggestion ?