Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef lstate_h
00008 #define lstate_h
00009
00010 #include "lua.h"
00011
00012 #include "lobject.h"
00013 #include "ltm.h"
00014 #include "lzio.h"
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 struct lua_longjmp;
00043
00044
00045
00046
00047 #define EXTRA_STACK 5
00048
00049
00050 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
00051
00052
00053
00054 #define KGC_NORMAL 0
00055 #define KGC_EMERGENCY 1
00056 #define KGC_GEN 2
00057
00058
00059 typedef struct stringtable {
00060 GCObject **hash;
00061 lu_int32 nuse;
00062 int size;
00063 } stringtable;
00064
00065
00066
00067
00068
00069 typedef struct CallInfo {
00070 StkId func;
00071 StkId top;
00072 struct CallInfo *previous, *next;
00073 short nresults;
00074 lu_byte callstatus;
00075 union {
00076 struct {
00077 StkId base;
00078 const Instruction *savedpc;
00079 } l;
00080 struct {
00081 int ctx;
00082 lua_CFunction k;
00083 ptrdiff_t old_errfunc;
00084 ptrdiff_t extra;
00085 lu_byte old_allowhook;
00086 lu_byte status;
00087 } c;
00088 } u;
00089 } CallInfo;
00090
00091
00092
00093
00094
00095 #define CIST_LUA (1<<0)
00096 #define CIST_HOOKED (1<<1)
00097 #define CIST_REENTRY (1<<2)
00098
00099 #define CIST_YIELDED (1<<3)
00100 #define CIST_YPCALL (1<<4)
00101 #define CIST_STAT (1<<5)
00102 #define CIST_TAIL (1<<6)
00103
00104
00105 #define isLua(ci) ((ci)->callstatus & CIST_LUA)
00106
00107
00108
00109
00110
00111 typedef struct global_State {
00112 lua_Alloc frealloc;
00113 void *ud;
00114 lu_mem totalbytes;
00115 l_mem GCdebt;
00116 lu_mem lastmajormem;
00117 stringtable strt;
00118 TValue l_registry;
00119 lu_byte currentwhite;
00120 lu_byte gcstate;
00121 lu_byte gckind;
00122 lu_byte gcrunning;
00123 int sweepstrgc;
00124 GCObject *allgc;
00125 GCObject *finobj;
00126 GCObject **sweepgc;
00127 GCObject *gray;
00128 GCObject *grayagain;
00129 GCObject *weak;
00130 GCObject *ephemeron;
00131 GCObject *allweak;
00132 GCObject *tobefnz;
00133 UpVal uvhead;
00134 Mbuffer buff;
00135 int gcpause;
00136 int gcmajorinc;
00137 int gcstepmul;
00138 lua_CFunction panic;
00139 struct lua_State *mainthread;
00140 const lua_Number *version;
00141 TString *memerrmsg;
00142 TString *tmname[TM_N];
00143 struct Table *mt[LUA_NUMTAGS];
00144 } global_State;
00145
00146
00147
00148
00149
00150 struct lua_State {
00151 CommonHeader;
00152 lu_byte status;
00153 StkId top;
00154 global_State *l_G;
00155 CallInfo *ci;
00156 const Instruction *oldpc;
00157 StkId stack_last;
00158 StkId stack;
00159 int stacksize;
00160 unsigned short nny;
00161 unsigned short nCcalls;
00162 lu_byte hookmask;
00163 lu_byte allowhook;
00164 int basehookcount;
00165 int hookcount;
00166 lua_Hook hook;
00167 GCObject *openupval;
00168 GCObject *gclist;
00169 struct lua_longjmp *errorJmp;
00170 ptrdiff_t errfunc;
00171 CallInfo base_ci;
00172 };
00173
00174
00175 #define G(L) (L->l_G)
00176
00177
00178
00179
00180
00181 union GCObject {
00182 GCheader gch;
00183 union TString ts;
00184 union Udata u;
00185 union Closure cl;
00186 struct Table h;
00187 struct Proto p;
00188 struct UpVal uv;
00189 struct lua_State th;
00190 };
00191
00192
00193 #define gch(o) (&(o)->gch)
00194
00195
00196 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
00197 #define gco2ts(o) (&rawgco2ts(o)->tsv)
00198 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
00199 #define gco2u(o) (&rawgco2u(o)->uv)
00200 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
00201 #define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
00202 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
00203 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
00204 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
00205
00206
00207 #define obj2gco(v) (cast(GCObject *, (v)))
00208
00209
00210
00211 #define gettotalbytes(g) ((g)->totalbytes + (g)->GCdebt)
00212
00213 LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
00214 LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
00215 LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
00216 LUAI_FUNC void luaE_freeCI (lua_State *L);
00217
00218
00219 #endif
00220