aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-03-10 16:12:53 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2025-03-10 16:12:53 +0100
commitcd6169cf3ecaa41a0aec1cfddd98284fa831285c (patch)
treec34359d4874c2ef4a1b106c6d693d59bfe4bce42
parentd290acf78ad4291099ebccdf94d81aa60ce866bb (diff)
downloadlanes-cd6169cf3ecaa41a0aec1cfddd98284fa831285c.tar.gz
lanes-cd6169cf3ecaa41a0aec1cfddd98284fa831285c.tar.bz2
lanes-cd6169cf3ecaa41a0aec1cfddd98284fa831285c.zip
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()
-rw-r--r--src/compat.cpp6
-rw-r--r--src/nameof.cpp7
2 files changed, 6 insertions, 7 deletions
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
120#endif// LUA_VERSION_NUM > 501 120#endif// LUA_VERSION_NUM > 501
121 STACK_CHECK(L_, 1); 121 STACK_CHECK(L_, 1);
122 int const _uvType{ lua_type(L_, -1) }; 122 int const _uvType{ lua_type(L_, -1) };
123 // under Lua 5.2, there is a single uservalue that is either nil or a table. 123 // under Lua 5.2 and 5.3, there is a single uservalue, that can be nil.
124 // If nil, don't transfer it, as it can cause issues when copying to a Keeper state because of nil sentinel conversion 124 // emulate 5.4 behavior by returning LUA_TNONE when that's the case
125 return (LUA_VERSION_NUM == 502 && _uvType == LUA_TNIL) ? LUA_TNONE : _uvType; 125 return (_uvType == LUA_TNIL) ? LUA_TNONE : _uvType;
126} 126}
127 127
128// ################################################################################################# 128// #################################################################################################
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_
60 // decorate the key string with something that tells us the type of the value 60 // decorate the key string with something that tells us the type of the value
61 switch (luaG_type(L_, StackIndex{ -2 })) { 61 switch (luaG_type(L_, StackIndex{ -2 })) {
62 default: 62 default:
63 LUA_ASSERT(L_, false); // there is something wrong if we end up here
63 luaG_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" 64 luaG_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??"
64 break; 65 break;
65 case LuaType::FUNCTION: 66 case LuaType::FUNCTION:
@@ -78,7 +79,6 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_
78 FqnLength const _depth{ lua_rawlen(L_, kFQN) + 1 }; 79 FqnLength const _depth{ lua_rawlen(L_, kFQN) + 1 };
79 lua_rawseti(L_, kFQN, static_cast<int>(_depth)); // L_: o "r" {c} {fqn} ... k v 80 lua_rawseti(L_, kFQN, static_cast<int>(_depth)); // L_: o "r" {c} {fqn} ... k v
80 STACK_CHECK(L_, 0); 81 STACK_CHECK(L_, 0);
81 STACK_CHECK(L_, 0);
82 return _depth; 82 return _depth;
83 }; 83 };
84 84
@@ -114,7 +114,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_
114 114
115 // filter out uninteresting values 115 // filter out uninteresting values
116 auto const _valType{ luaG_type(L_, kIdxTop) }; 116 auto const _valType{ luaG_type(L_, kIdxTop) };
117 if (_valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { 117 if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) {
118 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k 118 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k
119 return _r; 119 return _r;
120 } 120 }
@@ -164,7 +164,6 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_
164 164
165 static constexpr auto _scanUserData = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { 165 static constexpr auto _scanUserData = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength {
166 FqnLength r_{ shortest_ }; 166 FqnLength r_{ shortest_ };
167 FqnLength const _depth{ lua_rawlen(L_, kFQN) + 1 };
168 STACK_GROW(L_, 2); 167 STACK_GROW(L_, 2);
169 STACK_CHECK_START_REL(L_, 0); 168 STACK_CHECK_START_REL(L_, 0);
170 if (lua_getmetatable(L_, kIdxTop)) { // L_: o "r" {c} {fqn} ... U {mt} 169 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_
233 232
234 FqnLength r_; 233 FqnLength r_;
235 // scan location contents 234 // scan location contents
236 switch (luaG_type(L_, kIdxTop)) { // L_: o "r" {c} {fqn} ... <> 235 switch (_typeWhere) { // L_: o "r" {c} {fqn} ... <>
237 default: 236 default:
238 raise_luaL_error(L_, "unexpected error, please investigate"); 237 raise_luaL_error(L_, "unexpected error, please investigate");
239 break; 238 break;