MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / lua_newstate

Function lua_newstate

third-party/lua-5.4.6/src/lstate.c:363–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

luaL_newstateFunction · 0.70

Calls 4

preinit_threadFunction · 0.70
luai_makeseedFunction · 0.70
luaD_rawrunprotectedFunction · 0.70
close_stateFunction · 0.70

Tested by

no test coverage detected