Skip to content

Commit 9b7444a

Browse files
committed
Fix argument parser not handling noexcept functions
1 parent ba746c3 commit 9b7444a

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

Server/mods/deathmatch/logic/luadefs/CLuaDefs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CLuaDefs
9696
template <auto ReturnOnError, auto T>
9797
static inline int ArgumentParserWarn(lua_State* L)
9898
{
99-
return CLuaFunctionParser<false, ReturnOnError, T>()(L, m_pScriptDebugging);
99+
return CLuaFunctionParser<false, ReturnOnError, remove_noexcept_fn_v<T>>()(L, m_pScriptDebugging);
100100
}
101101

102102
// Special case for overloads
@@ -106,8 +106,8 @@ class CLuaDefs
106106
{
107107
// Pad functions to have the same number of parameters by
108108
// filling both up to the larger number of parameters with dummy_type arguments
109-
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
110-
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
109+
using PaddedFunctionA = pad_func_with_func<remove_noexcept_fn_v<FunctionA>, remove_noexcept_fn_v<FunctionB>>;
110+
using PaddedFunctionB = pad_func_with_func<remove_noexcept_fn_v<FunctionB>, remove_noexcept_fn_v<FunctionA>>;
111111
// Combine functions
112112
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;
113113

@@ -118,7 +118,7 @@ class CLuaDefs
118118
template <auto T>
119119
static inline int ArgumentParser(lua_State* L)
120120
{
121-
return CLuaFunctionParser<true, nullptr, T>()(L, m_pScriptDebugging);
121+
return CLuaFunctionParser<true, nullptr, remove_noexcept_fn_v<T>>()(L, m_pScriptDebugging);
122122
}
123123

124124
// Special case for overloads
@@ -128,8 +128,8 @@ class CLuaDefs
128128
{
129129
// Pad functions to have the same number of parameters by
130130
// filling both up to the larger number of parameters with dummy_type arguments
131-
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
132-
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
131+
using PaddedFunctionA = pad_func_with_func<remove_noexcept_fn_v<FunctionA>, remove_noexcept_fn_v<FunctionB>>;
132+
using PaddedFunctionB = pad_func_with_func<remove_noexcept_fn_v<FunctionB>, remove_noexcept_fn_v<FunctionA>>;
133133
// Combine functions
134134
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;
135135

Shared/sdk/SharedUtil.Template.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,33 @@ struct pad_func_with_func<Func, FuncB>
250250
std::max(sizeof...(Args), sizeof...(ArgsB)) - sizeof...(Args) == 0>::type>
251251
{
252252
};
253+
254+
255+
// Removes noexcept(true) from a function type
256+
template <typename T>
257+
struct remove_noexcept
258+
{
259+
using type = T;
260+
};
261+
template <typename R, typename... P>
262+
struct remove_noexcept<R(P...) noexcept>
263+
{
264+
using type = R(P...);
265+
};
266+
template <typename T>
267+
using remove_noexcept_t = typename remove_noexcept<T>::type;
268+
269+
// Removes noexcept(true) from a function
270+
template <auto T>
271+
struct remove_noexcept_fn
272+
{
273+
constexpr static auto func = T;
274+
};
275+
template <typename Ret, typename... Args, Ret(Func)(Args...) noexcept>
276+
struct remove_noexcept_fn<Func>
277+
{
278+
using func_t = Ret (*)(Args...);
279+
constexpr static func_t func = Func;
280+
};
281+
template <auto Func>
282+
constexpr auto remove_noexcept_fn_v = remove_noexcept_fn<Func>::func;

0 commit comments

Comments
 (0)