Skip to content

Allow using std::variant with several pointers (Lua parser) #4224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> && std::is_class_v<std::remove_pointer_t<T>>)
return iArgument == LUA_TUSERDATA || iArgument == LUA_TLIGHTUSERDATA;
{
if (iArgument != LUA_TUSERDATA && iArgument != LUA_TLIGHTUSERDATA)
return false;

using class_t = std::remove_pointer_t<T>;
int tempIndex{index};
void* pValue = lua::PopPrimitive<void*>(L, tempIndex);
auto result = iArgument == LUA_TLIGHTUSERDATA ? UserDataCast((class_t*)pValue, L) :
UserDataCast(*reinterpret_cast<class_t**>(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
Expand Down
Loading