diff options
-rw-r--r-- | lobject.h | 80 |
1 files changed, 47 insertions, 33 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.47 2011/02/28 17:32:10 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.48 2011/04/05 14:24:07 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 | */ |
@@ -30,10 +30,23 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /* | 32 | /* |
33 | ** Variant tag for light C functions (negative to be considered | 33 | ** tags for Tagged Values have the following use of bits: |
34 | ** non collectable by 'iscollectable') | 34 | ** bits 0-3: actual tag (a LUA_T* value) |
35 | ** bit 4: variant bit (for functions, means a light C function) | ||
36 | ** bit 5: whether value is collectable | ||
35 | */ | 37 | */ |
36 | #define LUA_TLCF (~0x0F | LUA_TFUNCTION) | 38 | |
39 | /* Variant tag for light C functions */ | ||
40 | #define BIT_ISVARIANT (1 << 4) | ||
41 | #define LUA_TLCF (LUA_TFUNCTION | BIT_ISVARIANT) | ||
42 | |||
43 | |||
44 | /* Bit mark for collectable types */ | ||
45 | #define BIT_ISCOLLECTABLE (1 << 5) | ||
46 | |||
47 | /* mark a tag as collectable */ | ||
48 | #define ctb(t) ((t) | BIT_ISCOLLECTABLE) | ||
49 | |||
37 | 50 | ||
38 | /* | 51 | /* |
39 | ** Union of all collectable objects | 52 | ** Union of all collectable objects |
@@ -86,31 +99,32 @@ typedef struct lua_TValue { | |||
86 | #define NILCONSTANT {NULL}, LUA_TNIL | 99 | #define NILCONSTANT {NULL}, LUA_TNIL |
87 | 100 | ||
88 | 101 | ||
89 | /* | 102 | /* raw type tag of a TValue */ |
90 | ** type tag of a TValue | 103 | #define rttype(o) ((o)->tt_) |
91 | */ | ||
92 | #define ttype(o) ((o)->tt_) | ||
93 | 104 | ||
105 | /* type tag of a TValue (bits 0-3 for tags + variant bit) */ | ||
106 | #define ttype(o) (rttype(o) & 0x1F) | ||
94 | 107 | ||
95 | /* | 108 | |
96 | ** type tag of a TValue with no variants | 109 | /* type tag of a TValue with no variants (bits 0-3) */ |
97 | */ | 110 | #define ttypenv(o) (rttype(o) & 0x0F) |
98 | #define ttypenv(o) (ttype(o) & 0x0F) | ||
99 | 111 | ||
100 | 112 | ||
101 | /* Macros to test type */ | 113 | /* Macros to test type */ |
102 | #define ttisnil(o) (ttype(o) == LUA_TNIL) | 114 | #define ttisnil(o) (rttype(o) == LUA_TNIL) |
103 | #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) | 115 | #define ttisboolean(o) (rttype(o) == LUA_TBOOLEAN) |
104 | #define ttisstring(o) (ttype(o) == LUA_TSTRING) | 116 | #define ttislightuserdata(o) (rttype(o) == LUA_TLIGHTUSERDATA) |
105 | #define ttistable(o) (ttype(o) == LUA_TTABLE) | 117 | #define ttisnumber(o) (rttype(o) == LUA_TNUMBER) |
106 | #define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION) | 118 | #define ttisstring(o) (rttype(o) == ctb(LUA_TSTRING)) |
107 | #define ttisclosure(o) (ttype(o) == LUA_TFUNCTION) | 119 | #define ttistable(o) (rttype(o) == ctb(LUA_TTABLE)) |
108 | #define ttislcf(o) (ttype(o) == LUA_TLCF) | 120 | #define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION) |
109 | #define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) | 121 | #define ttisclosure(o) (rttype(o) == ctb(LUA_TFUNCTION)) |
110 | #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) | 122 | #define ttislcf(o) (rttype(o) == LUA_TLCF) |
111 | #define ttisthread(o) (ttype(o) == LUA_TTHREAD) | 123 | #define ttisuserdata(o) (rttype(o) == ctb(LUA_TUSERDATA)) |
112 | #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) | 124 | #define ttisthread(o) (rttype(o) == ctb(LUA_TTHREAD)) |
113 | #define ttisdeadkey(o) (ttype(o) == LUA_TDEADKEY) | 125 | #define ttisdeadkey(o) (rttype(o) == ctb(LUA_TDEADKEY)) |
126 | |||
127 | #define ttisequal(o1,o2) (rttype(o1) == rttype(o2)) | ||
114 | 128 | ||
115 | /* Macros to access values */ | 129 | /* Macros to access values */ |
116 | #define gcvalue(o) check_exp(iscollectable(o), (o)->value_.gc) | 130 | #define gcvalue(o) check_exp(iscollectable(o), (o)->value_.gc) |
@@ -129,7 +143,7 @@ typedef struct lua_TValue { | |||
129 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) | 143 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
130 | 144 | ||
131 | 145 | ||
132 | #define iscollectable(o) (ttype(o) >= LUA_TSTRING) | 146 | #define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE) |
133 | 147 | ||
134 | 148 | ||
135 | /* Macros for internal tests */ | 149 | /* Macros for internal tests */ |
@@ -160,39 +174,39 @@ typedef struct lua_TValue { | |||
160 | 174 | ||
161 | #define setgcovalue(L,obj,x) \ | 175 | #define setgcovalue(L,obj,x) \ |
162 | { TValue *io_=(obj); GCObject *i_g=(x); \ | 176 | { TValue *io_=(obj); GCObject *i_g=(x); \ |
163 | io_->value_.gc=i_g; io_->tt_=gch(i_g)->tt; } | 177 | io_->value_.gc=i_g; io_->tt_=ctb(gch(i_g)->tt); } |
164 | 178 | ||
165 | #define setsvalue(L,obj,x) \ | 179 | #define setsvalue(L,obj,x) \ |
166 | { TValue *io_=(obj); \ | 180 | { TValue *io_=(obj); \ |
167 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=LUA_TSTRING; \ | 181 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=ctb(LUA_TSTRING); \ |
168 | checkliveness(G(L),io_); } | 182 | checkliveness(G(L),io_); } |
169 | 183 | ||
170 | #define setuvalue(L,obj,x) \ | 184 | #define setuvalue(L,obj,x) \ |
171 | { TValue *io_=(obj); \ | 185 | { TValue *io_=(obj); \ |
172 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=LUA_TUSERDATA; \ | 186 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=ctb(LUA_TUSERDATA); \ |
173 | checkliveness(G(L),io_); } | 187 | checkliveness(G(L),io_); } |
174 | 188 | ||
175 | #define setthvalue(L,obj,x) \ | 189 | #define setthvalue(L,obj,x) \ |
176 | { TValue *io_=(obj); \ | 190 | { TValue *io_=(obj); \ |
177 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=LUA_TTHREAD; \ | 191 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=ctb(LUA_TTHREAD); \ |
178 | checkliveness(G(L),io_); } | 192 | checkliveness(G(L),io_); } |
179 | 193 | ||
180 | #define setclvalue(L,obj,x) \ | 194 | #define setclvalue(L,obj,x) \ |
181 | { TValue *io_=(obj); \ | 195 | { TValue *io_=(obj); \ |
182 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=LUA_TFUNCTION; \ | 196 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=ctb(LUA_TFUNCTION); \ |
183 | checkliveness(G(L),io_); } | 197 | checkliveness(G(L),io_); } |
184 | 198 | ||
185 | #define sethvalue(L,obj,x) \ | 199 | #define sethvalue(L,obj,x) \ |
186 | { TValue *io_=(obj); \ | 200 | { TValue *io_=(obj); \ |
187 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=LUA_TTABLE; \ | 201 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=ctb(LUA_TTABLE); \ |
188 | checkliveness(G(L),io_); } | 202 | checkliveness(G(L),io_); } |
189 | 203 | ||
190 | #define setptvalue(L,obj,x) \ | 204 | #define setptvalue(L,obj,x) \ |
191 | { TValue *io_=(obj); \ | 205 | { TValue *io_=(obj); \ |
192 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=LUA_TPROTO; \ | 206 | io_->value_.gc=cast(GCObject *, (x)); io_->tt_=ctb(LUA_TPROTO); \ |
193 | checkliveness(G(L),io_); } | 207 | checkliveness(G(L),io_); } |
194 | 208 | ||
195 | #define setdeadvalue(obj) ((obj)->tt_=LUA_TDEADKEY) | 209 | #define setdeadvalue(obj) ((obj)->tt_=ctb(LUA_TDEADKEY)) |
196 | 210 | ||
197 | 211 | ||
198 | 212 | ||