new macro 'checktype'

This commit is contained in:
Roberto Ierusalimschy 2012-01-20 20:47:11 -02:00
parent fd22ccd6d0
commit 28f8ed9113

View File

@ -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 ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -36,6 +36,9 @@
** bit 6: whether value is collectable ** bit 6: whether value is collectable
*/ */
#define VARBITS (3 << 4)
/* /*
** LUA_TFUNCTION variants: ** LUA_TFUNCTION variants:
** 0 - Lua function ** 0 - Lua function
@ -121,13 +124,14 @@ typedef struct lua_TValue TValue;
/* Macros to test type */ /* Macros to test type */
#define checktag(o,t) (rttype(o) == (t)) #define checktag(o,t) (rttype(o) == (t))
#define checktype(o,t) (ttypenv(o) == (t))
#define ttisnumber(o) checktag((o), LUA_TNUMBER) #define ttisnumber(o) checktag((o), LUA_TNUMBER)
#define ttisnil(o) checktag((o), LUA_TNIL) #define ttisnil(o) checktag((o), LUA_TNIL)
#define ttisboolean(o) checktag((o), LUA_TBOOLEAN) #define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
#define ttisstring(o) checktag((o), ctb(LUA_TSTRING)) #define ttisstring(o) checktag((o), ctb(LUA_TSTRING))
#define ttistable(o) checktag((o), ctb(LUA_TTABLE)) #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 ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL)) #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
@ -350,7 +354,9 @@ typedef struct lua_TValue TValue;
*/ */
#undef checktag #undef checktag
#undef checktype
#define checktag(o,t) (tt_(o) == tag2tt(t)) #define checktag(o,t) (tt_(o) == tag2tt(t))
#define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS))
#undef ttisequal #undef ttisequal
#define ttisequal(o1,o2) \ #define ttisequal(o1,o2) \