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

Function lua_newstate

third-party/lua-5.2.4/src/lstate.c:266–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

luaL_newstateFunction · 0.70

Calls 4

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

Tested by

no test coverage detected