MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / lua_newstate

Function lua_newstate

other_src/lua/src/lstate.cpp:147–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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