Lines Matching refs:L
42 static void stack_init (lua_State *L1, lua_State *L) { in stack_init() argument
44 L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); in stack_init()
49 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); in stack_init()
61 static void freestack (lua_State *L, lua_State *L1) { in freestack() argument
62 luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); in freestack()
63 luaM_freearray(L, L1->stack, L1->stacksize, TValue); in freestack()
70 static void f_luaopen (lua_State *L, void *ud) { in f_luaopen() argument
71 global_State *g = G(L); in f_luaopen()
73 stack_init(L, L); /* init stack */ in f_luaopen()
74 sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ in f_luaopen()
75 sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ in f_luaopen()
76 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ in f_luaopen()
77 luaT_init(L); in f_luaopen()
78 luaX_init(L); in f_luaopen()
79 luaS_fix(luaS_newliteral(L, MEMERRMSG)); in f_luaopen()
84 static void preinit_state (lua_State *L, global_State *g) { in preinit_state() argument
85 G(L) = g; in preinit_state()
86 L->stack = NULL; in preinit_state()
87 L->stacksize = 0; in preinit_state()
88 L->errorJmp = NULL; in preinit_state()
89 L->hook = NULL; in preinit_state()
90 L->hookmask = 0; in preinit_state()
91 L->basehookcount = 0; in preinit_state()
92 L->allowhook = 1; in preinit_state()
93 resethookcount(L); in preinit_state()
94 L->openupval = NULL; in preinit_state()
95 L->size_ci = 0; in preinit_state()
96 L->nCcalls = L->baseCcalls = 0; in preinit_state()
97 L->status = 0; in preinit_state()
98 L->base_ci = L->ci = NULL; in preinit_state()
99 L->savedpc = NULL; in preinit_state()
100 L->errfunc = 0; in preinit_state()
101 setnilvalue(gt(L)); in preinit_state()
105 static void close_state (lua_State *L) { in close_state() argument
106 global_State *g = G(L); in close_state()
107 luaF_close(L, L->stack); /* close all upvalues for this thread */ in close_state()
108 luaC_freeall(L); /* collect all objects */ in close_state()
109 lua_assert(g->rootgc == obj2gco(L)); in close_state()
111 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); in close_state()
112 luaZ_freebuffer(L, &g->buff); in close_state()
113 freestack(L, L); in close_state()
115 (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); in close_state()
119 lua_State *luaE_newthread (lua_State *L) { in luaE_newthread() argument
120 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); in luaE_newthread()
121 luaC_link(L, obj2gco(L1), LUA_TTHREAD); in luaE_newthread()
122 preinit_state(L1, G(L)); in luaE_newthread()
123 stack_init(L1, L); /* init stack */ in luaE_newthread()
124 setobj2n(L, gt(L1), gt(L)); /* share table of globals */ in luaE_newthread()
125 L1->hookmask = L->hookmask; in luaE_newthread()
126 L1->basehookcount = L->basehookcount; in luaE_newthread()
127 L1->hook = L->hook; in luaE_newthread()
134 void luaE_freethread (lua_State *L, lua_State *L1) { in luaE_freethread() argument
138 freestack(L, L1); in luaE_freethread()
139 luaM_freemem(L, fromstate(L1), state_size(lua_State)); in luaE_freethread()
145 lua_State *L; in lua_newstate() local
149 L = tostate(l); in lua_newstate()
150 g = &((LG *)L)->g; in lua_newstate()
151 L->next = NULL; in lua_newstate()
152 L->tt = LUA_TTHREAD; in lua_newstate()
154 L->marked = luaC_white(g); in lua_newstate()
155 set2bits(L->marked, FIXEDBIT, SFIXEDBIT); in lua_newstate()
156 preinit_state(L, g); in lua_newstate()
159 g->mainthread = L; in lua_newstate()
166 setnilvalue(registry(L)); in lua_newstate()
167 luaZ_initbuffer(L, &g->buff); in lua_newstate()
170 g->rootgc = obj2gco(L); in lua_newstate()
182 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { in lua_newstate()
184 close_state(L); in lua_newstate()
185 L = NULL; in lua_newstate()
188 luai_userstateopen(L); in lua_newstate()
189 return L; in lua_newstate()
193 static void callallgcTM (lua_State *L, void *ud) { in callallgcTM() argument
195 luaC_callGCTM(L); /* call GC metamethods for all udata */ in callallgcTM()
199 LUA_API void lua_close (lua_State *L) { in lua_close() argument
200 L = G(L)->mainthread; /* only the main thread can be closed */ in lua_close()
201 lua_lock(L); in lua_close()
202 luaF_close(L, L->stack); /* close all upvalues for this thread */ in lua_close()
203 luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ in lua_close()
204 L->errfunc = 0; /* no error function during GC metamethods */ in lua_close()
206 L->ci = L->base_ci; in lua_close()
207 L->base = L->top = L->ci->base; in lua_close()
208 L->nCcalls = L->baseCcalls = 0; in lua_close()
209 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); in lua_close()
210 lua_assert(G(L)->tmudata == NULL); in lua_close()
211 luai_userstateclose(L); in lua_close()
212 close_state(L); in lua_close()