lua-users home
lua-l archive

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


The way that I'm terminating the thread is by preempting them out, and then removing the reference to them from the global lua table.

I am in charge of multitasking all my coroutines, and i have a class that encapsulates the coroutine, so i keep a variable with the "state" of the thread at any given time, NOT_LOADED, STARTING, RUNNING, SLEEPING, DEAD, KILLED.

So if it's DEAD (because it's finished running), i just clean it up. But I can force the clean up by setting it to KILLED, then removing the references to it from the main globals.

Hope this helps, and hope that I'm not doing anything stupid.

David Andersen wrote:

I was reading through the mailing list and I saw that you can forcibly stop a thread by removing all trace of it from the stack. I'm pretty new to lua, so I'm wondering if anyone can point me in the right direction. I am looking for the correct C API commands to use to pop from the stack. I'm afraid of introducing a memory leak.

Maybe its really easy and I just need to call :

threadState = lua_newthread(L);
<do stuff>
lua_pop(threadState, lua_gettop(threadState));

I am using the technique found in this posting to run AI scripts for a game, so I have lots of threads, and they need to be terminated immediately when the object they are attached to dies.

http://www.icynorth.com/forums/viewtopic.php?p=228&sid=4b08243f0dd2ebe6b8b416fe0bc4eeb4#228



--
// David Morris-Oliveros
// Camera & Lua Coder
// Team Bondi


------------------------------------------------------------------------
Contact:
Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Australia
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
Web: http://www.teambondi.com
------------------------------------------------------------------------
This email may contain confidential information.  If you are not
the intended recipient, you may not copy or deliver this message to
anyone. In such case, you should destroy this message and kindly
notify the sender by reply email. Opinions, conclusions and other
information in this message that do not relate to the official business
of our firm shall be understood as neither given nor endorsed by it.
------------------------------------------------------------------------