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 #ifndef lua_lock
00028 #define lua_lock(L)     ((void) 0)
00029 #endif
00030 
00031 #ifndef lua_unlock
00032 #define lua_unlock(L)   ((void) 0)
00033 #endif
00034 
00035 
00036 #ifndef lua_userstateopen
00037 #define lua_userstateopen(l)
00038 #endif
00039 
00040 
00041 
00042 struct lua_longjmp;  
00043 
00044 
00045 
00046 #define defaultmeta(L)  (&G(L)->_defaultmeta)
00047 
00048 
00049 #define gt(L)   (&L->_gt)
00050 
00051 
00052 #define registry(L)     (&G(L)->_registry)
00053 
00054 
00055 
00056 #define EXTRA_STACK   5
00057 
00058 
00059 #define BASIC_CI_SIZE           8
00060 
00061 #define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
00062 
00063 
00064 
00065 typedef struct stringtable {
00066 
00067   GCObject **hash;
00068   ls_nstr nuse;  
00069   int size;
00070 } stringtable;
00071 
00072 
00073 
00074 
00075 
00076 typedef struct CallInfo {
00077  
00078   StkId base;  
00079  
00080   StkId top;  
00081   int state;  
00082   union {
00083     struct {  
00084 
00085       const Instruction *savedpc;
00086 
00087       const Instruction **pc;  
00088       int tailcalls;  
00089     } l;
00090     struct {  
00091       int dummy;  
00092     } c;
00093   } u;
00094 } CallInfo;
00095 
00096 
00097 
00098 
00099 
00100 #define CI_C            (1<<0)  
00101 
00102 #define CI_HASFRAME     (1<<1)
00103 
00104 
00105 #define CI_CALLING      (1<<2)
00106 #define CI_SAVEDPC      (1<<3)  
00107 #define CI_YIELD        (1<<4)  
00108 
00109 
00110 #define ci_func(ci)     (clvalue((ci)->base - 1))
00111 
00112 
00113 
00114 
00115 
00116 typedef struct global_State {
00117   stringtable strt;  
00118 
00119   GCObject *rootgc;  
00120  
00121   GCObject *rootudata;   
00122  
00123   GCObject *tmudata;  
00124   Mbuffer buff;  
00125   lu_mem GCthreshold;
00126   lu_mem nblocks;  
00127   lua_CFunction panic;  
00128   TObject _registry;
00129   TObject _defaultmeta;
00130   struct lua_State *mainthread;
00131   Node dummynode[1];  
00132   TString *tmname[TM_N];  
00133 } global_State;
00134 
00135 
00136 
00137 
00138 
00139 struct lua_State {
00140   CommonHeader;
00141  
00142   StkId top;  
00143  
00144   StkId base;  
00145 
00146   global_State *l_G;
00147  
00148   CallInfo *ci;  
00149 
00150   StkId stack_last;  
00151  
00152   StkId stack;  
00153   int stacksize;
00154  
00155   CallInfo *end_ci;  
00156  
00157   CallInfo *base_ci;  
00158   unsigned short size_ci;  
00159   unsigned short nCcalls;  
00160   lu_byte hookmask;
00161   lu_byte allowhook;
00162   lu_byte hookinit;
00163   int basehookcount;
00164   int hookcount;
00165 
00166   lua_Hook hook;
00167   TObject _gt;  
00168  
00169   GCObject *openupval;  
00170  
00171   GCObject *gclist;
00172 
00173   struct lua_longjmp *errorJmp;  
00174   ptrdiff_t errfunc;  
00175 };
00176 
00177 
00178 #define G(L)    (L->l_G)
00179 
00180 
00181 
00182 
00183 
00184 union GCObject {
00185   GCheader gch;
00186   union TString ts;
00187   union Udata u;
00188   union Closure cl;
00189   struct Table h;
00190   struct Proto p;
00191   struct UpVal uv;
00192   struct lua_State th;  
00193 };
00194 
00195 
00196 
00197 #define gcotots(o)      check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
00198 #define gcotou(o)       check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
00199 #define gcotocl(o)      check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
00200 #define gcotoh(o)       check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
00201 #define gcotop(o)       check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
00202 #define gcotouv(o)      check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
00203 #define ngcotouv(o) \
00204         check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
00205 #define gcototh(o)      check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
00206 
00207 
00208 #define valtogco(v)     (cast(GCObject *, (v)))
00209 
00210 
00211 
00212 lua_State *luaE_newthread (lua_State *L)
00213         ;
00214 void luaE_freethread (lua_State *L, lua_State *L1)
00215         ;
00216 
00217 #endif
00218