|
native Lua
0.5.0-devel
Lua on the platform you use with the compiler you choose
|
Go to the documentation of this file.
24 #define LUA_TUPVAL LUA_NUMTYPES
25 #define LUA_TPROTO (LUA_NUMTYPES+1)
31 #define LUA_TOTALTYPES (LUA_TPROTO + 2)
42 #define makevariant(t,v) ((t) | ((v) << 4))
63 #define TValuefields Value value_; lu_byte tt_
70 #define val_(o) ((o)->value_)
71 #define valraw(o) (&val_(o))
75 #define rawtt(o) ((o)->tt_)
78 #define novariant(t) ((t) & 0x0F)
81 #define withvariant(t) ((t) & 0x3F)
82 #define ttypetag(o) withvariant(rawtt(o))
85 #define ttype(o) (novariant(rawtt(o)))
89 #define checktag(o,t) (rawtt(o) == (t))
90 #define checktype(o,t) (ttype(o) == (t))
96 #define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt)
103 #define checkliveness(L,obj) \
104 ((void)L, lua_longassert(!iscollectable(obj) || \
105 (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))))
111 #define settt_(o,t) ((o)->tt_=(t))
115 #define setobj(L,obj1,obj2) \
116 { TValue *io1=(obj1); const TValue *io2=(obj2); \
117 io1->value_ = io2->value_; settt_(io1, io2->tt_); \
118 checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); }
126 #define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2))
128 #define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2)
130 #define setobjt2t setobj
132 #define setobj2n setobj
134 #define setobj2t setobj
149 #define s2v(o) (&(o)->val)
160 #define LUA_VNIL makevariant(LUA_TNIL, 0)
163 #define LUA_VEMPTY makevariant(LUA_TNIL, 1)
166 #define LUA_VABSTKEY makevariant(LUA_TNIL, 2)
170 #define ttisnil(v) checktype((v), LUA_TNIL)
174 #define ttisstrictnil(o) checktag((o), LUA_VNIL)
177 #define setnilvalue(obj) settt_(obj, LUA_VNIL)
180 #define isabstkey(v) checktag((v), LUA_VABSTKEY)
186 #define isnonstrictnil(v) (ttisnil(v) && !ttisstrictnil(v))
194 #define isempty(v) ttisnil(v)
198 #define ABSTKEYCONSTANT {NULL}, LUA_VABSTKEY
202 #define setempty(v) settt_(v, LUA_VEMPTY)
216 #define LUA_VFALSE makevariant(LUA_TBOOLEAN, 0)
217 #define LUA_VTRUE makevariant(LUA_TBOOLEAN, 1)
219 #define ttisboolean(o) checktype((o), LUA_TBOOLEAN)
220 #define ttisfalse(o) checktag((o), LUA_VFALSE)
221 #define ttistrue(o) checktag((o), LUA_VTRUE)
224 #define l_isfalse(o) (ttisfalse(o) || ttisnil(o))
227 #define setbfvalue(obj) settt_(obj, LUA_VFALSE)
228 #define setbtvalue(obj) settt_(obj, LUA_VTRUE)
239 #define LUA_VTHREAD makevariant(LUA_TTHREAD, 0)
241 #define ttisthread(o) checktag((o), ctb(LUA_VTHREAD))
243 #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc))
245 #define setthvalue(L,obj,x) \
246 { TValue *io = (obj); lua_State *x_ = (x); \
247 val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTHREAD)); \
248 checkliveness(L,io); }
250 #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t)
265 #define CommonHeader struct GCObject *next; lu_byte tt; lu_byte marked
275 #define BIT_ISCOLLECTABLE (1 << 6)
277 #define iscollectable(o) (rawtt(o) & BIT_ISCOLLECTABLE)
280 #define ctb(t) ((t) | BIT_ISCOLLECTABLE)
282 #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
284 #define gcvalueraw(v) ((v).gc)
286 #define setgcovalue(L,obj,x) \
287 { TValue *io = (obj); GCObject *i_g=(x); \
288 val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }
300 #define LUA_VNUMINT makevariant(LUA_TNUMBER, 0)
301 #define LUA_VNUMFLT makevariant(LUA_TNUMBER, 1)
303 #define ttisnumber(o) checktype((o), LUA_TNUMBER)
304 #define ttisfloat(o) checktag((o), LUA_VNUMFLT)
305 #define ttisinteger(o) checktag((o), LUA_VNUMINT)
307 #define nvalue(o) check_exp(ttisnumber(o), \
308 (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))
309 #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
310 #define ivalue(o) check_exp(ttisinteger(o), val_(o).i)
312 #define fltvalueraw(v) ((v).n)
313 #define ivalueraw(v) ((v).i)
315 #define setfltvalue(obj,x) \
316 { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); }
318 #define chgfltvalue(obj,x) \
319 { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
321 #define setivalue(obj,x) \
322 { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); }
324 #define chgivalue(obj,x) \
325 { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
337 #define LUA_VSHRSTR makevariant(LUA_TSTRING, 0)
338 #define LUA_VLNGSTR makevariant(LUA_TSTRING, 1)
340 #define ttisstring(o) checktype((o), LUA_TSTRING)
341 #define ttisshrstring(o) checktag((o), ctb(LUA_VSHRSTR))
342 #define ttislngstring(o) checktag((o), ctb(LUA_VLNGSTR))
344 #define tsvalueraw(v) (gco2ts((v).gc))
346 #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
348 #define setsvalue(L,obj,x) \
349 { TValue *io = (obj); TString *x_ = (x); \
350 val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
351 checkliveness(L,io); }
354 #define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s)
357 #define setsvalue2n setsvalue
380 #define getstr(ts) ((ts)->contents)
384 #define svalue(o) getstr(tsvalue(o))
387 #define tsslen(s) ((s)->tt == LUA_VSHRSTR ? (s)->shrlen : (s)->u.lnglen)
390 #define vslen(o) tsslen(tsvalue(o))
406 #define LUA_VLIGHTUSERDATA makevariant(LUA_TLIGHTUSERDATA, 0)
408 #define LUA_VUSERDATA makevariant(LUA_TUSERDATA, 0)
410 #define ttislightuserdata(o) checktag((o), LUA_VLIGHTUSERDATA)
411 #define ttisfulluserdata(o) checktag((o), ctb(LUA_VUSERDATA))
413 #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
414 #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc))
416 #define pvalueraw(v) ((v).p)
418 #define setpvalue(obj,x) \
419 { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_VLIGHTUSERDATA); }
421 #define setuvalue(L,obj,x) \
422 { TValue *io = (obj); Udata *x_ = (x); \
423 val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VUSERDATA)); \
424 checkliveness(L,io); }
467 #define udatamemoffset(nuv) \
468 ((nuv) == 0 ? offsetof(Udata0, bindata) \
469 : offsetof(Udata, uv) + (sizeof(UValue) * (nuv)))
472 #define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue))
475 #define sizeudata(nuv,nb) (udatamemoffset(nuv) + (nb))
486 #define LUA_VPROTO makevariant(LUA_TPROTO, 0)
563 #define LUA_VUPVAL makevariant(LUA_TUPVAL, 0)
567 #define LUA_VLCL makevariant(LUA_TFUNCTION, 0)
568 #define LUA_VLCF makevariant(LUA_TFUNCTION, 1)
569 #define LUA_VCCL makevariant(LUA_TFUNCTION, 2)
571 #define ttisfunction(o) checktype(o, LUA_TFUNCTION)
572 #define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_VLCL)
573 #define ttisLclosure(o) checktag((o), ctb(LUA_VLCL))
574 #define ttislcf(o) checktag((o), LUA_VLCF)
575 #define ttisCclosure(o) checktag((o), ctb(LUA_VCCL))
577 #define isLfunction(o) ttisLclosure(o)
579 #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
580 #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc))
581 #define fvalue(o) check_exp(ttislcf(o), val_(o).f)
582 #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc))
584 #define fvalueraw(v) ((v).f)
586 #define setclLvalue(L,obj,x) \
587 { TValue *io = (obj); LClosure *x_ = (x); \
588 val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VLCL)); \
589 checkliveness(L,io); }
591 #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl)
593 #define setfvalue(obj,x) \
594 { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_VLCF); }
596 #define setclCvalue(L,obj,x) \
597 { TValue *io = (obj); CClosure *x_ = (x); \
598 val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VCCL)); \
599 checkliveness(L,io); }
620 #define ClosureHeader \
621 CommonHeader; lu_byte nupvalues; GCObject *gclist
643 #define getproto(o) (clLvalue(o)->p)
654 #define LUA_VTABLE makevariant(LUA_TTABLE, 0)
656 #define ttistable(o) checktag((o), ctb(LUA_VTABLE))
658 #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc))
660 #define sethvalue(L,obj,x) \
661 { TValue *io = (obj); Table *x_ = (x); \
662 val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTABLE)); \
663 checkliveness(L,io); }
665 #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h)
687 #define setnodekey(L,node,obj) \
688 { Node *n_=(node); const TValue *io_=(obj); \
689 n_->u.key_val = io_->value_; n_->u.key_tt = io_->tt_; \
690 checkliveness(L,io_); }
694 #define getnodekey(L,obj,node) \
695 { TValue *io_=(obj); const Node *n_=(node); \
696 io_->value_ = n_->u.key_val; io_->tt_ = n_->u.key_tt; \
697 checkliveness(L,io_); }
707 #define BITRAS (1 << 7)
708 #define isrealasize(t) (!((t)->marked & BITRAS))
709 #define setrealasize(t) ((t)->marked &= cast_byte(~BITRAS))
710 #define setnorealasize(t) ((t)->marked |= BITRAS)
729 #define keytt(node) ((node)->u.key_tt)
730 #define keyval(node) ((node)->u.key_val)
732 #define keyisnil(node) (keytt(node) == LUA_TNIL)
733 #define keyisinteger(node) (keytt(node) == LUA_VNUMINT)
734 #define keyival(node) (keyval(node).i)
735 #define keyisshrstr(node) (keytt(node) == ctb(LUA_VSHRSTR))
736 #define keystrval(node) (gco2ts(keyval(node).gc))
738 #define setnilkey(node) (keytt(node) = LUA_TNIL)
740 #define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE)
742 #define gckey(n) (keyval(n).gc)
743 #define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL)
753 #define setdeadkey(n) (keytt(n) = LUA_TTABLE, gckey(n) = NULL)
762 #define lmod(s,size) \
763 (check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1)))))
766 #define twoto(x) (1<<(x))
767 #define sizenode(t) (twoto((t)->lsizenode))
CommonHeader
Definition: lobject.h:606
Upvaldesc * upvalues
Definition: lobject.h:546
lu_byte kind
Definition: lobject.h:496
lu_byte flags
Definition: lobject.h:715
CommonHeader
Definition: lobject.h:270
signed char ls_byte
Definition: llimits.h:39
Definition: lobject.h:457
#define LUAI_FUNC
Definition: luaconf.h:324
Instruction * code
Definition: lobject.h:544
void * p
Definition: lobject.h:51
int pc
Definition: lobject.h:522
lu_byte key_tt
Definition: lobject.h:678
int sizeabslineinfo
Definition: lobject.h:540
ClosureHeader
Definition: lobject.h:631
lua_Integer i
Definition: lobject.h:53
CommonHeader
Definition: lobject.h:364
struct UpVal * next
Definition: lobject.h:611
TValue val
Definition: lobject.h:141
CommonHeader
Definition: lobject.h:714
LUAI_FUNC int luaO_hexavalue(int c)
Definition: lobject.c:135
TString * varname
Definition: lobject.h:505
native Lua configuration file
int lastlinedefined
Definition: lobject.h:542
lua_CFunction f
Definition: lobject.h:52
struct Proto ** p
Definition: lobject.h:545
LUAI_MAXALIGN
Definition: lobject.h:462
unsigned short nuvalue
Definition: lobject.h:459
lu_byte is_vararg
Definition: lobject.h:532
UValue uv[1]
Definition: lobject.h:444
unsigned short nuvalue
Definition: lobject.h:440
int next
Definition: lobject.h:679
LUA_NUMBER lua_Number
Definition: lua.h:92
TString * name
Definition: lobject.h:493
int sizecode
Definition: lobject.h:536
lu_byte extra
Definition: lobject.h:365
ClosureHeader
Definition: lobject.h:624
Definition: lobject.h:140
TValue i_val
Definition: lobject.h:682
int sizep
Definition: lobject.h:538
union StackValue StackValue
TValue uv
Definition: lobject.h:429
TString * source
Definition: lobject.h:550
CommonHeader
Definition: lobject.h:458
Node * lastfree
Definition: lobject.h:720
LUAI_MAXALIGN
Definition: lobject.h:430
int startpc
Definition: lobject.h:506
lu_byte numparams
Definition: lobject.h:531
int linedefined
Definition: lobject.h:541
lu_byte tbc
Definition: lobject.h:607
Definition: lobject.h:605
size_t len
Definition: lobject.h:441
unsigned int hash
Definition: lobject.h:367
AbsLineInfo * abslineinfo
Definition: lobject.h:548
struct GCObject * gc
Definition: lobject.h:50
GCObject * gclist
Definition: lobject.h:443
struct TString * hnext
Definition: lobject.h:370
lua_Number n
Definition: lobject.h:54
Definition: lobject.h:623
int line
Definition: lobject.h:523
LUAI_FUNC size_t luaO_str2num(const char *s, TValue *o)
Definition: lobject.c:303
LUAI_FUNC void luaO_chunkid(char *out, const char *source, size_t srclen)
Definition: lobject.c:548
Definition: lobject.h:676
Definition: lobject.h:363
Definition: lobject.h:428
LUAI_FUNC void luaO_tostring(lua_State *L, TValue *obj)
Definition: lobject.c:362
LUAI_FUNC const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)
Definition: lobject.c:460
int sizek
Definition: lobject.h:535
unsigned char lu_byte
Definition: llimits.h:38
size_t lnglen
Definition: lobject.h:369
lua_CFunction f
Definition: lobject.h:625
ls_byte * lineinfo
Definition: lobject.h:547
TValue upvalue[1]
Definition: lobject.h:626
GCObject * gclist
Definition: lobject.h:551
char contents[1]
Definition: lobject.h:372
Definition: lobject.h:713
Definition: lobject.h:438
struct Table * metatable
Definition: lobject.h:721
Value key_val
Definition: lobject.h:680
GCObject * gclist
Definition: lobject.h:722
LUA_INTEGER lua_Integer
Definition: lua.h:96
struct Proto * p
Definition: lobject.h:632
struct Upvaldesc Upvaldesc
Definition: lobject.h:521
TValuefields
Definition: lobject.h:677
TValue value
Definition: lobject.h:614
TValue * v
Definition: lobject.h:608
TValue * array
Definition: lobject.h:718
TValue * k
Definition: lobject.h:543
unsigned int alimit
Definition: lobject.h:717
Definition: lobject.h:630
int sizelineinfo
Definition: lobject.h:537
lu_byte maxstacksize
Definition: lobject.h:533
lu_byte instack
Definition: lobject.h:494
CClosure c
Definition: lobject.h:638
int sizeupvalues
Definition: lobject.h:534
l_uint32 Instruction
Definition: llimits.h:188
struct Table * metatable
Definition: lobject.h:461
StackValue * StkId
Definition: lobject.h:146
LUAI_FUNC const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
Definition: lobject.c:530
LUAI_FUNC int luaO_rawarith(lua_State *L, int op, const TValue *p1, const TValue *p2, TValue *res)
Definition: lobject.c:89
Definition: lobject.h:529
CommonHeader
Definition: lobject.h:439
struct UpVal::@3::@4 open
struct AbsLineInfo AbsLineInfo
LUAI_FUNC void luaO_arith(lua_State *L, int op, const TValue *p1, const TValue *p2, StkId res)
Definition: lobject.c:126
Definition: lobject.h:492
lu_byte idx
Definition: lobject.h:495
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:108
Definition: lobject.h:675
lu_byte shrlen
Definition: lobject.h:366
struct Table * metatable
Definition: lobject.h:442
Definition: lobject.h:504
Definition: lobject.h:269
LUAI_FUNC int luaO_ceillog2(unsigned int x)
Definition: lobject.c:35
CommonHeader
Definition: lobject.h:530
struct UpVal ** previous
Definition: lobject.h:612
lu_byte lsizenode
Definition: lobject.h:716
LocVar * locvars
Definition: lobject.h:549
TValuefields
Definition: lobject.h:66
int endpc
Definition: lobject.h:507
LUAI_FUNC int luaO_utf8esc(char *buff, unsigned long x)
Definition: lobject.c:318
int sizelocvars
Definition: lobject.h:539
Definition: lobject.h:637
Node * node
Definition: lobject.h:719
UpVal * upvals[1]
Definition: lobject.h:633
size_t len
Definition: lobject.h:460
LClosure l
Definition: lobject.h:639