mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-18 19:19:29 +01:00
Codechange: Remove manual param count for constructors too
This commit is contained in:
parent
6d601e2eb1
commit
ccffbb4142
@ -178,7 +178,6 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
|||||||
endif()
|
endif()
|
||||||
unset(IS_PUBLIC)
|
unset(IS_PUBLIC)
|
||||||
unset(CLS_PARAMS)
|
unset(CLS_PARAMS)
|
||||||
set(CLS_ARGC 1)
|
|
||||||
set(CLS_TYPES "x")
|
set(CLS_TYPES "x")
|
||||||
set(CLS_IN_API ${API_SELECTED})
|
set(CLS_IN_API ${API_SELECTED})
|
||||||
unset(API_SELECTED)
|
unset(API_SELECTED)
|
||||||
@ -356,7 +355,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
|||||||
if("${CLS_TYPES}" STREQUAL "v")
|
if("${CLS_TYPES}" STREQUAL "v")
|
||||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddSQAdvancedConstructor(engine);")
|
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddSQAdvancedConstructor(engine);")
|
||||||
else()
|
else()
|
||||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddConstructor<void (${CLS}::*)(${CLS_PARAMS}), ${CLS_ARGC}>(engine, \"${CLS_TYPES}\");")
|
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddConstructor<void (${CLS}::*)(${CLS_PARAMS})>(engine, \"${CLS_TYPES}\");")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
string(APPEND SQUIRREL_EXPORT "\n")
|
string(APPEND SQUIRREL_EXPORT "\n")
|
||||||
@ -631,9 +630,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
|||||||
set(TYPES "x")
|
set(TYPES "x")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(LEN 1)
|
|
||||||
foreach(PARAM IN LISTS PARAMS)
|
foreach(PARAM IN LISTS PARAMS)
|
||||||
math(EXPR LEN "${LEN} + 1")
|
|
||||||
string(STRIP "${PARAM}" PARAM)
|
string(STRIP "${PARAM}" PARAM)
|
||||||
if("${PARAM}" MATCHES "\\*|&")
|
if("${PARAM}" MATCHES "\\*|&")
|
||||||
if("${PARAM}" MATCHES "^char")
|
if("${PARAM}" MATCHES "^char")
|
||||||
@ -672,7 +669,6 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
|||||||
unset(API_SELECTED)
|
unset(API_SELECTED)
|
||||||
|
|
||||||
if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME)
|
if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME)
|
||||||
set(CLS_ARGC ${LEN})
|
|
||||||
set(CLS_TYPES "${TYPES}")
|
set(CLS_TYPES "${TYPES}")
|
||||||
elseif("${FUNCNAME}" MATCHES "^_" AND NOT "${TYPES}" STREQUAL "v")
|
elseif("${FUNCNAME}" MATCHES "^_" AND NOT "${TYPES}" STREQUAL "v")
|
||||||
elseif(IS_STATIC)
|
elseif(IS_STATIC)
|
||||||
|
@ -34,7 +34,7 @@ template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq
|
|||||||
/* Create the AIInfo class, and add the RegisterAI function */
|
/* Create the AIInfo class, and add the RegisterAI function */
|
||||||
DefSQClass<AIInfo, ScriptType::AI> SQAIInfo("AIInfo");
|
DefSQClass<AIInfo, ScriptType::AI> SQAIInfo("AIInfo");
|
||||||
SQAIInfo.PreRegister(engine);
|
SQAIInfo.PreRegister(engine);
|
||||||
SQAIInfo.AddConstructor<void (AIInfo::*)(), 1>(engine, "x");
|
SQAIInfo.AddConstructor<void (AIInfo::*)()>(engine, "x");
|
||||||
SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting");
|
SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting");
|
||||||
SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddLabels, "AddLabels");
|
SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddLabels, "AddLabels");
|
||||||
SQAIInfo.DefSQConst(engine, ScriptConfigFlags{}.base(), "CONFIG_NONE");
|
SQAIInfo.DefSQConst(engine, ScriptConfigFlags{}.base(), "CONFIG_NONE");
|
||||||
|
@ -32,7 +32,7 @@ template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) {
|
|||||||
/* Create the GSInfo class, and add the RegisterGS function */
|
/* Create the GSInfo class, and add the RegisterGS function */
|
||||||
DefSQClass<GameInfo, ScriptType::GS> SQGSInfo("GSInfo");
|
DefSQClass<GameInfo, ScriptType::GS> SQGSInfo("GSInfo");
|
||||||
SQGSInfo.PreRegister(engine);
|
SQGSInfo.PreRegister(engine);
|
||||||
SQGSInfo.AddConstructor<void (GameInfo::*)(), 1>(engine, "x");
|
SQGSInfo.AddConstructor<void (GameInfo::*)()>(engine, "x");
|
||||||
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting");
|
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting");
|
||||||
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddLabels, "AddLabels");
|
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddLabels, "AddLabels");
|
||||||
SQGSInfo.DefSQConst(engine, ScriptConfigFlags{}.base(), "CONFIG_NONE");
|
SQGSInfo.DefSQConst(engine, ScriptConfigFlags{}.base(), "CONFIG_NONE");
|
||||||
|
@ -108,11 +108,11 @@ public:
|
|||||||
engine.AddClassBegin(this->classname, parent_class);
|
engine.AddClassBegin(this->classname, parent_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Func, int Tnparam>
|
template <typename Func>
|
||||||
void AddConstructor(Squirrel &engine, std::string_view params)
|
void AddConstructor(Squirrel &engine, std::string_view params)
|
||||||
{
|
{
|
||||||
using namespace SQConvert;
|
using namespace SQConvert;
|
||||||
engine.AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, params);
|
engine.AddMethod("constructor", DefSQConstructorCallback<CL, Func>, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSQAdvancedConstructor(Squirrel &engine)
|
void AddSQAdvancedConstructor(Squirrel &engine)
|
||||||
|
@ -376,14 +376,17 @@ namespace SQConvert {
|
|||||||
* params. It creates the instance in C++, and it sets all the needed
|
* params. It creates the instance in C++, and it sets all the needed
|
||||||
* settings in SQ to register the instance.
|
* settings in SQ to register the instance.
|
||||||
*/
|
*/
|
||||||
template <typename Tcls, typename Tmethod, int Tnparam>
|
template <typename Tcls, typename Tmethod>
|
||||||
inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm)
|
inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
/* Find the amount of params we got */
|
||||||
|
int nparam = sq_gettop(vm);
|
||||||
|
|
||||||
/* Create the real instance */
|
/* Create the real instance */
|
||||||
Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)nullptr, (Tmethod)nullptr, vm);
|
Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)nullptr, (Tmethod)nullptr, vm);
|
||||||
sq_setinstanceup(vm, -Tnparam, instance);
|
sq_setinstanceup(vm, -nparam, instance);
|
||||||
sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>);
|
sq_setreleasehook(vm, -nparam, DefSQDestructorCallback<Tcls>);
|
||||||
instance->AddRef();
|
instance->AddRef();
|
||||||
return 0;
|
return 0;
|
||||||
} catch (SQInteger &e) {
|
} catch (SQInteger &e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user