diff --git a/cmake/scripts/SquirrelExport.cmake b/cmake/scripts/SquirrelExport.cmake index 242a724483..fbb4207cd1 100644 --- a/cmake/scripts/SquirrelExport.cmake +++ b/cmake/scripts/SquirrelExport.cmake @@ -178,7 +178,6 @@ foreach(LINE IN LISTS SOURCE_LINES) endif() unset(IS_PUBLIC) unset(CLS_PARAMS) - set(CLS_ARGC 1) set(CLS_TYPES "x") set(CLS_IN_API ${API_SELECTED}) unset(API_SELECTED) @@ -356,7 +355,7 @@ foreach(LINE IN LISTS SOURCE_LINES) if("${CLS_TYPES}" STREQUAL "v") string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddSQAdvancedConstructor(engine);") else() - string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddConstructor(engine, \"${CLS_TYPES}\");") + string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddConstructor(engine, \"${CLS_TYPES}\");") endif() endif() string(APPEND SQUIRREL_EXPORT "\n") @@ -631,9 +630,7 @@ foreach(LINE IN LISTS SOURCE_LINES) set(TYPES "x") endif() - set(LEN 1) foreach(PARAM IN LISTS PARAMS) - math(EXPR LEN "${LEN} + 1") string(STRIP "${PARAM}" PARAM) if("${PARAM}" MATCHES "\\*|&") if("${PARAM}" MATCHES "^char") @@ -672,7 +669,6 @@ foreach(LINE IN LISTS SOURCE_LINES) unset(API_SELECTED) if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME) - set(CLS_ARGC ${LEN}) set(CLS_TYPES "${TYPES}") elseif("${FUNCNAME}" MATCHES "^_" AND NOT "${TYPES}" STREQUAL "v") elseif(IS_STATIC) diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index 67fad8d494..3cc023c995 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -34,7 +34,7 @@ template <> SQInteger PushClassName(HSQUIRRELVM vm) { sq /* Create the AIInfo class, and add the RegisterAI function */ DefSQClass SQAIInfo("AIInfo"); SQAIInfo.PreRegister(engine); - SQAIInfo.AddConstructor(engine, "x"); + SQAIInfo.AddConstructor(engine, "x"); SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting"); SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddLabels, "AddLabels"); SQAIInfo.DefSQConst(engine, ScriptConfigFlags{}.base(), "CONFIG_NONE"); diff --git a/src/game/game_info.cpp b/src/game/game_info.cpp index edf5334604..6d128ac9a1 100644 --- a/src/game/game_info.cpp +++ b/src/game/game_info.cpp @@ -32,7 +32,7 @@ template <> SQInteger PushClassName(HSQUIRRELVM vm) { /* Create the GSInfo class, and add the RegisterGS function */ DefSQClass SQGSInfo("GSInfo"); SQGSInfo.PreRegister(engine); - SQGSInfo.AddConstructor(engine, "x"); + SQGSInfo.AddConstructor(engine, "x"); SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting"); SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddLabels, "AddLabels"); SQGSInfo.DefSQConst(engine, ScriptConfigFlags{}.base(), "CONFIG_NONE"); diff --git a/src/script/squirrel_class.hpp b/src/script/squirrel_class.hpp index 6a683a0631..e090689e05 100644 --- a/src/script/squirrel_class.hpp +++ b/src/script/squirrel_class.hpp @@ -108,11 +108,11 @@ public: engine.AddClassBegin(this->classname, parent_class); } - template + template void AddConstructor(Squirrel &engine, std::string_view params) { using namespace SQConvert; - engine.AddMethod("constructor", DefSQConstructorCallback, params); + engine.AddMethod("constructor", DefSQConstructorCallback, params); } void AddSQAdvancedConstructor(Squirrel &engine) diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index dffa022480..1820ff171a 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -376,14 +376,17 @@ namespace SQConvert { * params. It creates the instance in C++, and it sets all the needed * settings in SQ to register the instance. */ - template + template inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm) { try { + /* Find the amount of params we got */ + int nparam = sq_gettop(vm); + /* Create the real instance */ Tcls *instance = HelperT::SQConstruct((Tcls *)nullptr, (Tmethod)nullptr, vm); - sq_setinstanceup(vm, -Tnparam, instance); - sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback); + sq_setinstanceup(vm, -nparam, instance); + sq_setreleasehook(vm, -nparam, DefSQDestructorCallback); instance->AddRef(); return 0; } catch (SQInteger &e) {