lstate.h
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 struct lua_longjmp;
00019
00020
00021
00022 #define gt(L) (&L->l_gt)
00023
00024
00025 #define registry(L) (&G(L)->l_registry)
00026
00027
00028
00029 #define EXTRA_STACK 5
00030
00031
00032 #define BASIC_CI_SIZE 8
00033
00034 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
00035
00036
00037
00038 typedef struct stringtable {
00039 GCObject **hash;
00040 lu_int32 nuse;
00041 int size;
00042 } stringtable;
00043
00044
00045
00046
00047
00048 typedef struct CallInfo {
00049 StkId base;
00050 StkId func;
00051 StkId top;
00052 const Instruction *savedpc;
00053 int nresults;
00054 int tailcalls;
00055 } CallInfo;
00056
00057
00058
00059 #define curr_func(L) (clvalue(L->ci->func))
00060 #define ci_func(ci) (clvalue((ci)->func))
00061 #define f_isLua(ci) (!ci_func(ci)->c.isC)
00062 #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
00063
00064
00065
00066
00067
00068 typedef struct global_State {
00069 stringtable strt;
00070 lua_Alloc frealloc;
00071 void *ud;
00072 lu_byte currentwhite;
00073 lu_byte gcstate;
00074 int sweepstrgc;
00075 GCObject *rootgc;
00076 GCObject **sweepgc;
00077 GCObject *gray;
00078 GCObject *grayagain;
00079 GCObject *weak;
00080 GCObject *tmudata;
00081 Mbuffer buff;
00082 lu_mem GCthreshold;
00083 lu_mem totalbytes;
00084 lu_mem estimate;
00085 lu_mem gcdept;
00086 int gcpause;
00087 int gcstepmul;
00088 lua_CFunction panic;
00089 TValue l_registry;
00090 struct lua_State *mainthread;
00091 UpVal uvhead;
00092 struct Table *mt[NUM_TAGS];
00093 TString *tmname[TM_N];
00094 } global_State;
00095
00096
00097
00098
00099
00100 struct lua_State {
00101 CommonHeader;
00102 lu_byte status;
00103 StkId top;
00104 StkId base;
00105 global_State *l_G;
00106 CallInfo *ci;
00107 const Instruction *savedpc;
00108 StkId stack_last;
00109 StkId stack;
00110 CallInfo *end_ci;
00111 CallInfo *base_ci;
00112 int stacksize;
00113 int size_ci;
00114 unsigned short nCcalls;
00115 unsigned short baseCcalls;
00116 lu_byte hookmask;
00117 lu_byte allowhook;
00118 int basehookcount;
00119 int hookcount;
00120 lua_Hook hook;
00121 TValue l_gt;
00122 TValue env;
00123 GCObject *openupval;
00124 GCObject *gclist;
00125 struct lua_longjmp *errorJmp;
00126 ptrdiff_t errfunc;
00127 };
00128
00129
00130 #define G(L) (L->l_G)
00131
00132
00133
00134
00135
00136 union GCObject {
00137 GCheader gch;
00138 union TString ts;
00139 union Udata u;
00140 union Closure cl;
00141 struct Table h;
00142 struct Proto p;
00143 struct UpVal uv;
00144 struct lua_State th;
00145 };
00146
00147
00148
00149 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
00150 #define gco2ts(o) (&rawgco2ts(o)->tsv)
00151 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
00152 #define gco2u(o) (&rawgco2u(o)->uv)
00153 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
00154 #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
00155 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
00156 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
00157 #define ngcotouv(o) \
00158 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
00159 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
00160
00161
00162 #define obj2gco(v) (cast(GCObject *, (v)))
00163
00164
00165 LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
00166 LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
00167
00168 #endif