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