Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69c7139

Browse files
committed
New macro 'makevariant' to codify variant tags
1 parent 5ff408d commit 69c7139

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lobject.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
** bit 6: whether value is collectable
3737
*/
3838

39+
/* add variant bits to a type */
40+
#define makevariant(t,v) ((t) | ((v) << 4))
41+
3942

4043

4144
/*
@@ -165,13 +168,13 @@ typedef StackValue *StkId;
165168
** Variant tag, used only in tables to signal an empty slot
166169
** (which might be different from a slot containing nil)
167170
*/
168-
#define LUA_TEMPTY (LUA_TNIL | (1 << 4))
171+
#define LUA_TEMPTY makevariant(LUA_TNIL, 1)
169172

170173
/*
171174
** Variant used only in the value returned for a key not found in a
172175
** table (absent key).
173176
*/
174-
#define LUA_TABSTKEY (LUA_TNIL | (2 << 4))
177+
#define LUA_TABSTKEY makevariant(LUA_TNIL, 2)
175178

176179

177180
#define isabstkey(v) checktag((v), LUA_TABSTKEY)
@@ -210,8 +213,8 @@ typedef StackValue *StkId;
210213
*/
211214

212215

213-
#define LUA_TFALSE (LUA_TBOOLEAN | (1 << 4))
214-
#define LUA_TTRUE (LUA_TBOOLEAN | (2 << 4))
216+
#define LUA_TFALSE makevariant(LUA_TBOOLEAN, 1)
217+
#define LUA_TTRUE makevariant(LUA_TBOOLEAN, 2)
215218

216219
#define ttisboolean(o) checktype((o), LUA_TBOOLEAN)
217220
#define ttisfalse(o) checktag((o), LUA_TFALSE)
@@ -292,8 +295,8 @@ typedef struct GCObject {
292295
*/
293296

294297
/* Variant tags for numbers */
295-
#define LUA_TNUMFLT (LUA_TNUMBER | (1 << 4)) /* float numbers */
296-
#define LUA_TNUMINT (LUA_TNUMBER | (2 << 4)) /* integer numbers */
298+
#define LUA_TNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */
299+
#define LUA_TNUMFLT makevariant(LUA_TNUMBER, 2) /* float numbers */
297300

298301
#define ttisnumber(o) checktype((o), LUA_TNUMBER)
299302
#define ttisfloat(o) checktag((o), LUA_TNUMFLT)
@@ -329,8 +332,8 @@ typedef struct GCObject {
329332
*/
330333

331334
/* Variant tags for strings */
332-
#define LUA_TSHRSTR (LUA_TSTRING | (1 << 4)) /* short strings */
333-
#define LUA_TLNGSTR (LUA_TSTRING | (2 << 4)) /* long strings */
335+
#define LUA_TSHRSTR makevariant(LUA_TSTRING, 1) /* short strings */
336+
#define LUA_TLNGSTR makevariant(LUA_TSTRING, 2) /* long strings */
334337

335338
#define ttisstring(o) checktype((o), LUA_TSTRING)
336339
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
@@ -546,9 +549,9 @@ typedef struct Proto {
546549
*/
547550

548551
/* Variant tags for functions */
549-
#define LUA_TLCL (LUA_TFUNCTION | (1 << 4)) /* Lua closure */
550-
#define LUA_TLCF (LUA_TFUNCTION | (2 << 4)) /* light C function */
551-
#define LUA_TCCL (LUA_TFUNCTION | (3 << 4)) /* C closure */
552+
#define LUA_TLCL makevariant(LUA_TFUNCTION, 1) /* Lua closure */
553+
#define LUA_TLCF makevariant(LUA_TFUNCTION, 2) /* light C function */
554+
#define LUA_TCCL makevariant(LUA_TFUNCTION, 3) /* C closure */
552555

553556
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
554557
#define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_TLCL)

0 commit comments

Comments
 (0)