From 8e3acbfa84a15cc693436b5e9264101414dd71dc Mon Sep 17 00:00:00 2001 From: glx22 Date: Thu, 12 Jun 2025 01:38:37 +0200 Subject: [PATCH] Codechange: Deduplicate DefSQClass::DefSQ[Static]Method() --- src/script/squirrel_class.hpp | 40 +++++++++-------------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/src/script/squirrel_class.hpp b/src/script/squirrel_class.hpp index e090689e05..dd84ff652b 100644 --- a/src/script/squirrel_class.hpp +++ b/src/script/squirrel_class.hpp @@ -27,13 +27,16 @@ public: {} /** - * This defines a method inside a class for Squirrel. + * This defines a method inside a class for Squirrel with defined params. + * @note If you define params, make sure that the first param is always 'x', + * which is the 'this' inside the function. This is hidden from the rest + * of the code, but without it calling your function will fail! */ template - void DefSQMethod(Squirrel &engine, Func function_proc, std::string_view function_name) + void DefSQMethod(Squirrel &engine, Func function_proc, std::string_view function_name, std::string_view params = {}) { using namespace SQConvert; - engine.AddMethod(function_name, DefSQNonStaticCallback, {}, &function_proc, sizeof(function_proc)); + engine.AddMethod(function_name, DefSQNonStaticCallback, params, &function_proc, sizeof(function_proc)); } /** @@ -47,26 +50,16 @@ public: } /** - * This defines a method inside a class for Squirrel with defined params. - * @note If you define nparam, make sure that the first param is always 'x', + * This defines a static method inside a class for Squirrel with defined params. + * @note If you define params, make sure that the first param is always 'x', * which is the 'this' inside the function. This is hidden from the rest * of the code, but without it calling your function will fail! */ template - void DefSQMethod(Squirrel &engine, Func function_proc, std::string_view function_name, std::string_view params) + void DefSQStaticMethod(Squirrel &engine, Func function_proc, std::string_view function_name, std::string_view params = {}) { using namespace SQConvert; - engine.AddMethod(function_name, DefSQNonStaticCallback, params, &function_proc, sizeof(function_proc)); - } - - /** - * This defines a static method inside a class for Squirrel. - */ - template - void DefSQStaticMethod(Squirrel &engine, Func function_proc, std::string_view function_name) - { - using namespace SQConvert; - engine.AddMethod(function_name, DefSQStaticCallback, {}, &function_proc, sizeof(function_proc)); + engine.AddMethod(function_name, DefSQStaticCallback, params, &function_proc, sizeof(function_proc)); } /** @@ -79,19 +72,6 @@ public: engine.AddMethod(function_name, DefSQAdvancedStaticCallback, {}, &function_proc, sizeof(function_proc)); } - /** - * This defines a static method inside a class for Squirrel with defined params. - * @note If you define nparam, make sure that the first param is always 'x', - * which is the 'this' inside the function. This is hidden from the rest - * of the code, but without it calling your function will fail! - */ - template - void DefSQStaticMethod(Squirrel &engine, Func function_proc, std::string_view function_name, std::string_view params) - { - using namespace SQConvert; - engine.AddMethod(function_name, DefSQStaticCallback, params, &function_proc, sizeof(function_proc)); - } - template void DefSQConst(Squirrel &engine, Var value, std::string_view var_name) {