mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-16 00:42:45 +01:00
Codechange: Remove manual param count for constructors too
This commit is contained in:
@@ -108,11 +108,11 @@ public:
|
||||
engine.AddClassBegin(this->classname, parent_class);
|
||||
}
|
||||
|
||||
template <typename Func, int Tnparam>
|
||||
template <typename Func>
|
||||
void AddConstructor(Squirrel &engine, std::string_view params)
|
||||
{
|
||||
using namespace SQConvert;
|
||||
engine.AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, params);
|
||||
engine.AddMethod("constructor", DefSQConstructorCallback<CL, Func>, params);
|
||||
}
|
||||
|
||||
void AddSQAdvancedConstructor(Squirrel &engine)
|
||||
|
||||
@@ -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 <typename Tcls, typename Tmethod, int Tnparam>
|
||||
template <typename Tcls, typename Tmethod>
|
||||
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<Tmethod>::SQConstruct((Tcls *)nullptr, (Tmethod)nullptr, vm);
|
||||
sq_setinstanceup(vm, -Tnparam, instance);
|
||||
sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>);
|
||||
sq_setinstanceup(vm, -nparam, instance);
|
||||
sq_setreleasehook(vm, -nparam, DefSQDestructorCallback<Tcls>);
|
||||
instance->AddRef();
|
||||
return 0;
|
||||
} catch (SQInteger &e) {
|
||||
|
||||
Reference in New Issue
Block a user