diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-19 15:39:36 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-19 15:39:36 -0300 |
commit | 0e6229a95333fe33858580a7d4094c841b52a611 (patch) | |
tree | 3888b7710046f10f74d5e0f0639951896e70850c | |
parent | d2ab1aef311d00656bc2542c79e318e2764728fa (diff) | |
download | lua-0e6229a95333fe33858580a7d4094c841b52a611.tar.gz lua-0e6229a95333fe33858580a7d4094c841b52a611.tar.bz2 lua-0e6229a95333fe33858580a7d4094c841b52a611.zip |
use proper macros to convert 'GCObject' to other objects + better
type cheking in 'set*value' macros
-rw-r--r-- | lobject.h | 47 |
1 files changed, 23 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.92 2014/05/15 20:41:27 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.93 2014/05/29 19:30: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 | */ |
@@ -156,17 +156,17 @@ typedef struct lua_TValue TValue; | |||
156 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) | 156 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) |
157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | 157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) |
158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | 158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) |
159 | #define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts) | 159 | #define rawtsvalue(o) check_exp(ttisstring(o), rawgco2ts(val_(o).gc)) |
160 | #define tsvalue(o) (&rawtsvalue(o)->tsv) | 160 | #define tsvalue(o) (&rawtsvalue(o)->tsv) |
161 | #define rawuvalue(o) check_exp(ttisfulluserdata(o), &val_(o).gc->u) | 161 | #define rawuvalue(o) check_exp(ttisfulluserdata(o), rawgco2u(val_(o).gc)) |
162 | #define uvalue(o) (&rawuvalue(o)->uv) | 162 | #define uvalue(o) (&rawuvalue(o)->uv) |
163 | #define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl) | 163 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) |
164 | #define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l) | 164 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) |
165 | #define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c) | 165 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) |
166 | #define fvalue(o) check_exp(ttislcf(o), val_(o).f) | 166 | #define fvalue(o) check_exp(ttislcf(o), val_(o).f) |
167 | #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) | 167 | #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc)) |
168 | #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) | 168 | #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) |
169 | #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) | 169 | #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc)) |
170 | /* a dead value may get the 'gc' field, but cannot access its contents */ | 170 | /* a dead value may get the 'gc' field, but cannot access its contents */ |
171 | #define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc)) | 171 | #define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc)) |
172 | 172 | ||
@@ -205,38 +205,37 @@ typedef struct lua_TValue TValue; | |||
205 | { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } | 205 | { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } |
206 | 206 | ||
207 | #define setgcovalue(L,obj,x) \ | 207 | #define setgcovalue(L,obj,x) \ |
208 | { TValue *io=(obj); GCObject *i_g=(x); \ | 208 | { TValue *io = (obj); GCObject *i_g=(x); \ |
209 | val_(io).gc=i_g; settt_(io, ctb(gch(i_g)->tt)); } | 209 | val_(io).gc = i_g; settt_(io, ctb(gch(i_g)->tt)); } |
210 | 210 | ||
211 | #define setsvalue(L,obj,x) \ | 211 | #define setsvalue(L,obj,x) \ |
212 | { TValue *io=(obj); \ | 212 | { TValue *io = (obj); TString *x_ = (x); \ |
213 | TString *x_ = (x); \ | 213 | val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tsv.tt)); \ |
214 | val_(io).gc=cast(GCObject *, x_); settt_(io, ctb(x_->tsv.tt)); \ | ||
215 | checkliveness(G(L),io); } | 214 | checkliveness(G(L),io); } |
216 | 215 | ||
217 | #define setuvalue(L,obj,x) \ | 216 | #define setuvalue(L,obj,x) \ |
218 | { TValue *io=(obj); \ | 217 | { TValue *io = (obj); Udata *x_ = (x); \ |
219 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TUSERDATA)); \ | 218 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \ |
220 | checkliveness(G(L),io); } | 219 | checkliveness(G(L),io); } |
221 | 220 | ||
222 | #define setthvalue(L,obj,x) \ | 221 | #define setthvalue(L,obj,x) \ |
223 | { TValue *io=(obj); \ | 222 | { TValue *io = (obj); lua_State *x_ = (x); \ |
224 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \ | 223 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \ |
225 | checkliveness(G(L),io); } | 224 | checkliveness(G(L),io); } |
226 | 225 | ||
227 | #define setclLvalue(L,obj,x) \ | 226 | #define setclLvalue(L,obj,x) \ |
228 | { TValue *io=(obj); \ | 227 | { TValue *io = (obj); LClosure *x_ = (x); \ |
229 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TLCL)); \ | 228 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \ |
230 | checkliveness(G(L),io); } | 229 | checkliveness(G(L),io); } |
231 | 230 | ||
232 | #define setclCvalue(L,obj,x) \ | 231 | #define setclCvalue(L,obj,x) \ |
233 | { TValue *io=(obj); \ | 232 | { TValue *io = (obj); CClosure *x_ = (x); \ |
234 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TCCL)); \ | 233 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \ |
235 | checkliveness(G(L),io); } | 234 | checkliveness(G(L),io); } |
236 | 235 | ||
237 | #define sethvalue(L,obj,x) \ | 236 | #define sethvalue(L,obj,x) \ |
238 | { TValue *io=(obj); \ | 237 | { TValue *io = (obj); Table *x_ = (x); \ |
239 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \ | 238 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \ |
240 | checkliveness(G(L),io); } | 239 | checkliveness(G(L),io); } |
241 | 240 | ||
242 | #define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) | 241 | #define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) |
@@ -390,7 +389,7 @@ typedef struct Proto { | |||
390 | int *lineinfo; /* map from opcodes to source lines (debug information) */ | 389 | int *lineinfo; /* map from opcodes to source lines (debug information) */ |
391 | LocVar *locvars; /* information about local variables (debug information) */ | 390 | LocVar *locvars; /* information about local variables (debug information) */ |
392 | Upvaldesc *upvalues; /* upvalue information */ | 391 | Upvaldesc *upvalues; /* upvalue information */ |
393 | union Closure *cache; /* last created closure with this prototype */ | 392 | struct LClosure *cache; /* last created closure with this prototype */ |
394 | TString *source; /* used for debug information */ | 393 | TString *source; /* used for debug information */ |
395 | GCObject *gclist; | 394 | GCObject *gclist; |
396 | } Proto; | 395 | } Proto; |