4 ** See Copyright Notice in lua.h
18 struct lua_longjmp
; /* defined in ldo.c */
21 /* table of globals */
22 #define gt(L) (&L->l_gt)
25 #define registry(L) (&G(L)->l_registry)
28 /* extra stack space to handle TM calls and some other extras */
32 #define BASIC_CI_SIZE 8
34 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
38 typedef struct stringtable
{
40 lu_int32 nuse
; /* number of elements */
46 ** informations about a call
48 typedef struct CallInfo
{
49 StkId base
; /* base for this function */
50 StkId func
; /* function index in the stack */
51 StkId top
; /* top for this function */
52 const Instruction
*savedpc
;
53 int nresults
; /* expected number of results from this function */
54 int tailcalls
; /* number of tail calls lost under this entry */
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))
66 ** `global state', shared by all threads of this state
68 typedef struct global_State
{
69 stringtable strt
; /* hash table for strings */
70 lua_Alloc frealloc
; /* function to reallocate memory */
71 void *ud
; /* auxiliary data to `frealloc' */
73 lu_byte gcstate
; /* state of garbage collector */
74 int sweepstrgc
; /* position of sweep in `strt' */
75 GCObject
*rootgc
; /* list of all collectable objects */
76 GCObject
**sweepgc
; /* position of sweep in `rootgc' */
77 GCObject
*gray
; /* list of gray objects */
78 GCObject
*grayagain
; /* list of objects to be traversed atomically */
79 GCObject
*weak
; /* list of weak tables (to be cleared) */
80 GCObject
*tmudata
; /* last element of list of userdata to be GC */
81 Mbuffer buff
; /* temporary buffer for string concatentation */
83 lu_mem totalbytes
; /* number of bytes currently allocated */
84 lu_mem estimate
; /* an estimate of number of bytes actually in use */
85 lu_mem gcdept
; /* how much GC is `behind schedule' */
86 int gcpause
; /* size of pause between successive GCs */
87 int gcstepmul
; /* GC `granularity' */
88 lua_CFunction panic
; /* to be called in unprotected errors */
90 struct lua_State
*mainthread
;
91 UpVal uvhead
; /* head of double-linked list of all open upvalues */
92 struct Table
*mt
[NUM_TAGS
]; /* metatables for basic types */
93 TString
*tmname
[TM_N
]; /* array with tag-method names */
103 StkId top
; /* first free slot in the stack */
104 StkId base
; /* base of current function */
106 CallInfo
*ci
; /* call info for current function */
107 const Instruction
*savedpc
; /* `savedpc' of current function */
108 StkId stack_last
; /* last free slot in the stack */
109 StkId stack
; /* stack base */
110 CallInfo
*end_ci
; /* points after end of ci array*/
111 CallInfo
*base_ci
; /* array of CallInfo's */
113 int size_ci
; /* size of array `base_ci' */
114 unsigned short nCcalls
; /* number of nested C calls */
115 unsigned short baseCcalls
; /* nested C calls when resuming coroutine */
121 TValue l_gt
; /* table of globals */
122 TValue env
; /* temporary place for environments */
123 GCObject
*openupval
; /* list of open upvalues in this stack */
125 struct lua_longjmp
*errorJmp
; /* current error recover point */
126 ptrdiff_t errfunc
; /* current error handling function (stack index) */
130 #define G(L) (L->l_G)
134 ** Union of all collectable objects
144 struct lua_State th
; /* thread */
148 /* macros to convert a GCObject into a specific value */
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))
161 /* macro to convert any Lua object into a GCObject */
162 #define obj2gco(v) (cast(GCObject *, (v)))
165 LUAI_FUNC lua_State
*luaE_newthread (lua_State
*L
);
166 LUAI_FUNC
void luaE_freethread (lua_State
*L
, lua_State
*L1
);