Codechange: Pass Script engine by reference.

This commit is contained in:
Peter Nelson
2025-03-24 16:54:55 +00:00
committed by Peter Nelson
parent 72ca962b84
commit 341cdbc16b
20 changed files with 65 additions and 65 deletions

View File

@@ -9,7 +9,7 @@
template <> SQInteger PushClassName<ScriptController, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm, "AIController", -1); return 1; }
void SQAIController_Register(Squirrel *engine)
void SQAIController_Register(Squirrel &engine)
{
DefSQClass<ScriptController, ScriptType::AI> SQAIController("AIController");
SQAIController.PreRegister(engine);

View File

@@ -9,7 +9,7 @@
template <> SQInteger PushClassName<ScriptController, ScriptType::GS>(HSQUIRRELVM vm) { sq_pushstring(vm, "GSController", -1); return 1; }
void SQGSController_Register(Squirrel *engine)
void SQGSController_Register(Squirrel &engine)
{
DefSQClass<ScriptController, ScriptType::GS> SQGSController("GSController");
SQGSController.PreRegister(engine);

View File

@@ -21,7 +21,7 @@ static SQInteger ${APIUC}ObjectCloned(HSQUIRRELVM)
throw Script_FatalError("This instance is not cloneable");
}
void SQ${APIUC}_RegisterAll(Squirrel *engine)
void SQ${APIUC}_RegisterAll(Squirrel &engine)
{
DefSQClass<ScriptObject, ScriptType::${APIUC}> SQ${APIUC}Object("${APIUC}Object");
SQ${APIUC}Object.PreRegister(engine);

View File

@@ -53,7 +53,7 @@ void ScriptScanner::ResetEngine()
{
this->engine->Reset();
this->engine->SetGlobalPointer(this);
this->RegisterAPI(this->engine);
this->RegisterAPI(*this->engine);
}
void ScriptScanner::Initialize(std::string_view name)

View File

@@ -115,7 +115,7 @@ protected:
/**
* Register the API for this ScriptInfo.
*/
virtual void RegisterAPI(class Squirrel *engine) = 0;
virtual void RegisterAPI(class Squirrel &engine) = 0;
/**
* Get the type of the script, in plural.

View File

@@ -30,20 +30,20 @@ public:
* This defines a method inside a class for Squirrel.
*/
template <typename Func>
void DefSQMethod(Squirrel *engine, Func function_proc, std::string_view function_name)
void DefSQMethod(Squirrel &engine, Func function_proc, std::string_view function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, {}, &function_proc, sizeof(function_proc));
engine.AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, {}, &function_proc, sizeof(function_proc));
}
/**
* This defines a method inside a class for Squirrel, which has access to the 'engine' (experts only!).
*/
template <typename Func>
void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, std::string_view function_name)
void DefSQAdvancedMethod(Squirrel &engine, Func function_proc, std::string_view function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func, ST>, {}, &function_proc, sizeof(function_proc));
engine.AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func, ST>, {}, &function_proc, sizeof(function_proc));
}
/**
@@ -53,30 +53,30 @@ 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, std::string_view 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>, params, &function_proc, sizeof(function_proc));
engine.AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, params, &function_proc, sizeof(function_proc));
}
/**
* This defines a static method inside a class for Squirrel.
*/
template <typename Func>
void DefSQStaticMethod(Squirrel *engine, Func function_proc, std::string_view function_name)
void DefSQStaticMethod(Squirrel &engine, Func function_proc, std::string_view function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, {}, &function_proc, sizeof(function_proc));
engine.AddMethod(function_name, DefSQStaticCallback<CL, Func>, {}, &function_proc, sizeof(function_proc));
}
/**
* This defines a static method inside a class for Squirrel, which has access to the 'engine' (experts only!).
*/
template <typename Func>
void DefSQAdvancedStaticMethod(Squirrel *engine, Func function_proc, std::string_view function_name)
void DefSQAdvancedStaticMethod(Squirrel &engine, Func function_proc, std::string_view function_name)
{
using namespace SQConvert;
engine->AddMethod(function_name, DefSQAdvancedStaticCallback<CL, Func>, {}, &function_proc, sizeof(function_proc));
engine.AddMethod(function_name, DefSQAdvancedStaticCallback<CL, Func>, {}, &function_proc, sizeof(function_proc));
}
/**
@@ -86,44 +86,44 @@ 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, 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, DefSQStaticCallback<CL, Func>, params, &function_proc, sizeof(function_proc));
engine.AddMethod(function_name, DefSQStaticCallback<CL, Func>, params, &function_proc, sizeof(function_proc));
}
template <typename Var>
void DefSQConst(Squirrel *engine, Var value, std::string_view var_name)
void DefSQConst(Squirrel &engine, Var value, std::string_view var_name)
{
engine->AddConst(var_name, value);
engine.AddConst(var_name, value);
}
void PreRegister(Squirrel *engine)
void PreRegister(Squirrel &engine)
{
engine->AddClassBegin(this->classname);
engine.AddClassBegin(this->classname);
}
void PreRegister(Squirrel *engine, std::string_view parent_class)
void PreRegister(Squirrel &engine, std::string_view parent_class)
{
engine->AddClassBegin(this->classname, parent_class);
engine.AddClassBegin(this->classname, parent_class);
}
template <typename Func, int Tnparam>
void AddConstructor(Squirrel *engine, std::string_view params)
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, Tnparam>, params);
}
void AddSQAdvancedConstructor(Squirrel *engine)
void AddSQAdvancedConstructor(Squirrel &engine)
{
using namespace SQConvert;
engine->AddMethod("constructor", DefSQAdvancedConstructorCallback<CL>);
engine.AddMethod("constructor", DefSQAdvancedConstructorCallback<CL>);
}
void PostRegister(Squirrel *engine)
void PostRegister(Squirrel &engine)
{
engine->AddClassEnd();
engine.AddClassEnd();
}
};