| 9056 | |
| 9057 | |
| 9058 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { |
| 9059 | int i; |
| 9060 | lua_State *L; |
| 9061 | global_State *g; |
| 9062 | void *l = (*f)(ud, NULL, 0, state_size(LG)); |
| 9063 | if (l == NULL) return NULL; |
| 9064 | L = tostate(l); |
| 9065 | g = &((LG *)L)->g; |
| 9066 | L->next = NULL; |
| 9067 | L->tt = LUA_TTHREAD; |
| 9068 | g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); |
| 9069 | L->marked = luaC_white(g); |
| 9070 | set2bits(L->marked, FIXEDBIT, SFIXEDBIT); |
| 9071 | preinit_state(L, g); |
| 9072 | g->frealloc = f; |
| 9073 | g->ud = ud; |
| 9074 | g->mainthread = L; |
| 9075 | g->uvhead.u.l.prev = &g->uvhead; |
| 9076 | g->uvhead.u.l.next = &g->uvhead; |
| 9077 | g->GCthreshold = 0; /* mark it as unfinished state */ |
| 9078 | g->strt.size = 0; |
| 9079 | g->strt.nuse = 0; |
| 9080 | g->strt.hash = NULL; |
| 9081 | setnilvalue(registry(L)); |
| 9082 | luaZ_initbuffer(L, &g->buff); |
| 9083 | g->panic = NULL; |
| 9084 | g->gcstate = GCSpause; |
| 9085 | g->rootgc = obj2gco(L); |
| 9086 | g->sweepstrgc = 0; |
| 9087 | g->sweepgc = &g->rootgc; |
| 9088 | g->gray = NULL; |
| 9089 | g->grayagain = NULL; |
| 9090 | g->weak = NULL; |
| 9091 | g->tmudata = NULL; |
| 9092 | g->totalbytes = sizeof(LG); |
| 9093 | g->gcpause = LUAI_GCPAUSE; |
| 9094 | g->gcstepmul = LUAI_GCMUL; |
| 9095 | g->gcdept = 0; |
| 9096 | for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL; |
| 9097 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { |
| 9098 | /* memory allocation error: free partial state */ |
| 9099 | close_state(L); |
| 9100 | L = NULL; |
| 9101 | } |
| 9102 | else |
| 9103 | luai_userstateopen(L); |
| 9104 | return L; |
| 9105 | } |
| 9106 | |
| 9107 | |
| 9108 | static void callallgcTM (lua_State *L, void *ud) { |
no test coverage detected