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

Function lua_newstate

third-party/lua-5.5.0/src/lstate.c:336–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334
335
336LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) {
337 int i;
338 lua_State *L;
339 global_State *g = cast(global_State*,
340 (*f)(ud, NULL, LUA_TTHREAD, sizeof(global_State)));
341 if (g == NULL) return NULL;
342 L = &g->mainth.l;
343 L->tt = LUA_VTHREAD;
344 g->currentwhite = bitmask(WHITE0BIT);
345 L->marked = luaC_white(g);
346 preinit_thread(L, g);
347 g->allgc = obj2gco(L); /* by now, only object is the main thread */
348 L->next = NULL;
349 incnny(L); /* main thread is always non yieldable */
350 g->frealloc = f;
351 g->ud = ud;
352 g->warnf = NULL;
353 g->ud_warn = NULL;
354 g->seed = seed;
355 g->gcstp = GCSTPGC; /* no GC while building state */
356 g->strt.size = g->strt.nuse = 0;
357 g->strt.hash = NULL;
358 setnilvalue(&g->l_registry);
359 g->panic = NULL;
360 g->gcstate = GCSpause;
361 g->gckind = KGC_INC;
362 g->gcstopem = 0;
363 g->gcemergency = 0;
364 g->finobj = g->tobefnz = g->fixedgc = NULL;
365 g->firstold1 = g->survival = g->old1 = g->reallyold = NULL;
366 g->finobjsur = g->finobjold1 = g->finobjrold = NULL;
367 g->sweepgc = NULL;
368 g->gray = g->grayagain = NULL;
369 g->weak = g->ephemeron = g->allweak = NULL;
370 g->twups = NULL;
371 g->GCtotalbytes = sizeof(global_State);
372 g->GCmarked = 0;
373 g->GCdebt = 0;
374 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */
375 setgcparam(g, PAUSE, LUAI_GCPAUSE);
376 setgcparam(g, STEPMUL, LUAI_GCMUL);
377 setgcparam(g, STEPSIZE, LUAI_GCSTEPSIZE);
378 setgcparam(g, MINORMUL, LUAI_GENMINORMUL);
379 setgcparam(g, MINORMAJOR, LUAI_MINORMAJOR);
380 setgcparam(g, MAJORMINOR, LUAI_MAJORMINOR);
381 for (i=0; i < LUA_NUMTYPES; i++) g->mt[i] = NULL;
382 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
383 /* memory allocation error: free partial state */
384 close_state(L);
385 L = NULL;
386 }
387 return L;
388}
389
390
391LUA_API void lua_close (lua_State *L) {

Callers 1

(luaL_newstate)Function · 0.70

Calls 3

preinit_threadFunction · 0.70
luaD_rawrunprotectedFunction · 0.70
close_stateFunction · 0.70

Tested by

no test coverage detected