mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-28 06:34:33 +01:00
Codechange: remove manual param count; in all cases strlen(params) == nparams
This commit is contained in:
@@ -14,17 +14,17 @@ void SQAIController_Register(Squirrel *engine)
|
||||
DefSQClass<ScriptController, ScriptType::AI> 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");
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ void SQGSController_Register(Squirrel *engine)
|
||||
DefSQClass<ScriptController, ScriptType::GS> 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");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<CL, Func, ST>, 0, nullptr, &function_proc, sizeof(function_proc));
|
||||
engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, {}, &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<CL, Func, ST>, 0, nullptr, &function_proc, sizeof(function_proc));
|
||||
engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func, ST>, {}, &function_proc, sizeof(function_proc));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,10 +53,10 @@ public:
|
||||
* of the code, but without it calling your function will fail!
|
||||
*/
|
||||
template <typename Func>
|
||||
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<CL, Func, ST>, nparam, params, &function_proc, sizeof(function_proc));
|
||||
engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, 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<CL, Func>, 0, nullptr, &function_proc, sizeof(function_proc));
|
||||
engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, {}, &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<CL, Func>, 0, nullptr, &function_proc, sizeof(function_proc));
|
||||
engine->AddMethod(function_name, DefSQAdvancedStaticCallback<CL, Func>, {}, &function_proc, sizeof(function_proc));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,10 +86,10 @@ public:
|
||||
* of the code, but without it calling your function will fail!
|
||||
*/
|
||||
template <typename Func>
|
||||
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<CL, Func>, nparam, params, &function_proc, sizeof(function_proc));
|
||||
engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, params, &function_proc, sizeof(function_proc));
|
||||
}
|
||||
|
||||
template <typename Var>
|
||||
@@ -109,16 +109,16 @@ public:
|
||||
}
|
||||
|
||||
template <typename Func, int Tnparam>
|
||||
void AddConstructor(Squirrel *engine, const char *params)
|
||||
void AddConstructor(Squirrel *engine, std::string_view params)
|
||||
{
|
||||
using namespace SQConvert;
|
||||
engine->AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, Tnparam, params);
|
||||
engine->AddMethod("constructor", DefSQConstructorCallback<CL, Func, Tnparam>, params);
|
||||
}
|
||||
|
||||
void AddSQAdvancedConstructor(Squirrel *engine)
|
||||
{
|
||||
using namespace SQConvert;
|
||||
engine->AddMethod("constructor", DefSQAdvancedConstructorCallback<CL>, 0, nullptr);
|
||||
engine->AddMethod("constructor", DefSQAdvancedConstructorCallback<CL>);
|
||||
}
|
||||
|
||||
void PostRegister(Squirrel *engine)
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user