From fb8fa661366e15e98c60d8929feaab9e551a02f9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 1 Jun 2018 13:51:34 -0300 Subject: no more 'luaH_emptyobject' and comparisons of addresses of global variables (instead, use a different kind of nil to signal the fake entry returned when a key is not found in a table) --- lobject.h | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'lobject.h') diff --git a/lobject.h b/lobject.h index dc5f32a1..a7b4318f 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.141 2018/02/26 14:16:05 roberto Exp roberto $ +** $Id: lobject.h,v 2.142 2018/04/04 14:23:41 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -137,7 +137,12 @@ typedef StackValue *StkId; /* index to stack elements */ ** =================================================================== */ -#define ttisnil(o) checktag((o), LUA_TNIL) +/* macro to test for (any kind of) nil */ +#define ttisnil(v) checktype((v), LUA_TNIL) + +/* macro to test for a "pure" nil */ +#define ttisstrictnil(o) checktag((o), LUA_TNIL) + /* macro defining a nil value */ #define NILCONSTANT {NULL}, LUA_TNIL @@ -155,17 +160,32 @@ typedef StackValue *StkId; /* index to stack elements */ */ #define LUA_TEMPTY (LUA_TNIL | (1 << 4)) -#define ttisnilorempty(v) checktype((v), LUA_TNIL) +/* +** Variant used only in the value returned for a key not found in a +** table (absent key). +*/ +#define LUA_TABSTKEY (LUA_TNIL | (2 << 4)) + -#define isreallyempty(v) checktag((v), LUA_TEMPTY) +#define isabstkey(v) checktag((v), LUA_TABSTKEY) -/* By default, entries with any kind of nil are considered empty */ -#define isempty(v) ttisnilorempty(v) +/* +** macro to detect non-standard nils (used only in assertions) +*/ +#define isreallyempty(v) (ttisnil(v) && !ttisstrictnil(v)) + + +/* +** By default, entries with any kind of nil are considered empty. +** (In any definition, values associated with absent keys must also +** be accepted as empty.) +*/ +#define isempty(v) ttisnil(v) -/* macro defining an empty value */ -#define EMPTYCONSTANT {NULL}, LUA_TEMPTY +/* macro defining a value corresponding to an absent key */ +#define ABSTKEYCONSTANT {NULL}, LUA_TABSTKEY /* mark an entry as empty */ -- cgit v1.2.3-55-g6feb