commit 28f8ed9113d1fb9862a2ebd8673ca6b99f4ed190
parent fd22ccd6d020bca1039626ee0c7de42b237a5686
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 20 Jan 2012 20:46:47 -0200
new macro 'checktype'
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lobject.h b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 2.64 2011/10/31 17:48:22 roberto Exp roberto $
+** $Id: lobject.h,v 2.65 2012/01/20 22:05:50 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -36,6 +36,9 @@
** bit 6: whether value is collectable
*/
+#define VARBITS (3 << 4)
+
+
/*
** LUA_TFUNCTION variants:
** 0 - Lua function
@@ -121,13 +124,14 @@ typedef struct lua_TValue TValue;
/* Macros to test type */
#define checktag(o,t) (rttype(o) == (t))
+#define checktype(o,t) (ttypenv(o) == (t))
#define ttisnumber(o) checktag((o), LUA_TNUMBER)
#define ttisnil(o) checktag((o), LUA_TNIL)
#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
#define ttisstring(o) checktag((o), ctb(LUA_TSTRING))
#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
-#define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION)
+#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
@@ -350,7 +354,9 @@ typedef struct lua_TValue TValue;
*/
#undef checktag
+#undef checktype
#define checktag(o,t) (tt_(o) == tag2tt(t))
+#define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS))
#undef ttisequal
#define ttisequal(o1,o2) \