Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lstate.c File Reference
#include <stddef.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "llex.h"
#include "lmem.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"

Go to the source code of this file.

Data Structures

struct  LG
 

Macros

#define lstate_c
 
#define LUA_CORE
 
#define state_size(x)   (sizeof(x) + LUAI_EXTRASPACE)
 
#define fromstate(l)   (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
 
#define tostate(l)   (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
 

Typedefs

typedef struct LG LG
 

Functions

static void stack_init (lua_State *L1, lua_State *L)
 
static void freestack (lua_State *L, lua_State *L1)
 
static void f_luaopen (lua_State *L, void *ud)
 
static void preinit_state (lua_State *L, global_State *g)
 
static void close_state (lua_State *L)
 
lua_StateluaE_newthread (lua_State *L)
 
void luaE_freethread (lua_State *L, lua_State *L1)
 
LUA_API lua_Statelua_newstate (lua_Alloc f, void *ud)
 
static void callallgcTM (lua_State *L, void *ud)
 
LUA_API void lua_close (lua_State *L)
 

Macro Definition Documentation

◆ fromstate

#define fromstate ( l)    (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)

Definition at line 28 of file lua-5.1.5/src/lstate.c.

Referenced by close_state(), and luaE_freethread().

◆ lstate_c

#define lstate_c

Definition at line 10 of file lua-5.1.5/src/lstate.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 11 of file lua-5.1.5/src/lstate.c.

◆ state_size

#define state_size ( x)    (sizeof(x) + LUAI_EXTRASPACE)

Definition at line 27 of file lua-5.1.5/src/lstate.c.

Referenced by close_state(), lua_newstate(), luaE_freethread(), and luaE_newthread().

◆ tostate

#define tostate ( l)    (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))

Definition at line 29 of file lua-5.1.5/src/lstate.c.

Referenced by lua_newstate(), and luaE_newthread().

Typedef Documentation

◆ LG

typedef struct LG LG

Function Documentation

◆ callallgcTM()

static void callallgcTM ( lua_State * L,
void * ud )
static

Definition at line 193 of file lua-5.1.5/src/lstate.c.

193 {
194 UNUSED(ud);
195 luaC_callGCTM(L); /* call GC metamethods for all udata */
196}
void luaC_callGCTM(lua_State *L)
#define UNUSED(x)

References luaC_callGCTM(), and UNUSED.

Referenced by lua_close().

◆ close_state()

static void close_state ( lua_State * L)
static

Definition at line 105 of file lua-5.1.5/src/lstate.c.

