| 293 | |
| 294 | |
| 295 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { |
| 296 | int i; |
| 297 | lua_State *L; |
| 298 | global_State *g; |
| 299 | LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG))); |
| 300 | if (l == NULL) return NULL; |
| 301 | L = &l->l.l; |
| 302 | g = &l->g; |
| 303 | L->next = NULL; |
| 304 | L->tt = LUA_TTHREAD; |
| 305 | g->currentwhite = bitmask(WHITE0BIT); |
| 306 | L->marked = luaC_white(g); |
| 307 | preinit_thread(L, g); |
| 308 | g->frealloc = f; |
| 309 | g->ud = ud; |
| 310 | g->mainthread = L; |
| 311 | g->seed = makeseed(L); |
| 312 | g->gcrunning = 0; /* no GC while building state */ |
| 313 | g->GCestimate = 0; |
| 314 | g->strt.size = g->strt.nuse = 0; |
| 315 | g->strt.hash = NULL; |
| 316 | setnilvalue(&g->l_registry); |
| 317 | g->panic = NULL; |
| 318 | g->version = NULL; |
| 319 | g->gcstate = GCSpause; |
| 320 | g->gckind = KGC_NORMAL; |
| 321 | g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL; |
| 322 | g->sweepgc = NULL; |
| 323 | g->gray = g->grayagain = NULL; |
| 324 | g->weak = g->ephemeron = g->allweak = NULL; |
| 325 | g->twups = NULL; |
| 326 | g->totalbytes = sizeof(LG); |
| 327 | g->GCdebt = 0; |
| 328 | g->gcfinnum = 0; |
| 329 | g->gcpause = LUAI_GCPAUSE; |
| 330 | g->gcstepmul = LUAI_GCMUL; |
| 331 | for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; |
| 332 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { |
| 333 | /* memory allocation error: free partial state */ |
| 334 | close_state(L); |
| 335 | L = NULL; |
| 336 | } |
| 337 | return L; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | LUA_API void lua_close (lua_State *L) { |
no test coverage detected