MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / lua_newstate

Function lua_newstate

lib/lua/src/lstate.c:360–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

luaL_newstateFunction · 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