105 {
106 global_State *g = G(L);
107 luaF_close(L, L->stack); /* close all upvalues for this thread */
108 luaC_freeall(L); /* collect all objects */
109 lua_assert(g->rootgc == obj2gco(L));
110 lua_assert(g->strt.nuse == 0);
111 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
112 luaZ_freebuffer(L, &g->buff);
113 freestack(L, L);
114 lua_assert(g->totalbytes == sizeof(LG));
115 (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
116}
void luaF_close(lua_State *L, StkId level)
void luaC_freeall(lua_State *L)
#define lua_assert(c)
#define luaM_freearray(L, b, n, t)
#define state_size(x)
static void freestack(lua_State *L, lua_State *L1)
#define fromstate(l)
#define G(L)
#define obj2gco(v)
#define luaZ_freebuffer(L, buff)

References global_State::buff, global_State::frealloc, freestack(), fromstate, G, lua_assert, luaC_freeall(), luaF_close(), luaM_freearray, luaZ_freebuffer, stringtable::nuse, obj2gco, global_State::rootgc, lua_State::stack, state_size, global_State::strt, global_State::totalbytes, and global_State::ud.

Referenced by lua_close(), and lua_newstate().

◆ f_luaopen()

static void f_luaopen ( lua_State * L,
void * ud )
static

Definition at line 70 of file lua-5.1.5/src/lstate.c.

70 {
71 global_State *g = G(L);
72 UNUSED(ud);
73 stack_init(L, L); /* init stack */
74 sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
75 sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
76 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
77 luaT_init(L);
78 luaX_init(L);
80 g->GCthreshold = 4*g->totalbytes;
81}
#define MINSTRTABSIZE
#define MEMERRMSG
#define sethvalue(L, obj, x)
static void stack_init(lua_State *L1, lua_State *L)
#define gt(L)
#define registry(L)
void luaS_resize(lua_State *L, int newsize)
#define luaS_newliteral(L, s)
#define luaS_fix(s)
Table * luaH_new(lua_State *L, int narray, int nhash)
void luaT_init(lua_State *L)
LUAI_FUNC void luaX_init(lua_State *L)
Definition noparser.c:21

References G, global_State::GCthreshold, gt, luaH_new(), luaS_fix, luaS_newliteral, luaS_resize(), luaT_init(), luaX_init(), MEMERRMSG, MINSTRTABSIZE, registry, sethvalue, stack_init(), global_State::totalbytes, and UNUSED.

Referenced by lua_newstate().

◆ freestack()

◆ lua_close()

LUA_API void lua_close ( lua_State * L)

Definition at line 199 of file lua-5.1.5/src/lstate.c.

199 {
200 L = G(L)->mainthread; /* only the main thread can be closed */
201 lua_lock(L);
202 luaF_close(L, L->stack); /* close all upvalues for this thread */
203 luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
204 L->errfunc = 0; /* no error function during GC metamethods */
205 do { /* repeat until no more errors */
206 L->ci = L->base_ci;
207 L->base = L->top = L->ci->base;
208 L->nCcalls = L->baseCcalls = 0;
209 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
210 lua_assert(G(L)->tmudata == NULL);
212 close_state(L);
213}
#define NULL
Definition gmacros.h:924
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
size_t luaC_separateudata(lua_State *L, int all)
#define lua_lock(L)
static void close_state(lua_State *L)
static void callallgcTM(lua_State *L, void *ud)
#define luai_userstateclose(L)
unsigned short nCcalls
unsigned short baseCcalls

References CallInfo::base, lua_State::base, lua_State::base_ci, lua_State::baseCcalls, callallgcTM(), lua_State::ci, close_state(), lua_State::errfunc, G, lua_assert, lua_lock, luaC_separateudata(), luaD_rawrunprotected(), luaF_close(), luai_userstateclose, lua_State::nCcalls, NULL, lua_State::stack, and lua_State::top.

Referenced by main(), main(), main(), master_thread_run(), os_exit(), os_exit(), and os_exit().

◆ lua_newstate()

LUA_API lua_State * lua_newstate ( lua_Alloc f,
void * ud )

Definition at line 143 of file lua-5.1.5/src/lstate.c.

143 {
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;
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;
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);
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
189 return L;
190}
#define bit2mask(b1, b2)
#define WHITE0BIT
#define FIXEDBIT
#define SFIXEDBIT
#define set2bits(x, b1, b2)
#define GCSpause
#define luaC_white(g)
#define NUM_TAGS
#define setnilvalue(obj)
#define tostate(l)
static void f_luaopen(lua_State *L, void *ud)
static void preinit_state(lua_State *L, global_State *g)
struct LG LG
#define LUA_TTHREAD
#define luai_userstateopen(L)
#define LUAI_GCPAUSE
#define LUAI_GCMUL
#define luaZ_initbuffer(L, buff)
struct UpVal * prev
union UpVal::@48 u
struct UpVal * next
struct UpVal::@48::@49 l
struct lua_State * mainthread
lua_CFunction panic
struct Table * mt[NUM_TAGS]

References bit2mask, global_State::buff, close_state(), global_State::currentwhite, f_luaopen(), FIXEDBIT, global_State::frealloc, global_State::gcdept, global_State::gcpause, GCSpause, global_State::gcstate, global_State::gcstepmul, global_State::GCthreshold, global_State::gray, global_State::grayagain, stringtable::hash, UpVal::l, LUA_TTHREAD, luaC_white, luaD_rawrunprotected(), LUAI_GCMUL, LUAI_GCPAUSE, luai_userstateopen, luaZ_initbuffer, global_State::mainthread, global_State::mt, UpVal::next, NULL, NUM_TAGS, stringtable::nuse, obj2gco, global_State::panic, preinit_state(), UpVal::prev, registry, global_State::rootgc, set2bits, setnilvalue, SFIXEDBIT, stringtable::size, state_size, global_State::strt, global_State::sweepgc, global_State::sweepstrgc, global_State::tmudata, tostate, global_State::totalbytes, UpVal::u, global_State::ud, global_State::uvhead, global_State::weak, and WHITE0BIT.

Referenced by luaL_newstate().

◆ luaE_freethread()

void luaE_freethread ( lua_State * L,
lua_State * L1 )

Definition at line 134 of file lua-5.1.5/src/lstate.c.

134 {
135 luaF_close(L1, L1->stack); /* close all upvalues for this thread */
136 lua_assert(L1->openupval == NULL);
138 freestack(L, L1);
140}
#define luaM_freemem(L, b, s)
#define luai_userstatefree(L)
GCObject * openupval

References freestack(), fromstate, lua_assert, luaF_close(), luai_userstatefree, luaM_freemem, NULL, lua_State::openupval, lua_State::stack, and state_size.

Referenced by freeobj(), freeobj(), freeobj(), and freeobj().

◆ luaE_newthread()

lua_State * luaE_newthread ( lua_State * L)

Definition at line 119 of file lua-5.1.5/src/lstate.c.

119 {
122 preinit_state(L1, G(L));
123 stack_init(L1, L); /* init stack */
124 setobj2n(L, gt(L1), gt(L)); /* share table of globals */
125 L1->hookmask = L->hookmask;
127 L1->hook = L->hook;
128 resethookcount(L1);
130 return L1;
131}
#define resethookcount(L)
void luaC_link(lua_State *L, GCObject *o, lu_byte tt)
#define iswhite(x)
#define luaM_malloc(L, t)
#define setobj2n

References lua_State::basehookcount, G, gt, lua_State::hook, lua_State::hookmask, iswhite, lua_assert, LUA_TTHREAD, luaC_link(), luaM_malloc, obj2gco, preinit_state(), resethookcount, setobj2n, stack_init(), state_size, and tostate.

Referenced by lua_newthread().

◆ preinit_state()

static void preinit_state ( lua_State * L,
global_State * g )
static

◆ stack_init()

static void stack_init ( lua_State * L1,
lua_State * L )
static

Definition at line 42 of file lua-5.1.5/src/lstate.c.

42 {
43 /* initialize CallInfo array */
45 L1->ci = L1->base_ci;
47 L1->end_ci = L1->base_ci + L1->size_ci - 1;
48 /* initialize stack array */
51 L1->top = L1->stack;
52 L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
53 /* initialize first ci */
54 L1->ci->func = L1->top;
55 setnilvalue(L1->top++); /* `function' entry for this `ci' */
56 L1->base = L1->ci->base = L1->top;
57 L1->ci->top = L1->top + LUA_MINSTACK;
58}
#define luaM_newvector(L, n, t)
#define BASIC_STACK_SIZE
#define EXTRA_STACK
#define BASIC_CI_SIZE
#define LUA_MINSTACK

References CallInfo::base, lua_State::base, lua_State::base_ci, BASIC_CI_SIZE, BASIC_STACK_SIZE, lua_State::ci, lua_State::end_ci, EXTRA_STACK, CallInfo::func, LUA_MINSTACK, luaM_newvector, setnilvalue, lua_State::size_ci, lua_State::stack, lua_State::stack_last, lua_State::stacksize, CallInfo::top, and lua_State::top.

Referenced by f_luaopen(), and luaE_newthread().