1
2
3
4
5
6
7 #ifndef lstate_h
8 #define lstate_h
9
10 #include "lua.h"
11
12 #include "lobject.h"
13 #include "ltm.h"
14 #include "lzio.h"
15
16
17
18 struct lua_longjmp;
19
20
21
22 #define gt(L) (&L->l_gt)
23
24
25 #define registry(L) (&G(L)->l_registry)
26
27
28
29 #define EXTRA_STACK 5
30
31
32 #define BASIC_CI_SIZE 8
33
34 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
35
36
37
38 typedef struct stringtable {
39 GCObject **hash;
40 lu_int32 nuse;
41 int size;
42 } stringtable;
43
44
45
46
47
48 typedef struct CallInfo {
49 StkId base;
50 StkId func;
51 StkId top;
52 const Instruction *savedpc;
53 int nresults;
54 int tailcalls;
55 } CallInfo;
56
57
58
59 #define curr_func(L) (clvalue(L->ci->func))
60 #define ci_func(ci) (clvalue((ci)->func))
61 #define f_isLua(ci) (!ci_func(ci)->c.isC)
62 #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
63
64
65
66
67
68 typedef struct global_State {
69 stringtable strt;
70 lua_Alloc frealloc;
71 void *ud;
72 lu_byte currentwhite;
73 lu_byte gcstate;
74 int sweepstrgc;
75 GCObject *rootgc;
76 GCObject **sweepgc;
77 GCObject *gray;
78 GCObject *grayagain;
79 GCObject *weak;
80 GCObject *tmudata;
81 Mbuffer buff;
82 lu_mem GCthreshold;
83 lu_mem totalbytes;
84 lu_mem estimate;
85 lu_mem gcdept;
86 int gcpause;
87 int gcstepmul;
88 lua_CFunction panic;
89 TValue l_registry;
90 struct lua_State *mainthread;
91 UpVal uvhead;
92 struct Table *mt[NUM_TAGS];
93 TString *tmname[TM_N];
94 } global_State;
95
96
97
98
99
100 struct lua_State {
101 CommonHeader;
102 lu_byte status;
103 StkId top;
104 StkId base;
105 global_State *l_G;
106 CallInfo *ci;
107 const Instruction *savedpc;
108 StkId stack_last;
109 StkId stack;
110 CallInfo *end_ci;
111 CallInfo *base_ci;
112 int stacksize;
113 int size_ci;
114 unsigned short nCcalls;
115 unsigned short baseCcalls;
116 lu_byte hookmask;
117 lu_byte allowhook;
118 int basehookcount;
119 int hookcount;
120 lua_Hook hook;
121 TValue l_gt;
122 TValue env;
123 GCObject *openupval;
124 GCObject *gclist;
125 struct lua_longjmp *errorJmp;
126 ptrdiff_t errfunc;
127 };
128
129
130 #define G(L) (L->l_G)
131
132
133
134
135
136 union GCObject {
137 GCheader gch;
138 union TString ts;
139 union Udata u;
140 union Closure cl;
141 struct Table h;
142 struct Proto p;
143 struct UpVal uv;
144 struct lua_State th;
145 };
146
147
148
149 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
150 #define gco2ts(o) (&rawgco2ts(o)->tsv)
151 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
152 #define gco2u(o) (&rawgco2u(o)->uv)
153 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
154 #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
155 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
156 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
157 #define ngcotouv(o) \
158 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
159 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
160
161
162 #define obj2gco(v) (cast(GCObject *, (v)))
163
164
165 LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
166 LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
167
168 #endif
169