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

Function lua_newstate

src/Chain/libraries/glua/lstate.cpp:299–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297
298
299LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) {
300 int i;
301 lua_State *L;
302 global_State *g;
303 LG *l = lua_cast(LG *, (*f)(ud, nullptr, LUA_TTHREAD, sizeof(LG)));
304 if (l == nullptr) return nullptr;
305 L = &l->l.l;
306 g = &l->g;
307 L->next = nullptr;
308 L->tt = LUA_TTHREAD;
309 g->currentwhite = bitmask(WHITE0BIT);
310 L->marked = luaC_white(g);
311 L->malloc_buffer = malloc(LUA_MALLOC_TOTAL_SIZE);
312 L->malloc_pos = 0;
313 L->malloced_buffers = new std::list<std::pair<ptrdiff_t, ptrdiff_t>>();
314 memset(L->compile_error, 0x0, LUA_COMPILE_ERROR_MAX_LENGTH);
315 memset(L->runerror, 0x0, LUA_VM_EXCEPTION_STRNG_MAX_LENGTH);
316 L->bytecode_debugger_opened = false;
317 L->in = stdin;
318 L->out = stdout;
319 L->err = stderr;
320 L->force_stopping = false;
321 L->exit_code = 0;
322 L->debugger_pausing = false;
323 L->preprocessor = nullptr;
324 preinit_thread(L, g);
325 g->frealloc = f;
326 g->ud = ud;
327 g->mainthread = L;
328 g->seed = makeseed(L);
329 g->gcrunning = 0; /* no GC while building state */
330 g->GCestimate = 0;
331 g->strt.size = g->strt.nuse = 0;
332 g->strt.hash = nullptr;
333 setnilvalue(&g->l_registry);
334 g->panic = nullptr;
335 g->version = nullptr;
336 g->gcstate = GCSpause;
337 g->gckind = KGC_NORMAL;
338 g->allgc = g->finobj = g->tobefnz = g->fixedgc = nullptr;
339 g->sweepgc = nullptr;
340 g->gray = g->grayagain = nullptr;
341 g->weak = g->ephemeron = g->allweak = nullptr;
342 g->twups = nullptr;
343 g->totalbytes = sizeof(LG);
344 g->GCdebt = 0;
345 g->gcfinnum = 0;
346 g->gcpause = LUAI_GCPAUSE;
347 g->gcstepmul = LUAI_GCMUL;
348 for (i = 0; i < LUA_NUMTAGS; i++) g->mt[i] = nullptr;
349 if (luaD_rawrunprotected(L, f_luaopen, nullptr) != LUA_OK) {
350 /* memory allocation error: free partial state */
351 close_state(L);
352 L = nullptr;
353 }
354 return L;
355}
356

Callers 1

luaL_newstateFunction · 0.85

Calls 4

preinit_threadFunction · 0.85
makeseedFunction · 0.85
luaD_rawrunprotectedFunction · 0.85
close_stateFunction · 0.85

Tested by

no test coverage detected