MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / lua_newstate

Function lua_newstate

extlibs/lua/src/lstate.c:377–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375
376
377LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
378 int i;
379 lua_State *L;
380 global_State *g;
381 LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));
382 if (l == NULL) return NULL;
383 L = &l->l.l;
384 g = &l->g;
385 L->tt = LUA_VTHREAD;
386 g->currentwhite = bitmask(WHITE0BIT);
387 L->marked = luaC_white(g);
388 preinit_thread(L, g);
389 g->allgc = obj2gco(L); /* by now, only object is the main thread */
390 L->next = NULL;
391 g->Cstacklimit = L->nCcalls = LUAI_MAXCSTACK + CSTACKERR;
392 g->frealloc = f;
393 g->ud = ud;
394 g->warnf = NULL;
395 g->ud_warn = NULL;
396 g->mainthread = L;
397 g->seed = luai_makeseed(L);
398 g->gcrunning = 0; /* no GC while building state */
399 g->strt.size = g->strt.nuse = 0;
400 g->strt.hash = NULL;
401 setnilvalue(&g->l_registry);
402 g->panic = NULL;
403 g->gcstate = GCSpause;
404 g->gckind = KGC_INC;
405 g->gcemergency = 0;
406 g->finobj = g->tobefnz = g->fixedgc = NULL;
407 g->survival = g->old = g->reallyold = NULL;
408 g->finobjsur = g->finobjold = g->finobjrold = NULL;
409 g->sweepgc = NULL;
410 g->gray = g->grayagain = NULL;
411 g->weak = g->ephemeron = g->allweak = NULL;
412 g->twups = NULL;
413 g->totalbytes = sizeof(LG);
414 g->GCdebt = 0;
415 g->lastatomic = 0;
416 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */
417 setgcparam(g->gcpause, LUAI_GCPAUSE);
418 setgcparam(g->gcstepmul, LUAI_GCMUL);
419 g->gcstepsize = LUAI_GCSTEPSIZE;
420 setgcparam(g->genmajormul, LUAI_GENMAJORMUL);
421 g->genminormul = LUAI_GENMINORMUL;
422 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
423 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
424 /* memory allocation error: free partial state */
425 close_state(L);
426 L = NULL;
427 }
428 return L;
429}
430
431
432LUA_API void lua_close (lua_State *L) {

Callers 2

luaL_newstateFunction · 0.85
stateMethod · 0.85

Calls 4

preinit_threadFunction · 0.85
luai_makeseedFunction · 0.85
luaD_rawrunprotectedFunction · 0.85
close_stateFunction · 0.85

Tested by

no test coverage detected