summaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h47
1 files changed, 32 insertions, 15 deletions
diff --git a/lobject.h b/lobject.h
index f5941839..daa46472 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.55 2011/05/31 18:24:36 roberto Exp roberto $ 2** $Id: lobject.h,v 2.56 2011/05/31 19:15:01 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -32,17 +32,25 @@
32/* 32/*
33** tags for Tagged Values have the following use of bits: 33** tags for Tagged Values have the following use of bits:
34** bits 0-3: actual tag (a LUA_T* value) 34** bits 0-3: actual tag (a LUA_T* value)
35** bit 4: variant bit (for functions, means a light C function) 35** bits 4-5: variant bits
36** bit 5: whether value is collectable 36** bit 6: whether value is collectable
37*/ 37*/
38 38
39/* Variant tag for light C functions */ 39/*
40#define BIT_ISVARIANT (1 << 4) 40** LUA_TFUNCTION variants:
41#define LUA_TLCF (LUA_TFUNCTION | BIT_ISVARIANT) 41** 0 - Lua function
42** 1 - light C function
43** 2 - regular C function (closure)
44*/
45
46/* Variant tags for functions */
47#define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */
48#define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */
49#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
42 50
43 51
44/* Bit mark for collectable types */ 52/* Bit mark for collectable types */
45#define BIT_ISCOLLECTABLE (1 << 5) 53#define BIT_ISCOLLECTABLE (1 << 6)
46 54
47/* mark a tag as collectable */ 55/* mark a tag as collectable */
48#define ctb(t) ((t) | BIT_ISCOLLECTABLE) 56#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
@@ -106,8 +114,8 @@ typedef struct lua_TValue {
106/* raw type tag of a TValue */ 114/* raw type tag of a TValue */
107#define rttype(o) ((o)->tt_) 115#define rttype(o) ((o)->tt_)
108 116
109/* type tag of a TValue (bits 0-3 for tags + variant bit) */ 117/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
110#define ttype(o) (rttype(o) & 0x1F) 118#define ttype(o) (rttype(o) & 0x3F)
111 119
112 120
113/* type tag of a TValue with no variants (bits 0-3) */ 121/* type tag of a TValue with no variants (bits 0-3) */
@@ -123,7 +131,9 @@ typedef struct lua_TValue {
123#define ttisstring(o) checktag((o), ctb(LUA_TSTRING)) 131#define ttisstring(o) checktag((o), ctb(LUA_TSTRING))
124#define ttistable(o) checktag((o), ctb(LUA_TTABLE)) 132#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
125#define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION) 133#define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION)
126#define ttisclosure(o) checktag((o), ctb(LUA_TFUNCTION)) 134#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
135#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
136#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
127#define ttislcf(o) checktag((o), LUA_TLCF) 137#define ttislcf(o) checktag((o), LUA_TLCF)
128#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA)) 138#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA))
129#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) 139#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
@@ -140,6 +150,8 @@ typedef struct lua_TValue {
140#define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u) 150#define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u)
141#define uvalue(o) (&rawuvalue(o)->uv) 151#define uvalue(o) (&rawuvalue(o)->uv)
142#define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl) 152#define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl)
153#define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l)
154#define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)
143#define fvalue(o) check_exp(ttislcf(o), val_(o).f) 155#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
144#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) 156#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
145#define bvalue(o) check_exp(ttisboolean(o), val_(o).b) 157#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
@@ -152,7 +164,7 @@ typedef struct lua_TValue {
152 164
153 165
154/* Macros for internal tests */ 166/* Macros for internal tests */
155#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) 167#define righttt(obj) (ttypenv(obj) == gcvalue(obj)->gch.tt)
156 168
157#define checkliveness(g,obj) \ 169#define checkliveness(g,obj) \
158 lua_longassert(!iscollectable(obj) || \ 170 lua_longassert(!iscollectable(obj) || \
@@ -197,9 +209,14 @@ typedef struct lua_TValue {
197 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \ 209 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \
198 checkliveness(G(L),io); } 210 checkliveness(G(L),io); }
199 211
200#define setclvalue(L,obj,x) \ 212#define setclLvalue(L,obj,x) \
213 { TValue *io=(obj); \
214 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TLCL)); \
215 checkliveness(G(L),io); }
216
217#define setclCvalue(L,obj,x) \
201 { TValue *io=(obj); \ 218 { TValue *io=(obj); \
202 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TFUNCTION)); \ 219 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TCCL)); \
203 checkliveness(G(L),io); } 220 checkliveness(G(L),io); }
204 221
205#define sethvalue(L,obj,x) \ 222#define sethvalue(L,obj,x) \
@@ -375,9 +392,9 @@ typedef union Closure {
375} Closure; 392} Closure;
376 393
377 394
378#define isLfunction(o) (ttisclosure(o) && !clvalue(o)->c.isC) 395#define isLfunction(o) ttisLclosure(o)
379 396
380#define getproto(o) (clvalue(o)->l.p) 397#define getproto(o) (clLvalue(o)->p)
381 398
382 399
383/* 400/*