/* ** open parts that may cause memory-allocation errors */ static void f_luaopen (lua_State *L, void *ud) { int stacksize = *(int *)ud; if (stacksize == 0) stacksize = DEFAULT_STACK_SIZE; else stacksize += LUA_MINSTACK; L->gt = luaH_new(L, 10); /* table of globals */ luaD_init(L, stacksize); luaS_init(L); luaX_init(L); luaT_init(L); lua_newtable(L); lua_ref(L, 1); /* create registry */ lua_register(L, LUA_ERRORMESSAGE, errormessage); #ifdef LUA_DEBUG luaB_opentests(L); if (lua_state == NULL) lua_state = L; /* keep first state to be opened */ #endif LUA_ASSERT(lua_gettop(L) == 0, "wrong API stack"); }
void lua_resetglobals() { lua_openthr(); rootproto.next = nullptr; rootproto.marked = 0; rootcl.next = nullptr; rootcl.marked = 0; rootglobal.next = nullptr; rootglobal.marked = 0; roottable.next = nullptr; roottable.marked = 0; refArray = nullptr; refSize = 0; GCthreshold = GARBAGE_BLOCK; nblocks = 0; luaD_init(); luaS_init(); luaX_init(); }
void lua_open (void) { if (lua_state) return; lua_state = luaM_new(lua_State); L->Cstack.base = 0; L->Cstack.lua2C = 0; L->Cstack.num = 0; L->errorJmp = NULL; L->Mbuffer = NULL; L->Mbuffbase = 0; L->Mbuffsize = 0; L->Mbuffnext = 0; L->Cblocks = NULL; L->numCblocks = 0; L->debug = 0; L->callhook = NULL; L->linehook = NULL; L->rootproto.next = NULL; L->rootproto.marked = 0; L->rootcl.next = NULL; L->rootcl.marked = 0; L->rootglobal.next = NULL; L->rootglobal.marked = 0; L->roottable.next = NULL; L->roottable.marked = 0; L->IMtable = NULL; L->refArray = NULL; L->refSize = 0; L->GCthreshold = GARBAGE_BLOCK; L->nblocks = 0; luaD_init(); luaS_init(); luaX_init(); luaT_init(); luaB_predefine(); }