static void close_state (lua_State *L) { global_State globalState; lua_State luaState; luaF_close(L, L->stack); /* close all upvalues for this thread */ luaState.l_G = &globalState; globalState.reallocFunc = G(L)->reallocFunc; globalState.freeFunc = G(L)->freeFunc; globalState.memData = G(L)->memData; if (G(L)) { /* close global state */ luaC_sweep(L, 1); /* collect all elements */ #if !LUA_REFCOUNT lua_assert(G(L)->rootgc == NULL); lua_assert(G(L)->rootudata == NULL); #endif LUA_REFCOUNT luaS_freeall(L); luaZ_freebuffer(L, &G(L)->buff); } freestack(L, L); if (G(L)) { //jj This check doesn't work anymore, because LuaState variables are allocated through the //jj memory interface, too. //jj lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); luaM_freelem(&luaState, G(L)); } freestate(&luaState, L); }
/* ** If possible, free concatenation buffer and shrink string table */ static void checkSizes (lua_State *L, global_State *g) { if (g->gckind != KGC_EMERGENCY) { l_mem olddebt = g->GCdebt; luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */ if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ luaS_resize(L, g->strt.size / 2); /* shrink it a little */ g->GCestimate += g->GCdebt - olddebt; /* update estimate */ } }
static void checkSizes (lua_State *L) { global_State *g = G(L); if (g->gckind != KGC_EMERGENCY) { /* do not change sizes in emergency */ int hs = g->strt.size / 2; /* half the size of the string table */ if (g->strt.nuse < cast(lu_int32, hs)) /* using less than that half? */ luaS_resize(L, hs); /* halve its size */ luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */ } }
static void close_state (lua_State *L) { global_State *g = G(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ luaC_freeallobjects(L); /* collect all objects */ luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); luaZ_freebuffer(L, &g->buff); freestack(L); lua_assert(gettotalbytes(g) == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ }
static void close_state (lua_State *L) { global_State *g = G(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ luaC_freeall(L); /* collect all objects */ lua_assert(g->rootgc == obj2gco(L)); lua_assert(g->strt.nuse == 0); luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); luaZ_freebuffer(L, &g->buff); freestack(L, L); lua_assert(g->totalbytes == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); }
static void close_state (lua_State *L) { luaF_close(L, L->stack); /* close all upvalues for this thread */ if (G(L)) { /* close global state */ luaC_sweep(L, 1); /* collect all elements */ lua_assert(G(L)->rootgc == NULL); lua_assert(G(L)->rootudata == NULL); luaS_freeall(L); luaZ_freebuffer(L, &G(L)->buff); } freestack(L, L); if (G(L)) { lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); luaM_freelem(NULL, G(L)); } freestate(NULL, L); }
/* ** dump Lua function as precompiled chunk */ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, char endian) { DumpState D; D.L=L; D.writer=w; D.data=data; D.strip=strip; D.status=0; D.swap=doendian(endian); D.endian=endian; luaZ_initbuffer(L, &D.b); DumpHeader(&D); DumpFunction(f,NULL,&D); luaZ_freebuffer(L, &D.b); return D.status; }