lua-users home
lua-l archive

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

Tom Miles wrote:
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 thread?).
It strikes me the crux of this problem isn't that there's not a function to delete a thread, but simply that you're using the stack as a persistent store for thread objects. Take them off the stack, stash them some where more sensible - a member of the table representing the actor the thread represents, or a schedule table, or other similar options.
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.
As others have said - weak tables.