From cd6169cf3ecaa41a0aec1cfddd98284fa831285c Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 10 Mar 2025 16:12:53 +0100 Subject: Fix unit tests failing for Lua 5.3 * Fix compatibility function lua_getiuservalue() for Lua 5.3 * Fix handling of nil function upvalues in lanes.nameof() --- src/compat.cpp | 6 +++--- src/nameof.cpp | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/compat.cpp b/src/compat.cpp index c332ddc..7e90142 100644 --- a/src/compat.cpp +++ b/src/compat.cpp @@ -120,9 +120,9 @@ int lua_getiuservalue(lua_State* const L_, StackIndex const idx_, UserValueIndex #endif// LUA_VERSION_NUM > 501 STACK_CHECK(L_, 1); int const _uvType{ lua_type(L_, -1) }; - // under Lua 5.2, there is a single uservalue that is either nil or a table. - // If nil, don't transfer it, as it can cause issues when copying to a Keeper state because of nil sentinel conversion - return (LUA_VERSION_NUM == 502 && _uvType == LUA_TNIL) ? LUA_TNONE : _uvType; + // under Lua 5.2 and 5.3, there is a single uservalue, that can be nil. + // emulate 5.4 behavior by returning LUA_TNONE when that's the case + return (_uvType == LUA_TNIL) ? LUA_TNONE : _uvType; } // ################################################################################################# diff --git a/src/nameof.cpp b/src/nameof.cpp index 938685c..f236f73 100644 --- a/src/nameof.cpp +++ b/src/nameof.cpp @@ -60,6 +60,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ // decorate the key string with something that tells us the type of the value switch (luaG_type(L_, StackIndex{ -2 })) { default: + LUA_ASSERT(L_, false); // there is something wrong if we end up here luaG_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" break; case LuaType::FUNCTION: @@ -78,7 +79,6 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ FqnLength const _depth{ lua_rawlen(L_, kFQN) + 1 }; lua_rawseti(L_, kFQN, static_cast(_depth)); // L_: o "r" {c} {fqn} ... k v STACK_CHECK(L_, 0); - STACK_CHECK(L_, 0); return _depth; }; @@ -114,7 +114,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ // filter out uninteresting values auto const _valType{ luaG_type(L_, kIdxTop) }; - if (_valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { + if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k return _r; } @@ -164,7 +164,6 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ static constexpr auto _scanUserData = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { FqnLength r_{ shortest_ }; - FqnLength const _depth{ lua_rawlen(L_, kFQN) + 1 }; STACK_GROW(L_, 2); STACK_CHECK_START_REL(L_, 0); if (lua_getmetatable(L_, kIdxTop)) { // L_: o "r" {c} {fqn} ... U {mt} @@ -233,7 +232,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ FqnLength r_; // scan location contents - switch (luaG_type(L_, kIdxTop)) { // L_: o "r" {c} {fqn} ... <> + switch (_typeWhere) { // L_: o "r" {c} {fqn} ... <> default: raise_luaL_error(L_, "unexpected error, please investigate"); break; -- cgit v1.2.3-55-g6feb