|
31 | 31 | #include "../CVehicleManager.h" |
32 | 32 | #include "../CRegistry.h" |
33 | 33 | #include "../CDatabaseManager.h" |
| 34 | +#include <lua/CLuaFunctionParser.h> |
34 | 35 |
|
35 | 36 | // Used by script handlers to verify elements |
36 | 37 | #define SCRIPT_VERIFY_BLIP(blip) (m_pBlipManager->Exists(blip)&&!blip->IsBeingDeleted()) |
@@ -84,4 +85,51 @@ class CLuaDefs |
84 | 85 | static CResourceManager* m_pResourceManager; |
85 | 86 | static CAccessControlListManager* m_pACLManager; |
86 | 87 | static CMainConfig* m_pMainConfig; |
| 88 | + |
| 89 | +protected: |
| 90 | + // Old style: Only warn on failure. This should |
| 91 | + // not be used for new functions. ReturnOnError |
| 92 | + // must be a value to use as result on invalid argument |
| 93 | + template <auto ReturnOnError, auto T> |
| 94 | + static inline int ArgumentParserWarn(lua_State* L) |
| 95 | + { |
| 96 | + return CLuaFunctionParser<false, ReturnOnError, T>()(L, m_pScriptDebugging); |
| 97 | + } |
| 98 | + |
| 99 | + // Special case for overloads |
| 100 | + // This combines multiple functions into one (via CLuaOverloadParser) |
| 101 | + template <auto ReturnOnError, auto FunctionA, auto FunctionB, auto... Functions> |
| 102 | + static inline int ArgumentParserWarn(lua_State* L) |
| 103 | + { |
| 104 | + // Pad functions to have the same number of parameters by |
| 105 | + // filling both up to the larger number of parameters with dummy_type arguments |
| 106 | + using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>; |
| 107 | + using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>; |
| 108 | + // Combine functions |
| 109 | + using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>; |
| 110 | + |
| 111 | + return ArgumentParserWarn<ReturnOnError, Overload::Call, Functions...>(L); |
| 112 | + } |
| 113 | + |
| 114 | + // New style: hard error on usage mistakes |
| 115 | + template <auto T> |
| 116 | + static inline int ArgumentParser(lua_State* L) |
| 117 | + { |
| 118 | + return CLuaFunctionParser<true, nullptr, T>()(L, m_pScriptDebugging); |
| 119 | + } |
| 120 | + |
| 121 | + // Special case for overloads |
| 122 | + // This combines multiple functions into one (via CLuaOverloadParser) |
| 123 | + template <auto FunctionA, auto FunctionB, auto... Functions> |
| 124 | + static inline int ArgumentParser(lua_State* L) |
| 125 | + { |
| 126 | + // Pad functions to have the same number of parameters by |
| 127 | + // filling both up to the larger number of parameters with dummy_type arguments |
| 128 | + using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>; |
| 129 | + using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>; |
| 130 | + // Combine functions |
| 131 | + using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>; |
| 132 | + |
| 133 | + return ArgumentParser<Overload::Call, Functions...>(L); |
| 134 | + } |
87 | 135 | }; |
0 commit comments