1 /* $NetBSD: lstate.h,v 1.1.1.2 2012/03/15 00:08:04 alnsn Exp $ */
4 ** $Id: lstate.h,v 1.1.1.2 2012/03/15 00:08:04 alnsn Exp $
6 ** See Copyright Notice in lua.h
20 struct lua_longjmp
; /* defined in ldo.c */
23 /* table of globals */
24 #define gt(L) (&L->l_gt)
27 #define registry(L) (&G(L)->l_registry)
30 /* extra stack space to handle TM calls and some other extras */
34 #define BASIC_CI_SIZE 8
36 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
40 typedef struct stringtable
{
42 lu_int32 nuse
; /* number of elements */
48 ** informations about a call
50 typedef struct CallInfo
{
51 StkId base
; /* base for this function */
52 StkId func
; /* function index in the stack */
53 StkId top
; /* top for this function */
54 const Instruction
*savedpc
;
55 int nresults
; /* expected number of results from this function */
56 int tailcalls
; /* number of tail calls lost under this entry */
61 #define curr_func(L) (clvalue(L->ci->func))
62 #define ci_func(ci) (clvalue((ci)->func))
63 #define f_isLua(ci) (!ci_func(ci)->c.isC)
64 #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
68 ** `global state', shared by all threads of this state
70 typedef struct global_State
{
71 stringtable strt
; /* hash table for strings */
72 lua_Alloc frealloc
; /* function to reallocate memory */
73 void *ud
; /* auxiliary data to `frealloc' */
75 lu_byte gcstate
; /* state of garbage collector */
76 int sweepstrgc
; /* position of sweep in `strt' */
77 GCObject
*rootgc
; /* list of all collectable objects */
78 GCObject
**sweepgc
; /* position of sweep in `rootgc' */
79 GCObject
*gray
; /* list of gray objects */
80 GCObject
*grayagain
; /* list of objects to be traversed atomically */
81 GCObject
*weak
; /* list of weak tables (to be cleared) */
82 GCObject
*tmudata
; /* last element of list of userdata to be GC */
83 Mbuffer buff
; /* temporary buffer for string concatentation */
85 lu_mem totalbytes
; /* number of bytes currently allocated */
86 lu_mem estimate
; /* an estimate of number of bytes actually in use */
87 lu_mem gcdept
; /* how much GC is `behind schedule' */
88 int gcpause
; /* size of pause between successive GCs */
89 int gcstepmul
; /* GC `granularity' */
90 lua_CFunction panic
; /* to be called in unprotected errors */
92 struct lua_State
*mainthread
;
93 UpVal uvhead
; /* head of double-linked list of all open upvalues */
94 struct Table
*mt
[NUM_TAGS
]; /* metatables for basic types */
95 TString
*tmname
[TM_N
]; /* array with tag-method names */
100 ** `per thread' state
105 StkId top
; /* first free slot in the stack */
106 StkId base
; /* base of current function */
108 CallInfo
*ci
; /* call info for current function */
109 const Instruction
*savedpc
; /* `savedpc' of current function */
110 StkId stack_last
; /* last free slot in the stack */
111 StkId stack
; /* stack base */
112 CallInfo
*end_ci
; /* points after end of ci array*/
113 CallInfo
*base_ci
; /* array of CallInfo's */
115 int size_ci
; /* size of array `base_ci' */
116 unsigned short nCcalls
; /* number of nested C calls */
117 unsigned short baseCcalls
; /* nested C calls when resuming coroutine */
123 TValue l_gt
; /* table of globals */
124 TValue env
; /* temporary place for environments */
125 GCObject
*openupval
; /* list of open upvalues in this stack */
127 struct lua_longjmp
*errorJmp
; /* current error recover point */
128 ptrdiff_t errfunc
; /* current error handling function (stack index) */
132 #define G(L) (L->l_G)
136 ** Union of all collectable objects
146 struct lua_State th
; /* thread */
150 /* macros to convert a GCObject into a specific value */
151 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
152 #define gco2ts(o) (&rawgco2ts(o)->tsv)
153 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
154 #define gco2u(o) (&rawgco2u(o)->uv)
155 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
156 #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
157 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
158 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
159 #define ngcotouv(o) \
160 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
161 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
163 /* macro to convert any Lua object into a GCObject */
164 #define obj2gco(v) (cast(GCObject *, (v)))
167 LUAI_FUNC lua_State
*luaE_newthread (lua_State
*L
);
168 LUAI_FUNC
void luaE_freethread (lua_State
*L
, lua_State
*L1
);