Skip to content
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

Fix CVector optional arguments - Follow-up #3896

Merged
merged 15 commits into from
Dec 23, 2024
29 changes: 25 additions & 4 deletions Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ struct CLuaFunctionParserBase
else if constexpr (std::is_same_v<T, CVector2D>)
{
if (lua_isnumber(L, index))
return {PopUnsafe<float>(L, index), PopUnsafe<float>(L, index)};
Dutchman101 marked this conversation as resolved.
Show resolved Hide resolved
{
auto x = PopUnsafe<float>(L, index);
auto y = PopUnsafe<float>(L, index);
return CVector2D(x, y);
}

int iType = lua_type(L, index);
bool isLightUserData = iType == LUA_TLIGHTUSERDATA;
Expand All @@ -561,7 +565,12 @@ struct CLuaFunctionParserBase
else if constexpr (std::is_same_v<T, CVector>)
{
if (lua_isnumber(L, index))
return CVector(PopUnsafe<float>(L, index), PopUnsafe<float>(L, index), PopUnsafe<float>(L, index));
{
auto x = PopUnsafe<float>(L, index);
auto y = PopUnsafe<float>(L, index);
auto z = PopUnsafe<float>(L, index);
return CVector(x, y, z);
}

int iType = lua_type(L, index);
bool isLightUserData = iType == LUA_TLIGHTUSERDATA;
Expand All @@ -584,7 +593,13 @@ struct CLuaFunctionParserBase
else if constexpr (std::is_same_v<T, CVector4D>)
{
if (lua_isnumber(L, index))
return {PopUnsafe<float>(L, index), PopUnsafe<float>(L, index), PopUnsafe<float>(L, index), PopUnsafe<float>(L, index)};
{
auto x = PopUnsafe<float>(L, index);
auto y = PopUnsafe<float>(L, index);
auto z = PopUnsafe<float>(L, index);
auto w = PopUnsafe<float>(L, index);
return CVector4D(x, y, z, w);
}

int iType = lua_type(L, index);
bool isLightUserData = iType == LUA_TLIGHTUSERDATA;
Expand All @@ -606,7 +621,13 @@ struct CLuaFunctionParserBase
{
if (lua_isnumber(L, index))
{
const auto ReadVector = [&] { return CVector(PopUnsafe<float>(L, index), PopUnsafe<float>(L, index), PopUnsafe<float>(L, index)); };
const auto ReadVector = [&]
{
auto x = PopUnsafe<float>(L, index);
auto y = PopUnsafe<float>(L, index);
auto z = PopUnsafe<float>(L, index);
return CVector(x, y, z);
};

CMatrix matrix;

Expand Down
Loading