lua-users home
lua-l archive

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


I 'belive' that will work =)

On 5/19/06, mos <mmosquito@163.com> wrote:


>
> 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
>

Hi!
       I dont know how to do and I just try like this:

       lua_State* m_L = lua_newthread(L);
       int refKey = luaL_ref(L, LUA_REGISTRYINDEX);

       NPC->L = L
       NPC->m_L = m_L
       NPC->refKey = refKey

       and
       NPC::~NPC(){
               if (L)
               {
                       luaL_unref(L,LUA_REGISTRYINDEX,refKey );
               }
       }

       no error occur, but I wonder if it will work as I expect.

mos