MCPcopy Create free account
hub / github.com/F-Stack/f-stack / lua_newstate

Function lua_newstate

freebsd/contrib/openzfs/module/lua/lstate.c:264–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262
263
264LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
265 int i;
266 lua_State *L;
267 global_State *g;
268 LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));
269 if (l == NULL) return NULL;
270 L = &l->l.l;
271 g = &l->g;
272 L->next = NULL;
273 L->tt = LUA_TTHREAD;
274 g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
275 L->marked = luaC_white(g);
276 g->gckind = KGC_NORMAL;
277 preinit_state(L, g);
278 g->frealloc = f;
279 g->ud = ud;
280 g->mainthread = L;
281 g->seed = makeseed(L);
282 g->uvhead.u.l.prev = &g->uvhead;
283 g->uvhead.u.l.next = &g->uvhead;
284 g->gcrunning = 0; /* no GC while building state */
285 g->GCestimate = 0;
286 g->strt.size = 0;
287 g->strt.nuse = 0;
288 g->strt.hash = NULL;
289 setnilvalue(&g->l_registry);
290 luaZ_initbuffer(L, &g->buff);
291 g->panic = NULL;
292 g->version = NULL;
293 g->gcstate = GCSpause;
294 g->allgc = NULL;
295 g->finobj = NULL;
296 g->tobefnz = NULL;
297 g->sweepgc = g->sweepfin = NULL;
298 g->gray = g->grayagain = NULL;
299 g->weak = g->ephemeron = g->allweak = NULL;
300 g->totalbytes = sizeof(LG);
301 g->GCdebt = 0;
302 g->gcpause = LUAI_GCPAUSE;
303 g->gcmajorinc = LUAI_GCMAJOR;
304 g->gcstepmul = LUAI_GCMUL;
305 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
306 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
307 /* memory allocation error: free partial state */
308 close_state(L);
309 L = NULL;
310 }
311 return L;
312}
313
314
315LUA_API void lua_close (lua_State *L) {

Callers 1

zcp_evalFunction · 0.50

Calls 4

makeseedFunction · 0.85
preinit_stateFunction · 0.70
luaD_rawrunprotectedFunction · 0.70
close_stateFunction · 0.70

Tested by

no test coverage detected