Lua 5.1.4: lstate.h


L0001    /*
L0002    ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
L0003    ** Global State
L0004    ** See Copyright Notice in lua.h
L0005    */
L0006    
L0007    #ifndef lstate_h
L0008    #define lstate_h
L0009    
L0010    #include "lua.h"
L0011    
L0012    #include "lobject.h"
L0013    #include "ltm.h"
L0014    #include "lzio.h"
L0015    
L0016    
L0017    
L0018    struct lua_longjmp;  /* defined in ldo.c */
L0019    
L0020    
L0021    /* table of globals */
L0022    #define gt(L)	(&L->l_gt)
L0023    
L0024    /* registry */
L0025    #define registry(L)	(&G(L)->l_registry)
L0026    
L0027    
L0028    /* extra stack space to handle TM calls and some other extras */
L0029    #define EXTRA_STACK   5
L0030    
L0031    
L0032    #define BASIC_CI_SIZE           8
L0033    
L0034    #define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
L0035    
L0036    
L0037    
L0038    typedef struct stringtable {
L0039      GCObject **hash;
L0040      lu_int32 nuse;  /* number of elements */
L0041      int size;
L0042    } stringtable;
L0043    
L0044    
L0045    /*
L0046    ** informations about a call
L0047    */
L0048    typedef struct CallInfo {
L0049      StkId base;  /* base for this function */
L0050      StkId func;  /* function index in the stack */
L0051      StkId	top;  /* top for this function */
L0052      const Instruction *savedpc;
L0053      int nresults;  /* expected number of results from this function */
L0054      int tailcalls;  /* number of tail calls lost under this entry */
L0055    } CallInfo;
L0056    
L0057    
L0058    
L0059    #define curr_func(L)	(clvalue(L->ci->func))
L0060    #define ci_func(ci)	(clvalue((ci)->func))
L0061    #define f_isLua(ci)	(!ci_func(ci)->c.isC)
L0062    #define isLua(ci)	(ttisfunction((ci)->func) && f_isLua(ci))
L0063    
L0064    
L0065    /*
L0066    ** `global state', shared by all threads of this state
L0067    */
L0068    typedef struct global_State {
L0069      stringtable strt;  /* hash table for strings */
L0070      lua_Alloc frealloc;  /* function to reallocate memory */
L0071      void *ud;         /* auxiliary data to `frealloc' */
L0072      lu_byte currentwhite;
L0073      lu_byte gcstate;  /* state of garbage collector */
L0074      int sweepstrgc;  /* position of sweep in `strt' */
L0075      GCObject *rootgc;  /* list of all collectable objects */
L0076      GCObject **sweepgc;  /* position of sweep in `rootgc' */
L0077      GCObject *gray;  /* list of gray objects */
L0078      GCObject *grayagain;  /* list of objects to be traversed atomically */
L0079      GCObject *weak;  /* list of weak tables (to be cleared) */
L0080      GCObject *tmudata;  /* last element of list of userdata to be GC */
L0081      Mbuffer buff;  /* temporary buffer for string concatentation */
L0082      lu_mem GCthreshold;
L0083      lu_mem totalbytes;  /* number of bytes currently allocated */
L0084      lu_mem estimate;  /* an estimate of number of bytes actually in use */
L0085      lu_mem gcdept;  /* how much GC is `behind schedule' */
L0086      int gcpause;  /* size of pause between successive GCs */
L0087      int gcstepmul;  /* GC `granularity' */
L0088      lua_CFunction panic;  /* to be called in unprotected errors */
L0089      TValue l_registry;
L0090      struct lua_State *mainthread;
L0091      UpVal uvhead;  /* head of double-linked list of all open upvalues */
L0092      struct Table *mt[NUM_TAGS];  /* metatables for basic types */
L0093      TString *tmname[TM_N];  /* array with tag-method names */
L0094    } global_State;
L0095    
L0096    
L0097    /*
L0098    ** `per thread' state
L0099    */
L0100    struct lua_State {
L0101      CommonHeader;
L0102      lu_byte status;
L0103      StkId top;  /* first free slot in the stack */
L0104      StkId base;  /* base of current function */
L0105      global_State *l_G;
L0106      CallInfo *ci;  /* call info for current function */
L0107      const Instruction *savedpc;  /* `savedpc' of current function */
L0108      StkId stack_last;  /* last free slot in the stack */
L0109      StkId stack;  /* stack base */
L0110      CallInfo *end_ci;  /* points after end of ci array*/
L0111      CallInfo *base_ci;  /* array of CallInfo's */
L0112      int stacksize;
L0113      int size_ci;  /* size of array `base_ci' */
L0114      unsigned short nCcalls;  /* number of nested C calls */
L0115      unsigned short baseCcalls;  /* nested C calls when resuming coroutine */
L0116      lu_byte hookmask;
L0117      lu_byte allowhook;
L0118      int basehookcount;
L0119      int hookcount;
L0120      lua_Hook hook;
L0121      TValue l_gt;  /* table of globals */
L0122      TValue env;  /* temporary place for environments */
L0123      GCObject *openupval;  /* list of open upvalues in this stack */
L0124      GCObject *gclist;
L0125      struct lua_longjmp *errorJmp;  /* current error recover point */
L0126      ptrdiff_t errfunc;  /* current error handling function (stack index) */
L0127    };
L0128    
L0129    
L0130    #define G(L)	(L->l_G)
L0131    
L0132    
L0133    /*
L0134    ** Union of all collectable objects
L0135    */
L0136    union GCObject {
L0137      GCheader gch;
L0138      union TString ts;
L0139      union Udata u;
L0140      union Closure cl;
L0141      struct Table h;
L0142      struct Proto p;
L0143      struct UpVal uv;
L0144      struct lua_State th;  /* thread */
L0145    };
L0146    
L0147    
L0148    /* macros to convert a GCObject into a specific value */
L0149    #define rawgco2ts(o)	check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
L0150    #define gco2ts(o)	(&rawgco2ts(o)->tsv)
L0151    #define rawgco2u(o)	check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
L0152    #define gco2u(o)	(&rawgco2u(o)->uv)
L0153    #define gco2cl(o)	check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
L0154    #define gco2h(o)	check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
L0155    #define gco2p(o)	check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
L0156    #define gco2uv(o)	check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
L0157    #define ngcotouv(o) \
L0158    	check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
L0159    #define gco2th(o)	check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
L0160    
L0161    /* macro to convert any Lua object into a GCObject */
L0162    #define obj2gco(v)	(cast(GCObject *, (v)))
L0163    
L0164    
L0165    LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
L0166    LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
L0167    
L0168    #endif
L0169    

Generated by pretty.lua