Create macro for scriptfunc definitions

Create a macro to make registration easier, by reducing the parameters.
This commit is contained in:
Kawe Mazidjatari 2023-07-19 12:09:42 +02:00
parent e67fcfd1fb
commit f39de84d15
6 changed files with 60 additions and 30 deletions

View File

@ -27,7 +27,7 @@ namespace VScriptCode
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: refreshes the server list // Purpose: refreshes the server list
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
SQRESULT RefreshServerCount(HSQUIRRELVM v) SQRESULT RefreshServerList(HSQUIRRELVM v)
{ {
string serverMessage; // Refresh list. string serverMessage; // Refresh list.
size_t iCount = g_pServerListManager->RefreshServerList(serverMessage); size_t iCount = g_pServerListManager->RefreshServerList(serverMessage);
@ -389,27 +389,27 @@ void Script_RegisterUIFunctions(CSquirrelVM* s)
Script_RegisterCommonAbstractions(s); Script_RegisterCommonAbstractions(s);
Script_RegisterCoreClientFunctions(s); Script_RegisterCoreClientFunctions(s);
s->RegisterFunction("RefreshServerList", "Script_RefreshServerList", "Refreshes the public server list and returns the count", "int", "", &VScriptCode::Client::RefreshServerCount); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, RefreshServerList, "Refreshes the public server list and returns the count", "int", "");
s->RegisterFunction("GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VScriptCode::Client::GetServerCount); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerCount, "Gets the number of public servers", "int", "");
// Functions for retrieving server browser data // Functions for retrieving server browser data
s->RegisterFunction("GetHiddenServerName", "Script_GetHiddenServerName", "Gets hidden server name by token", "string", "string", &VScriptCode::Client::GetHiddenServerName); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetHiddenServerName, "Gets hidden server name by token", "string", "string");
s->RegisterFunction("GetServerName", "Script_GetServerName", "Gets the name of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerName); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerName, "Gets the name of the server at the specified index of the server list", "string", "int");
s->RegisterFunction("GetServerDescription", "Script_GetServerDescription", "Gets the description of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerDescription); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerDescription, "Gets the description of the server at the specified index of the server list", "string", "int");
s->RegisterFunction("GetServerMap", "Script_GetServerMap", "Gets the map of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerMap); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerMap, "Gets the map of the server at the specified index of the server list", "string", "int");
s->RegisterFunction("GetServerPlaylist", "Script_GetServerPlaylist", "Gets the playlist of the server at the specified index of the server list", "string", "int", &VScriptCode::Client::GetServerPlaylist); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerPlaylist, "Gets the playlist of the server at the specified index of the server list", "string", "int");
s->RegisterFunction("GetServerCurrentPlayers", "Script_GetServerCurrentPlayers", "Gets the current player count of the server at the specified index of the server list", "int", "int", &VScriptCode::Client::GetServerCurrentPlayers); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerCurrentPlayers, "Gets the current player count of the server at the specified index of the server list", "int", "int");
s->RegisterFunction("GetServerMaxPlayers", "Script_GetServerMaxPlayers", "Gets the max player count of the server at the specified index of the server list", "int", "int", &VScriptCode::Client::GetServerMaxPlayers); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerMaxPlayers, "Gets the max player count of the server at the specified index of the server list", "int", "int");
// Misc main menu functions // Misc main menu functions
s->RegisterFunction("GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VScriptCode::Client::GetPromoData); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetPromoData, "Gets promo data for specified slot type", "string", "int");
// Functions for connecting to servers // Functions for connecting to servers
s->RegisterFunction("ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VScriptCode::Client::ConnectToServer); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToServer, "Joins server by ip address and encryption key", "void", "string, string");
s->RegisterFunction("ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VScriptCode::Client::ConnectToListedServer); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToListedServer, "Joins listed server by index", "void", "int");
s->RegisterFunction("ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VScriptCode::Client::ConnectToHiddenServer); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToHiddenServer, "Joins hidden server by token", "void", "string");
} }
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
@ -418,5 +418,5 @@ void Script_RegisterUIFunctions(CSquirrelVM* s)
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
void Script_RegisterCoreClientFunctions(CSquirrelVM* s) void Script_RegisterCoreClientFunctions(CSquirrelVM* s)
{ {
s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::Client::IsClientDLL); DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, IsClientDLL, "Returns whether this build is client only", "bool", "");
} }

View File

@ -5,7 +5,7 @@ namespace VScriptCode
{ {
namespace Client namespace Client
{ {
SQRESULT RefreshServerCount(HSQUIRRELVM v); SQRESULT RefreshServerList(HSQUIRRELVM v);
SQRESULT GetServerCount(HSQUIRRELVM v); SQRESULT GetServerCount(HSQUIRRELVM v);
SQRESULT GetHiddenServerName(HSQUIRRELVM v); SQRESULT GetHiddenServerName(HSQUIRRELVM v);
@ -32,4 +32,9 @@ void Script_RegisterClientFunctions(CSquirrelVM* s);
void Script_RegisterUIFunctions(CSquirrelVM* s); void Script_RegisterUIFunctions(CSquirrelVM* s);
void Script_RegisterCoreClientFunctions(CSquirrelVM* s); void Script_RegisterCoreClientFunctions(CSquirrelVM* s);
#define DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
helpString, returnType, parameters, VScriptCode::Client::##functionName); \
#endif // VSCRIPT_CLIENT_H #endif // VSCRIPT_CLIENT_H

View File

@ -206,11 +206,11 @@ void Script_RegisterServerFunctions(CSquirrelVM* s)
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
void Script_RegisterCoreServerFunctions(CSquirrelVM* s) void Script_RegisterCoreServerFunctions(CSquirrelVM* s)
{ {
s->RegisterFunction("IsServerActive", "Script_IsServerActive", "Returns whether the server is active", "bool", "", &VScriptCode::Server::IsServerActive); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, IsServerActive, "Returns whether the server is active", "bool", "");
s->RegisterFunction("IsDedicated", "Script_IsDedicated", "Returns whether this is a dedicated server", "bool", "", &VScriptCode::Server::IsDedicated); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, IsDedicated, "Returns whether this is a dedicated server", "bool", "");
s->RegisterFunction("CreateServer", "Script_CreateServer", "Starts server with the specified settings", "void", "string, string, string, string, int", &VScriptCode::Server::CreateServer); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, CreateServer, "Starts server with the specified settings", "void", "string, string, string, string, int");
s->RegisterFunction("DestroyServer", "Script_DestroyServer", "Shuts the local host game down", "void", "", &VScriptCode::Server::DestroyServer); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, DestroyServer, "Shuts the local host game down", "void", "");
} }
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
@ -219,14 +219,14 @@ void Script_RegisterCoreServerFunctions(CSquirrelVM* s)
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
void Script_RegisterAdminPanelFunctions(CSquirrelVM* s) void Script_RegisterAdminPanelFunctions(CSquirrelVM* s)
{ {
s->RegisterFunction("GetNumHumanPlayers", "Script_GetNumHumanPlayers", "Gets the number of human players on the server", "int", "", &VScriptCode::Server::GetNumHumanPlayers); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, GetNumHumanPlayers, "Gets the number of human players on the server", "int", "");
s->RegisterFunction("GetNumFakeClients", "Script_GetNumFakeClients", "Gets the number of bot players on the server", "int", "", &VScriptCode::Server::GetNumFakeClients); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, GetNumFakeClients, "Gets the number of bot players on the server", "int", "");
s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string", &VScriptCode::Server::KickPlayerByName); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, KickPlayerByName, "Kicks a player from the server by name", "void", "string");
s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string", &VScriptCode::Server::KickPlayerById); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, KickPlayerById, "Kicks a player from the server by handle or nucleus id", "void", "string");
s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::Server::BanPlayerByName); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, BanPlayerByName, "Bans a player from the server by name", "void", "string");
s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string", &VScriptCode::Server::BanPlayerById); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, BanPlayerById, "Bans a player from the server by handle or nucleus id", "void", "string");
s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VScriptCode::Server::UnbanPlayer); DEFINE_SERVER_SCRIPTFUNC_NAMED(s, UnbanPlayer, "Unbans a player from the server by nucleus id or ip address", "void", "string");
} }

