From 15321262d359d192b8e7b9a746cf10820d8e453f Mon Sep 17 00:00:00 2001 From: TEDERIs Date: Wed, 14 May 2025 19:08:29 +0700 Subject: [PATCH] Allow std::variant for element pointers (Lua parser) --- .../mods/deathmatch/logic/lua/CLuaFunctionParser.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h index 59e7e92575f..c4f74a3d9c5 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h @@ -320,7 +320,17 @@ struct CLuaFunctionParserBase // Catch all for class pointer types, assume all classes are valid script entities // and can be fetched from a userdata else if constexpr (std::is_pointer_v && std::is_class_v>) - return iArgument == LUA_TUSERDATA || iArgument == LUA_TLIGHTUSERDATA; + { + if (iArgument != LUA_TUSERDATA && iArgument != LUA_TLIGHTUSERDATA) + return false; + + using class_t = std::remove_pointer_t; + int tempIndex{index}; + void* pValue = lua::PopPrimitive(L, tempIndex); + auto result = iArgument == LUA_TLIGHTUSERDATA ? UserDataCast((class_t*)pValue, L) : + UserDataCast(*reinterpret_cast(pValue), L); + return result != nullptr; + } // dummy type is used as overload extension if one overload has fewer arguments // thus it is only allowed if there are no further args on the Lua side