18e3e3a7aSWarner Losh /* 20495ed39SKyle Evans ** $Id: lobject.h $ 38e3e3a7aSWarner Losh ** Type definitions for Lua objects 48e3e3a7aSWarner Losh ** See Copyright Notice in lua.h 58e3e3a7aSWarner Losh */ 68e3e3a7aSWarner Losh 78e3e3a7aSWarner Losh 88e3e3a7aSWarner Losh #ifndef lobject_h 98e3e3a7aSWarner Losh #define lobject_h 108e3e3a7aSWarner Losh 118e3e3a7aSWarner Losh 128e3e3a7aSWarner Losh #include <stdarg.h> 138e3e3a7aSWarner Losh 148e3e3a7aSWarner Losh 158e3e3a7aSWarner Losh #include "llimits.h" 168e3e3a7aSWarner Losh #include "lua.h" 178e3e3a7aSWarner Losh 188e3e3a7aSWarner Losh 198e3e3a7aSWarner Losh /* 200495ed39SKyle Evans ** Extra types for collectable non-values 218e3e3a7aSWarner Losh */ 220495ed39SKyle Evans #define LUA_TUPVAL LUA_NUMTYPES /* upvalues */ 230495ed39SKyle Evans #define LUA_TPROTO (LUA_NUMTYPES+1) /* function prototypes */ 240495ed39SKyle Evans #define LUA_TDEADKEY (LUA_NUMTYPES+2) /* removed keys in tables */ 250495ed39SKyle Evans 260495ed39SKyle Evans 278e3e3a7aSWarner Losh 288e3e3a7aSWarner Losh /* 290495ed39SKyle Evans ** number of all possible types (including LUA_TNONE but excluding DEADKEY) 308e3e3a7aSWarner Losh */ 310495ed39SKyle Evans #define LUA_TOTALTYPES (LUA_TPROTO + 2) 328e3e3a7aSWarner Losh 338e3e3a7aSWarner Losh 348e3e3a7aSWarner Losh /* 358e3e3a7aSWarner Losh ** tags for Tagged Values have the following use of bits: 360495ed39SKyle Evans ** bits 0-3: actual tag (a LUA_T* constant) 378e3e3a7aSWarner Losh ** bits 4-5: variant bits 388e3e3a7aSWarner Losh ** bit 6: whether value is collectable 398e3e3a7aSWarner Losh */ 408e3e3a7aSWarner Losh 410495ed39SKyle Evans /* add variant bits to a type */ 420495ed39SKyle Evans #define makevariant(t,v) ((t) | ((v) << 4)) 438e3e3a7aSWarner Losh 448e3e3a7aSWarner Losh 458e3e3a7aSWarner Losh 468e3e3a7aSWarner Losh /* 478e3e3a7aSWarner Losh ** Union of all Lua values 488e3e3a7aSWarner Losh */ 498e3e3a7aSWarner Losh typedef union Value { 500495ed39SKyle Evans struct GCObject *gc; /* collectable objects */ 518e3e3a7aSWarner Losh void *p; /* light userdata */ 528e3e3a7aSWarner Losh lua_CFunction f; /* light C functions */ 538e3e3a7aSWarner Losh lua_Integer i; /* integer numbers */ 548e3e3a7aSWarner Losh lua_Number n; /* float numbers */ 55*a9490b81SWarner Losh /* not used, but may avoid warnings for uninitialized value */ 56*a9490b81SWarner Losh lu_byte ub; 578e3e3a7aSWarner Losh } Value; 588e3e3a7aSWarner Losh 598e3e3a7aSWarner Losh 600495ed39SKyle Evans /* 610495ed39SKyle Evans ** Tagged Values. This is the basic representation of values in Lua: 620495ed39SKyle Evans ** an actual value plus a tag with its type. 630495ed39SKyle Evans */ 648e3e3a7aSWarner Losh 650495ed39SKyle Evans #define TValuefields Value value_; lu_byte tt_ 668e3e3a7aSWarner Losh 670495ed39SKyle Evans typedef struct TValue { 688e3e3a7aSWarner Losh TValuefields; 698e3e3a7aSWarner Losh } TValue; 708e3e3a7aSWarner Losh 718e3e3a7aSWarner Losh 728e3e3a7aSWarner Losh #define val_(o) ((o)->value_) 738c784bb8SWarner Losh #define valraw(o) (val_(o)) 748e3e3a7aSWarner Losh 758e3e3a7aSWarner Losh 768e3e3a7aSWarner Losh /* raw type tag of a TValue */ 770495ed39SKyle Evans #define rawtt(o) ((o)->tt_) 788e3e3a7aSWarner Losh 798e3e3a7aSWarner Losh /* tag with no variants (bits 0-3) */ 800495ed39SKyle Evans #define novariant(t) ((t) & 0x0F) 818e3e3a7aSWarner Losh 828e3e3a7aSWarner Losh /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ 830495ed39SKyle Evans #define withvariant(t) ((t) & 0x3F) 840495ed39SKyle Evans #define ttypetag(o) withvariant(rawtt(o)) 858e3e3a7aSWarner Losh 860495ed39SKyle Evans /* type of a TValue */ 870495ed39SKyle Evans #define ttype(o) (novariant(rawtt(o))) 888e3e3a7aSWarner Losh 898e3e3a7aSWarner Losh 908e3e3a7aSWarner Losh /* Macros to test type */ 910495ed39SKyle Evans #define checktag(o,t) (rawtt(o) == (t)) 920495ed39SKyle Evans #define checktype(o,t) (ttype(o) == (t)) 938e3e3a7aSWarner Losh 948e3e3a7aSWarner Losh 958e3e3a7aSWarner Losh /* Macros for internal tests */ 968e3e3a7aSWarner Losh 970495ed39SKyle Evans /* collectable object has the same tag as the original value */ 980495ed39SKyle Evans #define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt) 990495ed39SKyle Evans 1000495ed39SKyle Evans /* 1010495ed39SKyle Evans ** Any value being manipulated by the program either is non 1020495ed39SKyle Evans ** collectable, or the collectable object has the right tag 1030495ed39SKyle Evans ** and it is not dead. The option 'L == NULL' allows other 1040495ed39SKyle Evans ** macros using this one to be used where L is not available. 1050495ed39SKyle Evans */ 1068e3e3a7aSWarner Losh #define checkliveness(L,obj) \ 1070495ed39SKyle Evans ((void)L, lua_longassert(!iscollectable(obj) || \ 1080495ed39SKyle Evans (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))) 1098e3e3a7aSWarner Losh 1108e3e3a7aSWarner Losh 1118e3e3a7aSWarner Losh /* Macros to set values */ 1120495ed39SKyle Evans 1130495ed39SKyle Evans /* set a value's tag */ 1148e3e3a7aSWarner Losh #define settt_(o,t) ((o)->tt_=(t)) 1158e3e3a7aSWarner Losh 1160495ed39SKyle Evans 1178c784bb8SWarner Losh /* main macro to copy values (from 'obj2' to 'obj1') */ 1180495ed39SKyle Evans #define setobj(L,obj1,obj2) \ 1190495ed39SKyle Evans { TValue *io1=(obj1); const TValue *io2=(obj2); \ 1200495ed39SKyle Evans io1->value_ = io2->value_; settt_(io1, io2->tt_); \ 1210495ed39SKyle Evans checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); } 1220495ed39SKyle Evans 1230495ed39SKyle Evans /* 1240495ed39SKyle Evans ** Different types of assignments, according to source and destination. 1250495ed39SKyle Evans ** (They are mostly equal now, but may be different in the future.) 1260495ed39SKyle Evans */ 1270495ed39SKyle Evans 1280495ed39SKyle Evans /* from stack to stack */ 1290495ed39SKyle Evans #define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2)) 1300495ed39SKyle Evans /* to stack (not from same stack) */ 1310495ed39SKyle Evans #define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2) 1320495ed39SKyle Evans /* from table to same table */ 1330495ed39SKyle Evans #define setobjt2t setobj 1340495ed39SKyle Evans /* to new object */ 1350495ed39SKyle Evans #define setobj2n setobj 1360495ed39SKyle Evans /* to table */ 1370495ed39SKyle Evans #define setobj2t setobj 1380495ed39SKyle Evans 1390495ed39SKyle Evans 1400495ed39SKyle Evans /* 1418c784bb8SWarner Losh ** Entries in a Lua stack. Field 'tbclist' forms a list of all 1428c784bb8SWarner Losh ** to-be-closed variables active in this stack. Dummy entries are 1438c784bb8SWarner Losh ** used when the distance between two tbc variables does not fit 1448c784bb8SWarner Losh ** in an unsigned short. They are represented by delta==0, and 1458c784bb8SWarner Losh ** their real delta is always the maximum value that fits in 1468c784bb8SWarner Losh ** that field. 1470495ed39SKyle Evans */ 1480495ed39SKyle Evans typedef union StackValue { 1490495ed39SKyle Evans TValue val; 1508c784bb8SWarner Losh struct { 1518c784bb8SWarner Losh TValuefields; 1528c784bb8SWarner Losh unsigned short delta; 1538c784bb8SWarner Losh } tbclist; 1540495ed39SKyle Evans } StackValue; 1550495ed39SKyle Evans 1560495ed39SKyle Evans 1570495ed39SKyle Evans /* index to stack elements */ 1580495ed39SKyle Evans typedef StackValue *StkId; 1590495ed39SKyle Evans 160*a9490b81SWarner Losh 161*a9490b81SWarner Losh /* 162*a9490b81SWarner Losh ** When reallocating the stack, change all pointers to the stack into 163*a9490b81SWarner Losh ** proper offsets. 164*a9490b81SWarner Losh */ 165*a9490b81SWarner Losh typedef union { 166*a9490b81SWarner Losh StkId p; /* actual pointer */ 167*a9490b81SWarner Losh ptrdiff_t offset; /* used while the stack is being reallocated */ 168*a9490b81SWarner Losh } StkIdRel; 169*a9490b81SWarner Losh 170*a9490b81SWarner Losh 1710495ed39SKyle Evans /* convert a 'StackValue' to a 'TValue' */ 1720495ed39SKyle Evans #define s2v(o) (&(o)->val) 1730495ed39SKyle Evans 1740495ed39SKyle Evans 1750495ed39SKyle Evans 1760495ed39SKyle Evans /* 1770495ed39SKyle Evans ** {================================================================== 1780495ed39SKyle Evans ** Nil 1790495ed39SKyle Evans ** =================================================================== 1800495ed39SKyle Evans */ 1810495ed39SKyle Evans 1820495ed39SKyle Evans /* Standard nil */ 1830495ed39SKyle Evans #define LUA_VNIL makevariant(LUA_TNIL, 0) 1840495ed39SKyle Evans 1850495ed39SKyle Evans /* Empty slot (which might be different from a slot containing nil) */ 1860495ed39SKyle Evans #define LUA_VEMPTY makevariant(LUA_TNIL, 1) 1870495ed39SKyle Evans 1880495ed39SKyle Evans /* Value returned for a key not found in a table (absent key) */ 1890495ed39SKyle Evans #define LUA_VABSTKEY makevariant(LUA_TNIL, 2) 1900495ed39SKyle Evans 1910495ed39SKyle Evans 1920495ed39SKyle Evans /* macro to test for (any kind of) nil */ 1930495ed39SKyle Evans #define ttisnil(v) checktype((v), LUA_TNIL) 1940495ed39SKyle Evans 1950495ed39SKyle Evans 1960495ed39SKyle Evans /* macro to test for a standard nil */ 1970495ed39SKyle Evans #define ttisstrictnil(o) checktag((o), LUA_VNIL) 1980495ed39SKyle Evans 1990495ed39SKyle Evans 2000495ed39SKyle Evans #define setnilvalue(obj) settt_(obj, LUA_VNIL) 2010495ed39SKyle Evans 2020495ed39SKyle Evans 2030495ed39SKyle Evans #define isabstkey(v) checktag((v), LUA_VABSTKEY) 2040495ed39SKyle Evans 2050495ed39SKyle Evans 2060495ed39SKyle Evans /* 2070495ed39SKyle Evans ** macro to detect non-standard nils (used only in assertions) 2080495ed39SKyle Evans */ 2090495ed39SKyle Evans #define isnonstrictnil(v) (ttisnil(v) && !ttisstrictnil(v)) 2100495ed39SKyle Evans 2110495ed39SKyle Evans 2120495ed39SKyle Evans /* 2130495ed39SKyle Evans ** By default, entries with any kind of nil are considered empty. 2140495ed39SKyle Evans ** (In any definition, values associated with absent keys must also 2150495ed39SKyle Evans ** be accepted as empty.) 2160495ed39SKyle Evans */ 2170495ed39SKyle Evans #define isempty(v) ttisnil(v) 2180495ed39SKyle Evans 2190495ed39SKyle Evans 2200495ed39SKyle Evans /* macro defining a value corresponding to an absent key */ 2210495ed39SKyle Evans #define ABSTKEYCONSTANT {NULL}, LUA_VABSTKEY 2220495ed39SKyle Evans 2230495ed39SKyle Evans 2240495ed39SKyle Evans /* mark an entry as empty */ 2250495ed39SKyle Evans #define setempty(v) settt_(v, LUA_VEMPTY) 2260495ed39SKyle Evans 2270495ed39SKyle Evans 2280495ed39SKyle Evans 2290495ed39SKyle Evans /* }================================================================== */ 2300495ed39SKyle Evans 2310495ed39SKyle Evans 2320495ed39SKyle Evans /* 2330495ed39SKyle Evans ** {================================================================== 2340495ed39SKyle Evans ** Booleans 2350495ed39SKyle Evans ** =================================================================== 2360495ed39SKyle Evans */ 2370495ed39SKyle Evans 2380495ed39SKyle Evans 2390495ed39SKyle Evans #define LUA_VFALSE makevariant(LUA_TBOOLEAN, 0) 2400495ed39SKyle Evans #define LUA_VTRUE makevariant(LUA_TBOOLEAN, 1) 2410495ed39SKyle Evans 2420495ed39SKyle Evans #define ttisboolean(o) checktype((o), LUA_TBOOLEAN) 2430495ed39SKyle Evans #define ttisfalse(o) checktag((o), LUA_VFALSE) 2440495ed39SKyle Evans #define ttistrue(o) checktag((o), LUA_VTRUE) 2450495ed39SKyle Evans 2460495ed39SKyle Evans 2470495ed39SKyle Evans #define l_isfalse(o) (ttisfalse(o) || ttisnil(o)) 2480495ed39SKyle Evans 2490495ed39SKyle Evans 2500495ed39SKyle Evans #define setbfvalue(obj) settt_(obj, LUA_VFALSE) 2510495ed39SKyle Evans #define setbtvalue(obj) settt_(obj, LUA_VTRUE) 2520495ed39SKyle Evans 2530495ed39SKyle Evans /* }================================================================== */ 2540495ed39SKyle Evans 2550495ed39SKyle Evans 2560495ed39SKyle Evans /* 2570495ed39SKyle Evans ** {================================================================== 2580495ed39SKyle Evans ** Threads 2590495ed39SKyle Evans ** =================================================================== 2600495ed39SKyle Evans */ 2610495ed39SKyle Evans 2620495ed39SKyle Evans #define LUA_VTHREAD makevariant(LUA_TTHREAD, 0) 2630495ed39SKyle Evans 2640495ed39SKyle Evans #define ttisthread(o) checktag((o), ctb(LUA_VTHREAD)) 2650495ed39SKyle Evans 2660495ed39SKyle Evans #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc)) 2670495ed39SKyle Evans 2680495ed39SKyle Evans #define setthvalue(L,obj,x) \ 2690495ed39SKyle Evans { TValue *io = (obj); lua_State *x_ = (x); \ 2700495ed39SKyle Evans val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTHREAD)); \ 2710495ed39SKyle Evans checkliveness(L,io); } 2720495ed39SKyle Evans 2730495ed39SKyle Evans #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t) 2740495ed39SKyle Evans 2750495ed39SKyle Evans /* }================================================================== */ 2760495ed39SKyle Evans 2770495ed39SKyle Evans 2780495ed39SKyle Evans /* 2790495ed39SKyle Evans ** {================================================================== 2800495ed39SKyle Evans ** Collectable Objects 2810495ed39SKyle Evans ** =================================================================== 2820495ed39SKyle Evans */ 2830495ed39SKyle Evans 2840495ed39SKyle Evans /* 2850495ed39SKyle Evans ** Common Header for all collectable objects (in macro form, to be 2860495ed39SKyle Evans ** included in other objects) 2870495ed39SKyle Evans */ 2880495ed39SKyle Evans #define CommonHeader struct GCObject *next; lu_byte tt; lu_byte marked 2890495ed39SKyle Evans 2900495ed39SKyle Evans 2910495ed39SKyle Evans /* Common type for all collectable objects */ 2920495ed39SKyle Evans typedef struct GCObject { 2930495ed39SKyle Evans CommonHeader; 2940495ed39SKyle Evans } GCObject; 2950495ed39SKyle Evans 2960495ed39SKyle Evans 2970495ed39SKyle Evans /* Bit mark for collectable types */ 2980495ed39SKyle Evans #define BIT_ISCOLLECTABLE (1 << 6) 2990495ed39SKyle Evans 3000495ed39SKyle Evans #define iscollectable(o) (rawtt(o) & BIT_ISCOLLECTABLE) 3010495ed39SKyle Evans 3020495ed39SKyle Evans /* mark a tag as collectable */ 3030495ed39SKyle Evans #define ctb(t) ((t) | BIT_ISCOLLECTABLE) 3040495ed39SKyle Evans 3050495ed39SKyle Evans #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) 3060495ed39SKyle Evans 3070495ed39SKyle Evans #define gcvalueraw(v) ((v).gc) 3080495ed39SKyle Evans 3090495ed39SKyle Evans #define setgcovalue(L,obj,x) \ 3100495ed39SKyle Evans { TValue *io = (obj); GCObject *i_g=(x); \ 3110495ed39SKyle Evans val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); } 3120495ed39SKyle Evans 3130495ed39SKyle Evans /* }================================================================== */ 3140495ed39SKyle Evans 3150495ed39SKyle Evans 3160495ed39SKyle Evans /* 3170495ed39SKyle Evans ** {================================================================== 3180495ed39SKyle Evans ** Numbers 3190495ed39SKyle Evans ** =================================================================== 3200495ed39SKyle Evans */ 3210495ed39SKyle Evans 3220495ed39SKyle Evans /* Variant tags for numbers */ 3230495ed39SKyle Evans #define LUA_VNUMINT makevariant(LUA_TNUMBER, 0) /* integer numbers */ 3240495ed39SKyle Evans #define LUA_VNUMFLT makevariant(LUA_TNUMBER, 1) /* float numbers */ 3250495ed39SKyle Evans 3260495ed39SKyle Evans #define ttisnumber(o) checktype((o), LUA_TNUMBER) 3270495ed39SKyle Evans #define ttisfloat(o) checktag((o), LUA_VNUMFLT) 3280495ed39SKyle Evans #define ttisinteger(o) checktag((o), LUA_VNUMINT) 3290495ed39SKyle Evans 3300495ed39SKyle Evans #define nvalue(o) check_exp(ttisnumber(o), \ 3310495ed39SKyle Evans (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) 3320495ed39SKyle Evans #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) 3330495ed39SKyle Evans #define ivalue(o) check_exp(ttisinteger(o), val_(o).i) 3340495ed39SKyle Evans 3350495ed39SKyle Evans #define fltvalueraw(v) ((v).n) 3360495ed39SKyle Evans #define ivalueraw(v) ((v).i) 3370495ed39SKyle Evans 3388e3e3a7aSWarner Losh #define setfltvalue(obj,x) \ 3390495ed39SKyle Evans { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); } 3408e3e3a7aSWarner Losh 3418e3e3a7aSWarner Losh #define chgfltvalue(obj,x) \ 3428e3e3a7aSWarner Losh { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } 3438e3e3a7aSWarner Losh 3448e3e3a7aSWarner Losh #define setivalue(obj,x) \ 3450495ed39SKyle Evans { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); } 3468e3e3a7aSWarner Losh 3478e3e3a7aSWarner Losh #define chgivalue(obj,x) \ 3488e3e3a7aSWarner Losh { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); } 3498e3e3a7aSWarner Losh 3500495ed39SKyle Evans /* }================================================================== */ 3518e3e3a7aSWarner Losh 3528e3e3a7aSWarner Losh 3530495ed39SKyle Evans /* 3540495ed39SKyle Evans ** {================================================================== 3550495ed39SKyle Evans ** Strings 3560495ed39SKyle Evans ** =================================================================== 3570495ed39SKyle Evans */ 3588e3e3a7aSWarner Losh 3590495ed39SKyle Evans /* Variant tags for strings */ 3600495ed39SKyle Evans #define LUA_VSHRSTR makevariant(LUA_TSTRING, 0) /* short strings */ 3610495ed39SKyle Evans #define LUA_VLNGSTR makevariant(LUA_TSTRING, 1) /* long strings */ 3628e3e3a7aSWarner Losh 3630495ed39SKyle Evans #define ttisstring(o) checktype((o), LUA_TSTRING) 3640495ed39SKyle Evans #define ttisshrstring(o) checktag((o), ctb(LUA_VSHRSTR)) 3650495ed39SKyle Evans #define ttislngstring(o) checktag((o), ctb(LUA_VLNGSTR)) 3660495ed39SKyle Evans 3670495ed39SKyle Evans #define tsvalueraw(v) (gco2ts((v).gc)) 3680495ed39SKyle Evans 3690495ed39SKyle Evans #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) 3708e3e3a7aSWarner Losh 3718e3e3a7aSWarner Losh #define setsvalue(L,obj,x) \ 3728e3e3a7aSWarner Losh { TValue *io = (obj); TString *x_ = (x); \ 3738e3e3a7aSWarner Losh val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \ 3748e3e3a7aSWarner Losh checkliveness(L,io); } 3758e3e3a7aSWarner Losh 3760495ed39SKyle Evans /* set a string to the stack */ 3770495ed39SKyle Evans #define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s) 3788e3e3a7aSWarner Losh 3790495ed39SKyle Evans /* set a string to a new object */ 3808e3e3a7aSWarner Losh #define setsvalue2n setsvalue 3818e3e3a7aSWarner Losh 3828e3e3a7aSWarner Losh 3838e3e3a7aSWarner Losh /* 3840495ed39SKyle Evans ** Header for a string value. 3858e3e3a7aSWarner Losh */ 3868e3e3a7aSWarner Losh typedef struct TString { 3878e3e3a7aSWarner Losh CommonHeader; 3888e3e3a7aSWarner Losh lu_byte extra; /* reserved words for short strings; "has hash" for longs */ 3898e3e3a7aSWarner Losh lu_byte shrlen; /* length for short strings */ 3908e3e3a7aSWarner Losh unsigned int hash; 3918e3e3a7aSWarner Losh union { 3928e3e3a7aSWarner Losh size_t lnglen; /* length for long strings */ 3938e3e3a7aSWarner Losh struct TString *hnext; /* linked list for hash table */ 3948e3e3a7aSWarner Losh } u; 3950495ed39SKyle Evans char contents[1]; 3968e3e3a7aSWarner Losh } TString; 3978e3e3a7aSWarner Losh 3988e3e3a7aSWarner Losh 3998e3e3a7aSWarner Losh 4008e3e3a7aSWarner Losh /* 4018e3e3a7aSWarner Losh ** Get the actual string (array of bytes) from a 'TString'. 4028e3e3a7aSWarner Losh */ 4030495ed39SKyle Evans #define getstr(ts) ((ts)->contents) 4048e3e3a7aSWarner Losh 4058e3e3a7aSWarner Losh 4068e3e3a7aSWarner Losh /* get the actual string (array of bytes) from a Lua value */ 4078e3e3a7aSWarner Losh #define svalue(o) getstr(tsvalue(o)) 4088e3e3a7aSWarner Losh 4098e3e3a7aSWarner Losh /* get string length from 'TString *s' */ 4100495ed39SKyle Evans #define tsslen(s) ((s)->tt == LUA_VSHRSTR ? (s)->shrlen : (s)->u.lnglen) 4118e3e3a7aSWarner Losh 4128e3e3a7aSWarner Losh /* get string length from 'TValue *o' */ 4138e3e3a7aSWarner Losh #define vslen(o) tsslen(tsvalue(o)) 4148e3e3a7aSWarner Losh 4150495ed39SKyle Evans /* }================================================================== */ 4160495ed39SKyle Evans 4178e3e3a7aSWarner Losh 4188e3e3a7aSWarner Losh /* 4190495ed39SKyle Evans ** {================================================================== 4200495ed39SKyle Evans ** Userdata 4210495ed39SKyle Evans ** =================================================================== 4220495ed39SKyle Evans */ 4230495ed39SKyle Evans 4240495ed39SKyle Evans 4250495ed39SKyle Evans /* 4260495ed39SKyle Evans ** Light userdata should be a variant of userdata, but for compatibility 4270495ed39SKyle Evans ** reasons they are also different types. 4280495ed39SKyle Evans */ 4290495ed39SKyle Evans #define LUA_VLIGHTUSERDATA makevariant(LUA_TLIGHTUSERDATA, 0) 4300495ed39SKyle Evans 4310495ed39SKyle Evans #define LUA_VUSERDATA makevariant(LUA_TUSERDATA, 0) 4320495ed39SKyle Evans 4330495ed39SKyle Evans #define ttislightuserdata(o) checktag((o), LUA_VLIGHTUSERDATA) 4340495ed39SKyle Evans #define ttisfulluserdata(o) checktag((o), ctb(LUA_VUSERDATA)) 4350495ed39SKyle Evans 4360495ed39SKyle Evans #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) 4370495ed39SKyle Evans #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) 4380495ed39SKyle Evans 4390495ed39SKyle Evans #define pvalueraw(v) ((v).p) 4400495ed39SKyle Evans 4410495ed39SKyle Evans #define setpvalue(obj,x) \ 4420495ed39SKyle Evans { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_VLIGHTUSERDATA); } 4430495ed39SKyle Evans 4440495ed39SKyle Evans #define setuvalue(L,obj,x) \ 4450495ed39SKyle Evans { TValue *io = (obj); Udata *x_ = (x); \ 4460495ed39SKyle Evans val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VUSERDATA)); \ 4470495ed39SKyle Evans checkliveness(L,io); } 4480495ed39SKyle Evans 4490495ed39SKyle Evans 4500495ed39SKyle Evans /* Ensures that addresses after this type are always fully aligned. */ 4510495ed39SKyle Evans typedef union UValue { 4520495ed39SKyle Evans TValue uv; 4530495ed39SKyle Evans LUAI_MAXALIGN; /* ensures maximum alignment for udata bytes */ 4540495ed39SKyle Evans } UValue; 4550495ed39SKyle Evans 4560495ed39SKyle Evans 4570495ed39SKyle Evans /* 4580495ed39SKyle Evans ** Header for userdata with user values; 4590495ed39SKyle Evans ** memory area follows the end of this structure. 4608e3e3a7aSWarner Losh */ 4618e3e3a7aSWarner Losh typedef struct Udata { 4628e3e3a7aSWarner Losh CommonHeader; 4630495ed39SKyle Evans unsigned short nuvalue; /* number of user values */ 4648e3e3a7aSWarner Losh size_t len; /* number of bytes */ 4650495ed39SKyle Evans struct Table *metatable; 4660495ed39SKyle Evans GCObject *gclist; 4670495ed39SKyle Evans UValue uv[1]; /* user values */ 4688e3e3a7aSWarner Losh } Udata; 4698e3e3a7aSWarner Losh 4708e3e3a7aSWarner Losh 4718e3e3a7aSWarner Losh /* 4720495ed39SKyle Evans ** Header for userdata with no user values. These userdata do not need 4730495ed39SKyle Evans ** to be gray during GC, and therefore do not need a 'gclist' field. 4740495ed39SKyle Evans ** To simplify, the code always use 'Udata' for both kinds of userdata, 4750495ed39SKyle Evans ** making sure it never accesses 'gclist' on userdata with no user values. 4760495ed39SKyle Evans ** This structure here is used only to compute the correct size for 4770495ed39SKyle Evans ** this representation. (The 'bindata' field in its end ensures correct 4780495ed39SKyle Evans ** alignment for binary data following this header.) 4798e3e3a7aSWarner Losh */ 4800495ed39SKyle Evans typedef struct Udata0 { 4810495ed39SKyle Evans CommonHeader; 4820495ed39SKyle Evans unsigned short nuvalue; /* number of user values */ 4830495ed39SKyle Evans size_t len; /* number of bytes */ 4840495ed39SKyle Evans struct Table *metatable; 4850495ed39SKyle Evans union {LUAI_MAXALIGN;} bindata; 4860495ed39SKyle Evans } Udata0; 4870495ed39SKyle Evans 4880495ed39SKyle Evans 4890495ed39SKyle Evans /* compute the offset of the memory area of a userdata */ 4900495ed39SKyle Evans #define udatamemoffset(nuv) \ 4910495ed39SKyle Evans ((nuv) == 0 ? offsetof(Udata0, bindata) \ 4920495ed39SKyle Evans : offsetof(Udata, uv) + (sizeof(UValue) * (nuv))) 4930495ed39SKyle Evans 4940495ed39SKyle Evans /* get the address of the memory block inside 'Udata' */ 4950495ed39SKyle Evans #define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue)) 4960495ed39SKyle Evans 4970495ed39SKyle Evans /* compute the size of a userdata */ 4980495ed39SKyle Evans #define sizeudata(nuv,nb) (udatamemoffset(nuv) + (nb)) 4990495ed39SKyle Evans 5000495ed39SKyle Evans /* }================================================================== */ 5018e3e3a7aSWarner Losh 5028e3e3a7aSWarner Losh 5038e3e3a7aSWarner Losh /* 5040495ed39SKyle Evans ** {================================================================== 5050495ed39SKyle Evans ** Prototypes 5060495ed39SKyle Evans ** =================================================================== 5078e3e3a7aSWarner Losh */ 5088e3e3a7aSWarner Losh 5090495ed39SKyle Evans #define LUA_VPROTO makevariant(LUA_TPROTO, 0) 5108e3e3a7aSWarner Losh 5118e3e3a7aSWarner Losh 5128e3e3a7aSWarner Losh /* 5138e3e3a7aSWarner Losh ** Description of an upvalue for function prototypes 5148e3e3a7aSWarner Losh */ 5158e3e3a7aSWarner Losh typedef struct Upvaldesc { 5168e3e3a7aSWarner Losh TString *name; /* upvalue name (for debug information) */ 5178e3e3a7aSWarner Losh lu_byte instack; /* whether it is in stack (register) */ 5188e3e3a7aSWarner Losh lu_byte idx; /* index of upvalue (in stack or in outer function's list) */ 5190495ed39SKyle Evans lu_byte kind; /* kind of corresponding variable */ 5208e3e3a7aSWarner Losh } Upvaldesc; 5218e3e3a7aSWarner Losh 5228e3e3a7aSWarner Losh 5238e3e3a7aSWarner Losh /* 5248e3e3a7aSWarner Losh ** Description of a local variable for function prototypes 5258e3e3a7aSWarner Losh ** (used for debug information) 5268e3e3a7aSWarner Losh */ 5278e3e3a7aSWarner Losh typedef struct LocVar { 5288e3e3a7aSWarner Losh TString *varname; 5298e3e3a7aSWarner Losh int startpc; /* first point where variable is active */ 5308e3e3a7aSWarner Losh int endpc; /* first point where variable is dead */ 5318e3e3a7aSWarner Losh } LocVar; 5328e3e3a7aSWarner Losh 5338e3e3a7aSWarner Losh 5348e3e3a7aSWarner Losh /* 5350495ed39SKyle Evans ** Associates the absolute line source for a given instruction ('pc'). 5360495ed39SKyle Evans ** The array 'lineinfo' gives, for each instruction, the difference in 5370495ed39SKyle Evans ** lines from the previous instruction. When that difference does not 5380495ed39SKyle Evans ** fit into a byte, Lua saves the absolute line for that instruction. 5390495ed39SKyle Evans ** (Lua also saves the absolute line periodically, to speed up the 5400495ed39SKyle Evans ** computation of a line number: we can use binary search in the 5410495ed39SKyle Evans ** absolute-line array, but we must traverse the 'lineinfo' array 5420495ed39SKyle Evans ** linearly to compute a line.) 5430495ed39SKyle Evans */ 5440495ed39SKyle Evans typedef struct AbsLineInfo { 5450495ed39SKyle Evans int pc; 5460495ed39SKyle Evans int line; 5470495ed39SKyle Evans } AbsLineInfo; 5480495ed39SKyle Evans 5490495ed39SKyle Evans /* 5508e3e3a7aSWarner Losh ** Function Prototypes 5518e3e3a7aSWarner Losh */ 5528e3e3a7aSWarner Losh typedef struct Proto { 5538e3e3a7aSWarner Losh CommonHeader; 5540495ed39SKyle Evans lu_byte numparams; /* number of fixed (named) parameters */ 5558e3e3a7aSWarner Losh lu_byte is_vararg; 5568e3e3a7aSWarner Losh lu_byte maxstacksize; /* number of registers needed by this function */ 5578e3e3a7aSWarner Losh int sizeupvalues; /* size of 'upvalues' */ 5588e3e3a7aSWarner Losh int sizek; /* size of 'k' */ 5598e3e3a7aSWarner Losh int sizecode; 5608e3e3a7aSWarner Losh int sizelineinfo; 5618e3e3a7aSWarner Losh int sizep; /* size of 'p' */ 5628e3e3a7aSWarner Losh int sizelocvars; 5630495ed39SKyle Evans int sizeabslineinfo; /* size of 'abslineinfo' */ 5648e3e3a7aSWarner Losh int linedefined; /* debug information */ 5658e3e3a7aSWarner Losh int lastlinedefined; /* debug information */ 5668e3e3a7aSWarner Losh TValue *k; /* constants used by the function */ 5678e3e3a7aSWarner Losh Instruction *code; /* opcodes */ 5688e3e3a7aSWarner Losh struct Proto **p; /* functions defined inside the function */ 5698e3e3a7aSWarner Losh Upvaldesc *upvalues; /* upvalue information */ 5700495ed39SKyle Evans ls_byte *lineinfo; /* information about source lines (debug information) */ 5710495ed39SKyle Evans AbsLineInfo *abslineinfo; /* idem */ 5720495ed39SKyle Evans LocVar *locvars; /* information about local variables (debug information) */ 5738e3e3a7aSWarner Losh TString *source; /* used for debug information */ 5748e3e3a7aSWarner Losh GCObject *gclist; 5758e3e3a7aSWarner Losh } Proto; 5768e3e3a7aSWarner Losh 5770495ed39SKyle Evans /* }================================================================== */ 5788e3e3a7aSWarner Losh 5798e3e3a7aSWarner Losh 5808e3e3a7aSWarner Losh /* 5810495ed39SKyle Evans ** {================================================================== 5820495ed39SKyle Evans ** Functions 5830495ed39SKyle Evans ** =================================================================== 5848e3e3a7aSWarner Losh */ 5850495ed39SKyle Evans 5860495ed39SKyle Evans #define LUA_VUPVAL makevariant(LUA_TUPVAL, 0) 5870495ed39SKyle Evans 5880495ed39SKyle Evans 5890495ed39SKyle Evans /* Variant tags for functions */ 5900495ed39SKyle Evans #define LUA_VLCL makevariant(LUA_TFUNCTION, 0) /* Lua closure */ 5910495ed39SKyle Evans #define LUA_VLCF makevariant(LUA_TFUNCTION, 1) /* light C function */ 5920495ed39SKyle Evans #define LUA_VCCL makevariant(LUA_TFUNCTION, 2) /* C closure */ 5930495ed39SKyle Evans 5940495ed39SKyle Evans #define ttisfunction(o) checktype(o, LUA_TFUNCTION) 5950495ed39SKyle Evans #define ttisLclosure(o) checktag((o), ctb(LUA_VLCL)) 5960495ed39SKyle Evans #define ttislcf(o) checktag((o), LUA_VLCF) 5970495ed39SKyle Evans #define ttisCclosure(o) checktag((o), ctb(LUA_VCCL)) 5988c784bb8SWarner Losh #define ttisclosure(o) (ttisLclosure(o) || ttisCclosure(o)) 5998c784bb8SWarner Losh 6000495ed39SKyle Evans 6010495ed39SKyle Evans #define isLfunction(o) ttisLclosure(o) 6020495ed39SKyle Evans 6030495ed39SKyle Evans #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) 6040495ed39SKyle Evans #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) 6050495ed39SKyle Evans #define fvalue(o) check_exp(ttislcf(o), val_(o).f) 6060495ed39SKyle Evans #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) 6070495ed39SKyle Evans 6080495ed39SKyle Evans #define fvalueraw(v) ((v).f) 6090495ed39SKyle Evans 6100495ed39SKyle Evans #define setclLvalue(L,obj,x) \ 6110495ed39SKyle Evans { TValue *io = (obj); LClosure *x_ = (x); \ 6120495ed39SKyle Evans val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VLCL)); \ 6130495ed39SKyle Evans checkliveness(L,io); } 6140495ed39SKyle Evans 6150495ed39SKyle Evans #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl) 6160495ed39SKyle Evans 6170495ed39SKyle Evans #define setfvalue(obj,x) \ 6180495ed39SKyle Evans { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_VLCF); } 6190495ed39SKyle Evans 6200495ed39SKyle Evans #define setclCvalue(L,obj,x) \ 6210495ed39SKyle Evans { TValue *io = (obj); CClosure *x_ = (x); \ 6220495ed39SKyle Evans val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VCCL)); \ 6230495ed39SKyle Evans checkliveness(L,io); } 6248e3e3a7aSWarner Losh 6258e3e3a7aSWarner Losh 6268e3e3a7aSWarner Losh /* 6270495ed39SKyle Evans ** Upvalues for Lua closures 6288e3e3a7aSWarner Losh */ 6290495ed39SKyle Evans typedef struct UpVal { 6300495ed39SKyle Evans CommonHeader; 631*a9490b81SWarner Losh union { 632*a9490b81SWarner Losh TValue *p; /* points to stack or to its own value */ 633*a9490b81SWarner Losh ptrdiff_t offset; /* used while the stack is being reallocated */ 634*a9490b81SWarner Losh } v; 6350495ed39SKyle Evans union { 6360495ed39SKyle Evans struct { /* (when open) */ 6370495ed39SKyle Evans struct UpVal *next; /* linked list */ 6380495ed39SKyle Evans struct UpVal **previous; 6390495ed39SKyle Evans } open; 6400495ed39SKyle Evans TValue value; /* the value (when closed) */ 6410495ed39SKyle Evans } u; 6420495ed39SKyle Evans } UpVal; 6430495ed39SKyle Evans 6440495ed39SKyle Evans 6458e3e3a7aSWarner Losh 6468e3e3a7aSWarner Losh #define ClosureHeader \ 6478e3e3a7aSWarner Losh CommonHeader; lu_byte nupvalues; GCObject *gclist 6488e3e3a7aSWarner Losh 6498e3e3a7aSWarner Losh typedef struct CClosure { 6508e3e3a7aSWarner Losh ClosureHeader; 6518e3e3a7aSWarner Losh lua_CFunction f; 6528e3e3a7aSWarner Losh TValue upvalue[1]; /* list of upvalues */ 6538e3e3a7aSWarner Losh } CClosure; 6548e3e3a7aSWarner Losh 6558e3e3a7aSWarner Losh 6568e3e3a7aSWarner Losh typedef struct LClosure { 6578e3e3a7aSWarner Losh ClosureHeader; 6588e3e3a7aSWarner Losh struct Proto *p; 6598e3e3a7aSWarner Losh UpVal *upvals[1]; /* list of upvalues */ 6608e3e3a7aSWarner Losh } LClosure; 6618e3e3a7aSWarner Losh 6628e3e3a7aSWarner Losh 6638e3e3a7aSWarner Losh typedef union Closure { 6648e3e3a7aSWarner Losh CClosure c; 6658e3e3a7aSWarner Losh LClosure l; 6668e3e3a7aSWarner Losh } Closure; 6678e3e3a7aSWarner Losh 6688e3e3a7aSWarner Losh 6698e3e3a7aSWarner Losh #define getproto(o) (clLvalue(o)->p) 6708e3e3a7aSWarner Losh 6710495ed39SKyle Evans /* }================================================================== */ 6720495ed39SKyle Evans 6738e3e3a7aSWarner Losh 6748e3e3a7aSWarner Losh /* 6750495ed39SKyle Evans ** {================================================================== 6768e3e3a7aSWarner Losh ** Tables 6770495ed39SKyle Evans ** =================================================================== 6788e3e3a7aSWarner Losh */ 6798e3e3a7aSWarner Losh 6800495ed39SKyle Evans #define LUA_VTABLE makevariant(LUA_TTABLE, 0) 6810495ed39SKyle Evans 6820495ed39SKyle Evans #define ttistable(o) checktag((o), ctb(LUA_VTABLE)) 6830495ed39SKyle Evans 6840495ed39SKyle Evans #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc)) 6850495ed39SKyle Evans 6860495ed39SKyle Evans #define sethvalue(L,obj,x) \ 6870495ed39SKyle Evans { TValue *io = (obj); Table *x_ = (x); \ 6880495ed39SKyle Evans val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTABLE)); \ 6890495ed39SKyle Evans checkliveness(L,io); } 6900495ed39SKyle Evans 6910495ed39SKyle Evans #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h) 6928e3e3a7aSWarner Losh 6938e3e3a7aSWarner Losh 6940495ed39SKyle Evans /* 6950495ed39SKyle Evans ** Nodes for Hash tables: A pack of two TValue's (key-value pairs) 6960495ed39SKyle Evans ** plus a 'next' field to link colliding entries. The distribution 6970495ed39SKyle Evans ** of the key's fields ('key_tt' and 'key_val') not forming a proper 6980495ed39SKyle Evans ** 'TValue' allows for a smaller size for 'Node' both in 4-byte 6990495ed39SKyle Evans ** and 8-byte alignments. 7000495ed39SKyle Evans */ 7010495ed39SKyle Evans typedef union Node { 7020495ed39SKyle Evans struct NodeKey { 7030495ed39SKyle Evans TValuefields; /* fields for value */ 7040495ed39SKyle Evans lu_byte key_tt; /* key type */ 7050495ed39SKyle Evans int next; /* for chaining */ 7060495ed39SKyle Evans Value key_val; /* key value */ 7070495ed39SKyle Evans } u; 7080495ed39SKyle Evans TValue i_val; /* direct access to node's value as a proper 'TValue' */ 7098e3e3a7aSWarner Losh } Node; 7108e3e3a7aSWarner Losh 7118e3e3a7aSWarner Losh 7120495ed39SKyle Evans /* copy a value into a key */ 7130495ed39SKyle Evans #define setnodekey(L,node,obj) \ 7140495ed39SKyle Evans { Node *n_=(node); const TValue *io_=(obj); \ 7150495ed39SKyle Evans n_->u.key_val = io_->value_; n_->u.key_tt = io_->tt_; \ 7160495ed39SKyle Evans checkliveness(L,io_); } 7170495ed39SKyle Evans 7180495ed39SKyle Evans 7190495ed39SKyle Evans /* copy a value from a key */ 7200495ed39SKyle Evans #define getnodekey(L,obj,node) \ 7210495ed39SKyle Evans { TValue *io_=(obj); const Node *n_=(node); \ 7220495ed39SKyle Evans io_->value_ = n_->u.key_val; io_->tt_ = n_->u.key_tt; \ 7230495ed39SKyle Evans checkliveness(L,io_); } 7240495ed39SKyle Evans 7250495ed39SKyle Evans 7260495ed39SKyle Evans /* 7270495ed39SKyle Evans ** About 'alimit': if 'isrealasize(t)' is true, then 'alimit' is the 7280495ed39SKyle Evans ** real size of 'array'. Otherwise, the real size of 'array' is the 7290495ed39SKyle Evans ** smallest power of two not smaller than 'alimit' (or zero iff 'alimit' 7300495ed39SKyle Evans ** is zero); 'alimit' is then used as a hint for #t. 7310495ed39SKyle Evans */ 7320495ed39SKyle Evans 7330495ed39SKyle Evans #define BITRAS (1 << 7) 7340495ed39SKyle Evans #define isrealasize(t) (!((t)->flags & BITRAS)) 7350495ed39SKyle Evans #define setrealasize(t) ((t)->flags &= cast_byte(~BITRAS)) 7360495ed39SKyle Evans #define setnorealasize(t) ((t)->flags |= BITRAS) 7370495ed39SKyle Evans 7380495ed39SKyle Evans 7398e3e3a7aSWarner Losh typedef struct Table { 7408e3e3a7aSWarner Losh CommonHeader; 7418e3e3a7aSWarner Losh lu_byte flags; /* 1<<p means tagmethod(p) is not present */ 7428e3e3a7aSWarner Losh lu_byte lsizenode; /* log2 of size of 'node' array */ 7430495ed39SKyle Evans unsigned int alimit; /* "limit" of 'array' array */ 7448e3e3a7aSWarner Losh TValue *array; /* array part */ 7458e3e3a7aSWarner Losh Node *node; 7468e3e3a7aSWarner Losh Node *lastfree; /* any free position is before this position */ 7478e3e3a7aSWarner Losh struct Table *metatable; 7488e3e3a7aSWarner Losh GCObject *gclist; 7498e3e3a7aSWarner Losh } Table; 7508e3e3a7aSWarner Losh 7518e3e3a7aSWarner Losh 7520495ed39SKyle Evans /* 7530495ed39SKyle Evans ** Macros to manipulate keys inserted in nodes 7540495ed39SKyle Evans */ 7550495ed39SKyle Evans #define keytt(node) ((node)->u.key_tt) 7560495ed39SKyle Evans #define keyval(node) ((node)->u.key_val) 7570495ed39SKyle Evans 7580495ed39SKyle Evans #define keyisnil(node) (keytt(node) == LUA_TNIL) 7590495ed39SKyle Evans #define keyisinteger(node) (keytt(node) == LUA_VNUMINT) 7600495ed39SKyle Evans #define keyival(node) (keyval(node).i) 7610495ed39SKyle Evans #define keyisshrstr(node) (keytt(node) == ctb(LUA_VSHRSTR)) 7620495ed39SKyle Evans #define keystrval(node) (gco2ts(keyval(node).gc)) 7630495ed39SKyle Evans 7640495ed39SKyle Evans #define setnilkey(node) (keytt(node) = LUA_TNIL) 7650495ed39SKyle Evans 7660495ed39SKyle Evans #define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE) 7670495ed39SKyle Evans 7680495ed39SKyle Evans #define gckey(n) (keyval(n).gc) 7690495ed39SKyle Evans #define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL) 7700495ed39SKyle Evans 7710495ed39SKyle Evans 7720495ed39SKyle Evans /* 7730495ed39SKyle Evans ** Dead keys in tables have the tag DEADKEY but keep their original 7740495ed39SKyle Evans ** gcvalue. This distinguishes them from regular keys but allows them to 7750495ed39SKyle Evans ** be found when searched in a special way. ('next' needs that to find 7760495ed39SKyle Evans ** keys removed from a table during a traversal.) 7770495ed39SKyle Evans */ 7780495ed39SKyle Evans #define setdeadkey(node) (keytt(node) = LUA_TDEADKEY) 7790495ed39SKyle Evans #define keyisdead(node) (keytt(node) == LUA_TDEADKEY) 7800495ed39SKyle Evans 7810495ed39SKyle Evans /* }================================================================== */ 7820495ed39SKyle Evans 7830495ed39SKyle Evans 7848e3e3a7aSWarner Losh 7858e3e3a7aSWarner Losh /* 7868e3e3a7aSWarner Losh ** 'module' operation for hashing (size is always a power of 2) 7878e3e3a7aSWarner Losh */ 7888e3e3a7aSWarner Losh #define lmod(s,size) \ 7890495ed39SKyle Evans (check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1))))) 7908e3e3a7aSWarner Losh 7918e3e3a7aSWarner Losh 7928e3e3a7aSWarner Losh #define twoto(x) (1<<(x)) 7938e3e3a7aSWarner Losh #define sizenode(t) (twoto((t)->lsizenode)) 7948e3e3a7aSWarner Losh 7958e3e3a7aSWarner Losh 7968e3e3a7aSWarner Losh /* size of buffer for 'luaO_utf8esc' function */ 7978e3e3a7aSWarner Losh #define UTF8BUFFSZ 8 7988e3e3a7aSWarner Losh 7998e3e3a7aSWarner Losh LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); 8008e3e3a7aSWarner Losh LUAI_FUNC int luaO_ceillog2 (unsigned int x); 8010495ed39SKyle Evans LUAI_FUNC int luaO_rawarith (lua_State *L, int op, const TValue *p1, 8028e3e3a7aSWarner Losh const TValue *p2, TValue *res); 8030495ed39SKyle Evans LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, 8040495ed39SKyle Evans const TValue *p2, StkId res); 8058e3e3a7aSWarner Losh LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); 8068e3e3a7aSWarner Losh LUAI_FUNC int luaO_hexavalue (int c); 8070495ed39SKyle Evans LUAI_FUNC void luaO_tostring (lua_State *L, TValue *obj); 8088e3e3a7aSWarner Losh LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, 8098e3e3a7aSWarner Losh va_list argp); 8108e3e3a7aSWarner Losh LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); 8110495ed39SKyle Evans LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen); 8128e3e3a7aSWarner Losh 8138e3e3a7aSWarner Losh 8148e3e3a7aSWarner Losh #endif 8158e3e3a7aSWarner Losh 816