lua-users home
lua-l archive

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


Hi,

If you take a look at lua_close...

    LUA_API void lua_close (lua_State *L) {
      L = G(L)->mainthread;  /* only the main thread can be closed */
      luai_userstateclose(L);
      lua_lock(L);
      luaF_close(L, L->stack);  /* close all upvalues for this thread */
      luaC_separateudata(L, 1);  /* separate udata that have GC metamethods */
      L->errfunc = 0;  /* no error function during GC metamethods */
      do {  /* repeat until no more errors */
        L->ci = L->base_ci;
        L->base = L->top = L->ci->base;
        L->nCcalls = 0;
      } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
      lua_assert(G(L)->tmudata == NULL);
      close_state(L);
    }

... you notice luai_userstateclose is called right before a
lua_lock.  Now, lua_lock probably uses stuff in the user
state that was allocated and initialized during a call to
luai_userstateopen. Isn't this stuff supposed to freed by a
call to luai_userstateclose? And if so, isn't calling
lua_lock right after it A Very Bad Thing (TM)?

What is the rationale for this? Why not call
luai_userstateclose only at the very end?

Regards,
Diego.