diff --git a/cmake/scripts/SquirrelExport.cmake b/cmake/scripts/SquirrelExport.cmake index 477e2ae782..c1e601e14b 100644 --- a/cmake/scripts/SquirrelExport.cmake +++ b/cmake/scripts/SquirrelExport.cmake @@ -464,8 +464,7 @@ foreach(LINE IN LISTS SOURCE_LINES) foreach(STATIC_METHOD IN LISTS STATIC_METHODS) string(REPLACE ":" ";" STATIC_METHOD "${STATIC_METHOD}") list(GET STATIC_METHOD 0 FUNCNAME) - list(GET STATIC_METHOD 1 ARGC) - list(GET STATIC_METHOD 2 TYPES) + list(GET STATIC_METHOD 1 TYPES) string(LENGTH "${FUNCNAME}" LEN) math(EXPR LEN "${MLEN} - ${LEN}") if("${TYPES}" STREQUAL "v") @@ -482,7 +481,7 @@ foreach(LINE IN LISTS SOURCE_LINES) if("${TYPES}" STREQUAL "v") string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQAdvancedStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");") else() - string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}${ARGC}, \"${TYPES}\");") + string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}\"${TYPES}\");") endif() endforeach() if(MLEN) @@ -502,8 +501,7 @@ foreach(LINE IN LISTS SOURCE_LINES) foreach(METHOD IN LISTS METHODS) string(REPLACE ":" ";" METHOD "${METHOD}") list(GET METHOD 0 FUNCNAME) - list(GET METHOD 1 ARGC) - list(GET METHOD 2 TYPES) + list(GET METHOD 1 TYPES) string(LENGTH "${FUNCNAME}" LEN) math(EXPR LEN "${MLEN} - ${LEN}") if("${TYPES}" STREQUAL "v") @@ -520,7 +518,7 @@ foreach(LINE IN LISTS SOURCE_LINES) if("${TYPES}" STREQUAL "v") string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQAdvancedMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");") else() - string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}${ARGC}, \"${TYPES}\");") + string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}\"${TYPES}\");") endif() endforeach() if(MLEN) @@ -687,9 +685,9 @@ foreach(LINE IN LISTS SOURCE_LINES) set(CLS_PARAM_2 "${TYPES}") elseif("${FUNCNAME}" MATCHES "^_" AND NOT "${TYPES}" STREQUAL "v") elseif(IS_STATIC) - list(APPEND STATIC_METHODS "${FUNCNAME}:${LEN}:${TYPES}") + list(APPEND STATIC_METHODS "${FUNCNAME}:${TYPES}") else() - list(APPEND METHODS "${FUNCNAME}:${LEN}:${TYPES}") + list(APPEND METHODS "${FUNCNAME}:${TYPES}") endif() continue() endif() diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index 53bc27ef2b..d59d149142 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -50,8 +50,8 @@ template <> SQInteger PushClassName(HSQUIRRELVM vm) { sq SQAIInfo.DefSQConst(engine, ScriptConfigFlags{ScriptConfigFlag::InGame}.base(), "AICONFIG_INGAME"); SQAIInfo.PostRegister(engine); - engine->AddMethod("RegisterAI", &AIInfo::Constructor, 2, "tx"); - engine->AddMethod("RegisterDummyAI", &AIInfo::DummyConstructor, 2, "tx"); + engine->AddMethod("RegisterAI", &AIInfo::Constructor, "tx"); + engine->AddMethod("RegisterDummyAI", &AIInfo::DummyConstructor, "tx"); } /* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm) @@ -130,7 +130,7 @@ bool AIInfo::CanLoadFromVersion(int version) const /* Create the AILibrary class, and add the RegisterLibrary function */ engine->AddClassBegin("AILibrary"); engine->AddClassEnd(); - engine->AddMethod("RegisterLibrary", &AILibrary::Constructor, 2, "tx"); + engine->AddMethod("RegisterLibrary", &AILibrary::Constructor, "tx"); } /* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm) diff --git a/src/game/game_info.cpp b/src/game/game_info.cpp index cd26703069..900bea5a12 100644 --- a/src/game/game_info.cpp +++ b/src/game/game_info.cpp @@ -42,7 +42,7 @@ template <> SQInteger PushClassName(HSQUIRRELVM vm) { SQGSInfo.DefSQConst(engine, ScriptConfigFlags{ScriptConfigFlag::Developer}.base(), "CONFIG_DEVELOPER"); SQGSInfo.PostRegister(engine); - engine->AddMethod("RegisterGS", &GameInfo::Constructor, 2, "tx"); + engine->AddMethod("RegisterGS", &GameInfo::Constructor, "tx"); } /* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm) @@ -100,7 +100,7 @@ bool GameInfo::CanLoadFromVersion(int version) const /* Create the GameLibrary class, and add the RegisterLibrary function */ engine->AddClassBegin("GSLibrary"); engine->AddClassEnd(); - engine->AddMethod("RegisterLibrary", &GameLibrary::Constructor, 2, "tx"); + engine->AddMethod("RegisterLibrary", &GameLibrary::Constructor, "tx"); } /* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm) diff --git a/src/script/api/ai/ai_controller.hpp.sq b/src/script/api/ai/ai_controller.hpp.sq index c1363fb20b..06ef24f143 100644 --- a/src/script/api/ai/ai_controller.hpp.sq +++ b/src/script/api/ai/ai_controller.hpp.sq @@ -14,17 +14,17 @@ void SQAIController_Register(Squirrel *engine) DefSQClass SQAIController("AIController"); SQAIController.PreRegister(engine); - SQAIController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, "."); - SQAIController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", 1, "."); - SQAIController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay, "SetCommandDelay", 2, ".i"); - SQAIController.DefSQStaticMethod(engine, &ScriptController::Sleep, "Sleep", 2, ".i"); - SQAIController.DefSQStaticMethod(engine, &ScriptController::Break, "Break", 2, ".s"); - SQAIController.DefSQStaticMethod(engine, &ScriptController::GetSetting, "GetSetting", 2, ".s"); - SQAIController.DefSQStaticMethod(engine, &ScriptController::GetVersion, "GetVersion", 1, "."); - SQAIController.DefSQStaticMethod(engine, &ScriptController::Print, "Print", 3, ".bs"); + SQAIController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", "."); + SQAIController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", "."); + SQAIController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay, "SetCommandDelay", ".i"); + SQAIController.DefSQStaticMethod(engine, &ScriptController::Sleep, "Sleep", ".i"); + SQAIController.DefSQStaticMethod(engine, &ScriptController::Break, "Break", ".s"); + SQAIController.DefSQStaticMethod(engine, &ScriptController::GetSetting, "GetSetting", ".s"); + SQAIController.DefSQStaticMethod(engine, &ScriptController::GetVersion, "GetVersion", "."); + SQAIController.DefSQStaticMethod(engine, &ScriptController::Print, "Print", ".bs"); SQAIController.PostRegister(engine); /* Register the import statement to the global scope */ - SQAIController.DefSQStaticMethod(engine, &ScriptController::Import, "import", 4, ".ssi"); + SQAIController.DefSQStaticMethod(engine, &ScriptController::Import, "import", ".ssi"); } diff --git a/src/script/api/game/game_controller.hpp.sq b/src/script/api/game/game_controller.hpp.sq index 2ac9148426..65da2e9443 100644 --- a/src/script/api/game/game_controller.hpp.sq +++ b/src/script/api/game/game_controller.hpp.sq @@ -14,17 +14,17 @@ void SQGSController_Register(Squirrel *engine) DefSQClass SQGSController("GSController"); SQGSController.PreRegister(engine); - SQGSController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, "."); - SQGSController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", 1, "."); - SQGSController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay, "SetCommandDelay", 2, ".i"); - SQGSController.DefSQStaticMethod(engine, &ScriptController::Sleep, "Sleep", 2, ".i"); - SQGSController.DefSQStaticMethod(engine, &ScriptController::Break, "Break", 2, ".s"); - SQGSController.DefSQStaticMethod(engine, &ScriptController::GetSetting, "GetSetting", 2, ".s"); - SQGSController.DefSQStaticMethod(engine, &ScriptController::GetVersion, "GetVersion", 1, "."); - SQGSController.DefSQStaticMethod(engine, &ScriptController::Print, "Print", 3, ".bs"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", "."); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", "."); + SQGSController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay, "SetCommandDelay", ".i"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::Sleep, "Sleep", ".i"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::Break, "Break", ".s"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetSetting, "GetSetting", ".s"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetVersion, "GetVersion", "."); + SQGSController.DefSQStaticMethod(engine, &ScriptController::Print, "Print", ".bs"); SQGSController.PostRegister(engine); /* Register the import statement to the global scope */ - SQGSController.DefSQStaticMethod(engine, &ScriptController::Import, "import", 4, ".ssi"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::Import, "import", ".ssi"); } diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index bc8e9969f6..27adb1da24 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -253,7 +253,7 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const std::string &s) } } -void Squirrel::AddMethod(std::string_view method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size) +void Squirrel::AddMethod(std::string_view method_name, SQFUNCTION proc, std::string_view params, void *userdata, int size) { ScriptAllocatorScope alloc_scope(this); @@ -265,7 +265,7 @@ void Squirrel::AddMethod(std::string_view method_name, SQFUNCTION proc, uint npa } sq_newclosure(this->vm, proc, size != 0 ? 1 : 0); - if (nparam != 0) sq_setparamscheck(this->vm, nparam, params); + if (!params.empty()) sq_setparamscheck(this->vm, params.size(), params.data()); sq_setnativeclosurename(this->vm, -1, method_name); sq_newslot(this->vm, -3, SQFalse); } diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index f77a96b49b..32953e9435 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -98,7 +98,7 @@ public: * Adds a function to the stack. Depending on the current state this means * either a method or a global function. */ - void AddMethod(std::string_view method_name, SQFUNCTION proc, uint nparam = 0, const char *params = nullptr, void *userdata = nullptr, int size = 0); + void AddMethod(std::string_view method_name, SQFUNCTION proc, std::string_view params = {}, void *userdata = nullptr, int size = 0); /** * Adds a const to the stack. Depending on the current state this means diff --git a/src/script/squirrel_class.hpp b/src/script/squirrel_class.hpp index f6534d8bde..eb1a3d8535 100644 --- a/src/script/squirrel_class.hpp +++ b/src/script/squirrel_class.hpp @@ -33,7 +33,7 @@ public: void DefSQMethod(Squirrel *engine, Func function_proc, std::string_view function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQNonStaticCallback, 0, nullptr, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQNonStaticCallback, {}, &function_proc, sizeof(function_proc)); } /** @@ -43,7 +43,7 @@ public: void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, std::string_view function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback, 0, nullptr, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback, {}, &function_proc, sizeof(function_proc)); } /** @@ -53,10 +53,10 @@ public: * of the code, but without it calling your function will fail! */ template - void DefSQMethod(Squirrel *engine, Func function_proc, std::string_view function_name, int nparam, const char *params) + void DefSQMethod(Squirrel *engine, Func function_proc, std::string_view function_name, std::string_view params) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQNonStaticCallback, nparam, params, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQNonStaticCallback, params, &function_proc, sizeof(function_proc)); } /** @@ -66,7 +66,7 @@ public: void DefSQStaticMethod(Squirrel *engine, Func function_proc, std::string_view function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQStaticCallback, 0, nullptr, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQStaticCallback, {}, &function_proc, sizeof(function_proc)); } /** @@ -76,7 +76,7 @@ public: void DefSQAdvancedStaticMethod(Squirrel *engine, Func function_proc, std::string_view function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQAdvancedStaticCallback, 0, nullptr, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQAdvancedStaticCallback, {}, &function_proc, sizeof(function_proc)); } /** @@ -86,10 +86,10 @@ public: * of the code, but without it calling your function will fail! */ template - void DefSQStaticMethod(Squirrel *engine, Func function_proc, std::string_view function_name, int nparam, const char *params) + void DefSQStaticMethod(Squirrel *engine, Func function_proc, std::string_view function_name, std::string_view params) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQStaticCallback, nparam, params, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQStaticCallback, params, &function_proc, sizeof(function_proc)); } template @@ -109,16 +109,16 @@ public: } template - void AddConstructor(Squirrel *engine, const char *params) + void AddConstructor(Squirrel *engine, std::string_view params) { using namespace SQConvert; - engine->AddMethod("constructor", DefSQConstructorCallback, Tnparam, params); + engine->AddMethod("constructor", DefSQConstructorCallback, params); } void AddSQAdvancedConstructor(Squirrel *engine) { using namespace SQConvert; - engine->AddMethod("constructor", DefSQAdvancedConstructorCallback, 0, nullptr); + engine->AddMethod("constructor", DefSQAdvancedConstructorCallback); } void PostRegister(Squirrel *engine) diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp index abcac023ec..a123722b30 100644 --- a/src/script/squirrel_std.cpp +++ b/src/script/squirrel_std.cpp @@ -90,16 +90,16 @@ void squirrel_register_global_std(Squirrel *engine) { /* We don't use squirrel_helper here, as we want to register to the global * scope and not to a class. */ - engine->AddMethod("require", &SquirrelStd::require, 2, ".s"); - engine->AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, 2, ".b"); + engine->AddMethod("require", &SquirrelStd::require, ".s"); + engine->AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b"); } void squirrel_register_std(Squirrel *engine) { /* We don't use squirrel_helper here, as we want to register to the global * scope and not to a class. */ - engine->AddMethod("min", &SquirrelStd::min, 3, ".ii"); - engine->AddMethod("max", &SquirrelStd::max, 3, ".ii"); + engine->AddMethod("min", &SquirrelStd::min, ".ii"); + engine->AddMethod("max", &SquirrelStd::max, ".ii"); sqstd_register_mathlib(engine->GetVM()); }