View File

@ -26,4 +26,9 @@ void Script_RegisterServerFunctions(CSquirrelVM* s);
void Script_RegisterCoreServerFunctions(CSquirrelVM* s); void Script_RegisterCoreServerFunctions(CSquirrelVM* s);
void Script_RegisterAdminPanelFunctions(CSquirrelVM* s); void Script_RegisterAdminPanelFunctions(CSquirrelVM* s);
#define DEFINE_SERVER_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
helpString, returnType, parameters, VScriptCode::Server::##functionName); \
#endif // VSCRIPT_SERVER_H #endif // VSCRIPT_SERVER_H

View File

@ -26,6 +26,15 @@ namespace VScriptCode
{ {
namespace Shared namespace Shared
{ {
//-----------------------------------------------------------------------------
// Purpose: generic stub for unsupported functions
//-----------------------------------------------------------------------------
SQRESULT StubUnsupported(HSQUIRRELVM v)
{
v_SQVM_RaiseError(v, "This function is not supported on this builds.\n");
return SQ_ERROR;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: expose SDK version to the VScript API // Purpose: expose SDK version to the VScript API
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -83,8 +92,8 @@ namespace VScriptCode
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
void Script_RegisterCommonAbstractions(CSquirrelVM* s) void Script_RegisterCommonAbstractions(CSquirrelVM* s)
{ {
s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::Shared::GetSDKVersion); DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetSDKVersion, "Gets the SDK version as a string", "string", "");
s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::Shared::GetAvailableMaps); DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailableMaps, "Gets an array of all available maps", "array< string >", "");
s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::Shared::GetAvailablePlaylists); DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailablePlaylists, "Gets an array of all available playlists", "array< string >", "");
} }

View File

@ -16,6 +16,7 @@ namespace VScriptCode
{ {
namespace Shared namespace Shared
{ {
SQRESULT StubUnsupported(HSQUIRRELVM v);
SQRESULT GetSDKVersion(HSQUIRRELVM v); SQRESULT GetSDKVersion(HSQUIRRELVM v);
SQRESULT GetAvailableMaps(HSQUIRRELVM v); SQRESULT GetAvailableMaps(HSQUIRRELVM v);
SQRESULT GetAvailablePlaylists(HSQUIRRELVM v); SQRESULT GetAvailablePlaylists(HSQUIRRELVM v);
@ -24,6 +25,16 @@ namespace VScriptCode
void Script_RegisterCommonAbstractions(CSquirrelVM* s); void Script_RegisterCommonAbstractions(CSquirrelVM* s);
#define DEFINE_SCRIPTFUNC_STUBBED(s, functionName, returnType) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
"Stub function; not supported on this build.", #returnType, "", \
&VScriptCode::Shared::StubUnsupported); \
#define DEFINE_SHARED_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
helpString, returnType, parameters, VScriptCode::Shared::##functionName);\
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class VScriptShared : public IDetour class VScriptShared : public IDetour
{ {