MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / lua_newstate

Function lua_newstate

Source/Misc/lua/src/lua.c:9058–9105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9056
9057
9058LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
9059int i;
9060lua_State *L;
9061global_State *g;
9062void *l = (*f)(ud, NULL, 0, state_size(LG));
9063if (l == NULL) return NULL;
9064L = tostate(l);
9065g = &((LG *)L)->g;
9066L->next = NULL;
9067L->tt = LUA_TTHREAD;
9068g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
9069L->marked = luaC_white(g);
9070set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
9071preinit_state(L, g);
9072g->frealloc = f;
9073g->ud = ud;
9074g->mainthread = L;
9075g->uvhead.u.l.prev = &g->uvhead;
9076g->uvhead.u.l.next = &g->uvhead;
9077g->GCthreshold = 0; /* mark it as unfinished state */
9078g->strt.size = 0;
9079g->strt.nuse = 0;
9080g->strt.hash = NULL;
9081setnilvalue(registry(L));
9082luaZ_initbuffer(L, &g->buff);
9083g->panic = NULL;
9084g->gcstate = GCSpause;
9085g->rootgc = obj2gco(L);
9086g->sweepstrgc = 0;
9087g->sweepgc = &g->rootgc;
9088g->gray = NULL;
9089g->grayagain = NULL;
9090g->weak = NULL;
9091g->tmudata = NULL;
9092g->totalbytes = sizeof(LG);
9093g->gcpause = LUAI_GCPAUSE;
9094g->gcstepmul = LUAI_GCMUL;
9095g->gcdept = 0;
9096for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
9097if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
9098/* memory allocation error: free partial state */
9099close_state(L);
9100L = NULL;
9101}
9102else
9103luai_userstateopen(L);
9104return L;
9105}
9106
9107
9108static void callallgcTM (lua_State *L, void *ud) {

Callers 1

luaL_newstateFunction · 0.85

Calls 4

preinit_stateFunction · 0.85
registryFunction · 0.85
luaD_rawrunprotectedFunction · 0.85
close_stateFunction · 0.85

Tested by

no test coverage detected