Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
37c5d05
Initial version of new style Lua argument parsing
sbx320 May 27, 2019
2c6277b
Clean up error handling logic
sbx320 May 30, 2019
2dd5e42
Implement Push for float, unsigned int, double
sbx320 May 31, 2019
f6122e0
Add is_variant<T>
sbx320 May 31, 2019
6034b96
Fix Linux
sbx320 May 31, 2019
0c1bdee
Add error string generation
sbx320 May 31, 2019
66d572b
Added CLuaStackChecker
sbx320 Jun 1, 2019
e7b76f6
Initial version of overload resolution logic
sbx320 Jun 2, 2019
2ed2efb
Full support for overloads
sbx320 Jun 4, 2019
dcf96da
Fix mac build
sbx320 Jun 4, 2019
0f29bb0
Improve code generation by using a common base class
sbx320 Jun 8, 2019
ba8671c
Allow passing the return value for warn-style errors
sbx320 Jun 11, 2019
a32246f
Clarify ArgumentParser
sbx320 Jun 11, 2019
338afa9
Remove CBanManager forward declaration
sbx320 Jun 11, 2019
9a717b4
Add further documentation to templates
sbx320 Jun 11, 2019
38ee1f2
Fix typo
sbx320 Jun 11, 2019
43fa9e6
Fix typo in CLuaOverloadParser.h
sbx320 Jun 12, 2019
037df3d
Move CRemoteCalls.h higher
qaisjp Mar 11, 2020
6e640ab
Move CRemoteCalls.h higher
qaisjp Mar 11, 2020
bb0dedb
Add missing PopPrimitive overload for std::size_t
sbx320 Apr 2, 2020
7f545f7
Fix windows build
sbx320 Apr 3, 2020
6eeaeb3
Improve error messages to include function names
sbx320 Apr 3, 2020
9da3e95
Improve inlining by moving some functions to LuaBasic.h
sbx320 Apr 3, 2020
8d6f6a1
Fix typo
sbx320 Apr 3, 2020
ba6fdc1
Add link to issue tracker when overload resolution fails
sbx320 Apr 5, 2020
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
49 changes: 48 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,51 @@ class CLuaDefs
static CClientDFFManager* m_pDFFManager;
static CClientColModelManager* m_pColModelManager;
static CRegisteredCommands* m_pRegisteredCommands;
};

protected:
// Old style: Only warn on failure. This should
// not be used for new functions. ReturnOnError
// must be a value to use as result on invalid argument
template <auto ReturnOnError, auto T>
static inline int ArgumentParserWarn(lua_State* L)
{
return CLuaFunctionParser<false, ReturnOnError, T>()(L, m_pScriptDebugging);
}

// Special case for overloads
// This combines multiple functions into one (via CLuaOverloadParser)
template <auto ReturnOnError, auto FunctionA, auto FunctionB, auto... Functions>
static inline int ArgumentParserWarn(lua_State* L)
{
// Pad functions to have the same number of parameters by
// filling both up to the larger number of parameters with dummy_type arguments
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
// Combine functions
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;

return ArgumentParserWarn<ReturnOnError, Overload::Call, Functions...>(L);
}

// New style: hard error on usage mistakes
template <auto T>
static inline int ArgumentParser(lua_State* L)
{
return CLuaFunctionParser<true, nullptr, T>()(L, m_pScriptDebugging);
}

// Special case for overloads
// This combines multiple functions into one (via CLuaOverloadParser)
template <auto FunctionA, auto FunctionB, auto... Functions>
static inline int ArgumentParser(lua_State* L)
{
// Pad functions to have the same number of parameters by
// filling both up to the larger number of parameters with dummy_type arguments
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
// Combine functions
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;

return ArgumentParser<Overload::Call, Functions...>(L);
}
};
6 changes: 3 additions & 3 deletions Server/mods/deathmatch/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ struct SAclRequest;
#include "packets/CServerInfoSyncPacket.h"
#include "packets/CDiscordJoinPacket.h"

// has to be included early to prevent "unknown type name 'CRemoteCall'" in CLuaFunctionParser.h
#include "CRemoteCalls.h"

// Lua function definitions
#include "luadefs/CLuaElementDefs.h"
#include "luadefs/CLuaAccountDefs.h"
Expand Down Expand Up @@ -142,9 +145,6 @@ struct SAclRequest;
#include "luadefs/CLuaWaterDefs.h"
#include "luadefs/CLuaWorldDefs.h"

// has to be included before CLuaFunctionParseHelpers to prevent "invalid use of incomplete type �class CRemoteCalls�
#include "CRemoteCalls.h"

// Lua includes
#include "lua/LuaCommon.h"
#include "lua/CLuaMain.h"
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ class CGame;
#include "lua/CLuaManager.h"

#include "CLightsyncManager.h"
#include "CBanManager.h"

// Forward declarations
class ASE;
class CAccessControlListManager;
class CAccountManager;
class CBanManager;
class CBlipManager;
class CClock;
class CColManager;
Expand Down
48 changes: 48 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "../CVehicleManager.h"
#include "../CRegistry.h"
#include "../CDatabaseManager.h"
#include <lua/CLuaFunctionParser.h>

// Used by script handlers to verify elements
#define SCRIPT_VERIFY_BLIP(blip) (m_pBlipManager->Exists(blip)&&!blip->IsBeingDeleted())
Expand Down Expand Up @@ -84,4 +85,51 @@ class CLuaDefs
static CResourceManager* m_pResourceManager;
static CAccessControlListManager* m_pACLManager;
static CMainConfig* m_pMainConfig;

protected:
// Old style: Only warn on failure. This should
// not be used for new functions. ReturnOnError
// must be a value to use as result on invalid argument
template <auto ReturnOnError, auto T>
static inline int ArgumentParserWarn(lua_State* L)
{
return CLuaFunctionParser<false, ReturnOnError, T>()(L, m_pScriptDebugging);
}

// Special case for overloads
// This combines multiple functions into one (via CLuaOverloadParser)
template <auto ReturnOnError, auto FunctionA, auto FunctionB, auto... Functions>
static inline int ArgumentParserWarn(lua_State* L)
{
// Pad functions to have the same number of parameters by
// filling both up to the larger number of parameters with dummy_type arguments
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
// Combine functions
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;

return ArgumentParserWarn<ReturnOnError, Overload::Call, Functions...>(L);
}

// New style: hard error on usage mistakes
template <auto T>
static inline int ArgumentParser(lua_State* L)
{
return CLuaFunctionParser<true, nullptr, T>()(L, m_pScriptDebugging);
}

// Special case for overloads
// This combines multiple functions into one (via CLuaOverloadParser)
template <auto FunctionA, auto FunctionB, auto... Functions>
static inline int ArgumentParser(lua_State* L)
{
// Pad functions to have the same number of parameters by
// filling both up to the larger number of parameters with dummy_type arguments
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
// Combine functions
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;

return ArgumentParser<Overload::Call, Functions...>(L);
}
};
Loading