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

Function lua_newstate

app/redis-6.2.6/deps/lua/src/lstate.c:143–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141
142
143LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
144 int i;
145 lua_State *L;
146 global_State *g;
147 void *l = (*f)(ud, NULL, 0, state_size(LG));
148 if (l == NULL) return NULL;
149 L = tostate(l);
150 g = &((LG *)L)->g;
151 L->next = NULL;
152 L->tt = LUA_TTHREAD;
153 g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
154 L->marked = luaC_white(g);
155 set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
156 preinit_state(L, g);
157 g->frealloc = f;
158 g->ud = ud;
159 g->mainthread = L;
160 g->uvhead.u.l.prev = &g->uvhead;
161 g->uvhead.u.l.next = &g->uvhead;
162 g->GCthreshold = 0; /* mark it as unfinished state */
163 g->strt.size = 0;
164 g->strt.nuse = 0;
165 g->strt.hash = NULL;
166 setnilvalue(registry(L));
167 luaZ_initbuffer(L, &g->buff);
168 g->panic = NULL;
169 g->gcstate = GCSpause;
170 g->rootgc = obj2gco(L);
171 g->sweepstrgc = 0;
172 g->sweepgc = &g->rootgc;
173 g->gray = NULL;
174 g->grayagain = NULL;
175 g->weak = NULL;
176 g->tmudata = NULL;
177 g->totalbytes = sizeof(LG);
178 g->gcpause = LUAI_GCPAUSE;
179 g->gcstepmul = LUAI_GCMUL;
180 g->gcdept = 0;
181 for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
182 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
183 /* memory allocation error: free partial state */
184 close_state(L);
185 L = NULL;
186 }
187 else
188 luai_userstateopen(L);
189 return L;
190}
191
192
193static void callallgcTM (lua_State *L, void *ud) {

Callers 1

luaL_newstateFunction · 0.70

Calls 3

preinit_stateFunction · 0.70
luaD_rawrunprotectedFunction · 0.70
close_stateFunction · 0.70

Tested by

no test coverage detected