1
0
Fork 0

Codechange: Pass Script engine by reference.

pull/14156/head
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

@ -345,7 +345,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
string(APPEND SQUIRREL_EXPORT "\n") string(APPEND SQUIRREL_EXPORT "\n")
# Then do the registration functions of the class. # Then do the registration functions of the class.
string(APPEND SQUIRREL_EXPORT "\nvoid SQ${API_CLS}_Register(Squirrel *engine)") string(APPEND SQUIRREL_EXPORT "\nvoid SQ${API_CLS}_Register(Squirrel &engine)")
string(APPEND SQUIRREL_EXPORT "\n{") string(APPEND SQUIRREL_EXPORT "\n{")
string(APPEND SQUIRREL_EXPORT "\n DefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");") string(APPEND SQUIRREL_EXPORT "\n DefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
if("${SUPER_CLS}" STREQUAL "Text") if("${SUPER_CLS}" STREQUAL "Text")

View File

@ -19,7 +19,7 @@ endif()
file(READ "${API_FILES}" SCRIPT_API_BINARY_FILES) file(READ "${API_FILES}" SCRIPT_API_BINARY_FILES)
foreach(FILE IN LISTS SCRIPT_API_BINARY_FILES) foreach(FILE IN LISTS SCRIPT_API_BINARY_FILES)
file(STRINGS "${FILE}" LINES REGEX "^void SQ${APIUC}.*_Register\\(Squirrel \\*engine\\)$") file(STRINGS "${FILE}" LINES REGEX "^void SQ${APIUC}.*_Register\\(Squirrel &engine\\)$")
if(LINES) if(LINES)
string(REGEX REPLACE ".*api/${APILC}/(.*)" "#include \"\\1\"" FILE "${FILE}") string(REGEX REPLACE ".*api/${APILC}/(.*)" "#include \"\\1\"" FILE "${FILE}")
list(APPEND SQUIRREL_INCLUDES "${FILE}") list(APPEND SQUIRREL_INCLUDES "${FILE}")
@ -28,7 +28,7 @@ foreach(FILE IN LISTS SCRIPT_API_BINARY_FILES)
continue() continue()
endif() endif()
string(REGEX REPLACE "^.*void " " " LINE "${LINE}") string(REGEX REPLACE "^.*void " " " LINE "${LINE}")
string(REGEX REPLACE "Squirrel \\*" "" LINE "${LINE}") string(REGEX REPLACE "Squirrel &" "" LINE "${LINE}")
list(APPEND SQUIRREL_REGISTER "${LINE}") list(APPEND SQUIRREL_REGISTER "${LINE}")
endforeach() endforeach()
endif() endif()

View File

@ -29,7 +29,7 @@ static bool CheckAPIVersion(const std::string &api_version)
template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm, "AIInfo", -1); return 1; } template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm, "AIInfo", -1); return 1; }
/* static */ void AIInfo::RegisterAPI(Squirrel *engine) /* static */ void AIInfo::RegisterAPI(Squirrel &engine)
{ {
/* 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");
@ -50,8 +50,8 @@ template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq
SQAIInfo.DefSQConst(engine, ScriptConfigFlags{ScriptConfigFlag::InGame}.base(), "AICONFIG_INGAME"); SQAIInfo.DefSQConst(engine, ScriptConfigFlags{ScriptConfigFlag::InGame}.base(), "AICONFIG_INGAME");
SQAIInfo.PostRegister(engine); SQAIInfo.PostRegister(engine);
engine->AddMethod("RegisterAI", &AIInfo::Constructor, "tx"); engine.AddMethod("RegisterAI", &AIInfo::Constructor, "tx");
engine->AddMethod("RegisterDummyAI", &AIInfo::DummyConstructor, "tx"); engine.AddMethod("RegisterDummyAI", &AIInfo::DummyConstructor, "tx");
} }
/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm) /* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm)
@ -125,12 +125,12 @@ bool AIInfo::CanLoadFromVersion(int version) const
} }
/* static */ void AILibrary::RegisterAPI(Squirrel *engine) /* static */ void AILibrary::RegisterAPI(Squirrel &engine)
{ {
/* Create the AILibrary class, and add the RegisterLibrary function */ /* Create the AILibrary class, and add the RegisterLibrary function */
engine->AddClassBegin("AILibrary"); engine.AddClassBegin("AILibrary");
engine->AddClassEnd(); engine.AddClassEnd();
engine->AddMethod("RegisterLibrary", &AILibrary::Constructor, "tx"); engine.AddMethod("RegisterLibrary", &AILibrary::Constructor, "tx");
} }
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm) /* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)

View File

@ -23,7 +23,7 @@ public:
/** /**
* Register the functions of this class. * Register the functions of this class.
*/ */
static void RegisterAPI(Squirrel *engine); static void RegisterAPI(Squirrel &engine);
/** /**
* Create an AI, using this AIInfo as start-template. * Create an AI, using this AIInfo as start-template.
@ -64,7 +64,7 @@ public:
/** /**
* Register the functions of this class. * Register the functions of this class.
*/ */
static void RegisterAPI(Squirrel *engine); static void RegisterAPI(Squirrel &engine);
/** /**
* Create an AI, using this AIInfo as start-template. * Create an AI, using this AIInfo as start-template.

View File

@ -43,7 +43,7 @@ void AIInstance::Initialize(AIInfo *info)
this->api_version = info->GetAPIVersion(); this->api_version = info->GetAPIVersion();
/* Register the AIController (including the "import" command) */ /* Register the AIController (including the "import" command) */
SQAIController_Register(this->engine); SQAIController_Register(*this->engine);
ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), _current_company); ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), _current_company);
} }
@ -53,7 +53,7 @@ void AIInstance::RegisterAPI()
ScriptInstance::RegisterAPI(); ScriptInstance::RegisterAPI();
/* Register all classes */ /* Register all classes */
SQAI_RegisterAll(this->engine); SQAI_RegisterAll(*this->engine);
if (!this->LoadCompatibilityScripts(AI_DIR, AIInfo::ApiVersions)) this->Died(); if (!this->LoadCompatibilityScripts(AI_DIR, AIInfo::ApiVersions)) this->Died();
} }

View File

@ -54,7 +54,7 @@ std::string AIScannerInfo::GetScriptName(ScriptInfo *info)
return info->GetName(); return info->GetName();
} }
void AIScannerInfo::RegisterAPI(class Squirrel *engine) void AIScannerInfo::RegisterAPI(class Squirrel &engine)
{ {
AIInfo::RegisterAPI(engine); AIInfo::RegisterAPI(engine);
} }
@ -131,7 +131,7 @@ std::string AIScannerLibrary::GetScriptName(ScriptInfo *info)
return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName()); return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName());
} }
void AIScannerLibrary::RegisterAPI(class Squirrel *engine) void AIScannerLibrary::RegisterAPI(class Squirrel &engine)
{ {
AILibrary::RegisterAPI(engine); AILibrary::RegisterAPI(engine);
} }

View File

@ -44,7 +44,7 @@ protected:
std::string_view GetFileName() const override { return PATHSEP "info.nut"; } std::string_view GetFileName() const override { return PATHSEP "info.nut"; }
Subdirectory GetDirectory() const override { return AI_DIR; } Subdirectory GetDirectory() const override { return AI_DIR; }
std::string_view GetScannerName() const override { return "AIs"; } std::string_view GetScannerName() const override { return "AIs"; }
void RegisterAPI(class Squirrel *engine) override; void RegisterAPI(class Squirrel &engine) override;
private: private:
AIInfo *info_dummy; ///< The dummy AI. AIInfo *info_dummy; ///< The dummy AI.
@ -67,7 +67,7 @@ protected:
std::string_view GetFileName() const override { return PATHSEP "library.nut"; } std::string_view GetFileName() const override { return PATHSEP "library.nut"; }
Subdirectory GetDirectory() const override { return AI_LIBRARY_DIR; } Subdirectory GetDirectory() const override { return AI_LIBRARY_DIR; }
std::string_view GetScannerName() const override { return "AI Libraries"; } std::string_view GetScannerName() const override { return "AI Libraries"; }
void RegisterAPI(class Squirrel *engine) override; void RegisterAPI(class Squirrel &engine) override;
}; };
#endif /* AI_SCANNER_HPP */ #endif /* AI_SCANNER_HPP */

View File

@ -27,7 +27,7 @@ static bool CheckAPIVersion(const std::string &api_version)
template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) { sq_pushstring(vm, "GSInfo", -1); return 1; } template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) { sq_pushstring(vm, "GSInfo", -1); return 1; }
/* static */ void GameInfo::RegisterAPI(Squirrel *engine) /* static */ void GameInfo::RegisterAPI(Squirrel &engine)
{ {
/* 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");
@ -42,7 +42,7 @@ template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) {
SQGSInfo.DefSQConst(engine, ScriptConfigFlags{ScriptConfigFlag::Developer}.base(), "CONFIG_DEVELOPER"); SQGSInfo.DefSQConst(engine, ScriptConfigFlags{ScriptConfigFlag::Developer}.base(), "CONFIG_DEVELOPER");
SQGSInfo.PostRegister(engine); SQGSInfo.PostRegister(engine);
engine->AddMethod("RegisterGS", &GameInfo::Constructor, "tx"); engine.AddMethod("RegisterGS", &GameInfo::Constructor, "tx");
} }
/* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm) /* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm)
@ -95,12 +95,12 @@ bool GameInfo::CanLoadFromVersion(int version) const
} }
/* static */ void GameLibrary::RegisterAPI(Squirrel *engine) /* static */ void GameLibrary::RegisterAPI(Squirrel &engine)
{ {
/* Create the GameLibrary class, and add the RegisterLibrary function */ /* Create the GameLibrary class, and add the RegisterLibrary function */
engine->AddClassBegin("GSLibrary"); engine.AddClassBegin("GSLibrary");
engine->AddClassEnd(); engine.AddClassEnd();
engine->AddMethod("RegisterLibrary", &GameLibrary::Constructor, "tx"); engine.AddMethod("RegisterLibrary", &GameLibrary::Constructor, "tx");
} }
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm) /* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)

View File

@ -23,7 +23,7 @@ public:
/** /**
* Register the functions of this class. * Register the functions of this class.
*/ */
static void RegisterAPI(Squirrel *engine); static void RegisterAPI(Squirrel &engine);
/** /**
* Create an Game, using this GameInfo as start-template. * Create an Game, using this GameInfo as start-template.
@ -56,7 +56,7 @@ public:
/** /**
* Register the functions of this class. * Register the functions of this class.
*/ */
static void RegisterAPI(Squirrel *engine); static void RegisterAPI(Squirrel &engine);
/** /**
* Create an GSLibrary, using this GSInfo as start-template. * Create an GSLibrary, using this GSInfo as start-template.

View File

@ -38,7 +38,7 @@ void GameInstance::Initialize(GameInfo *info)
this->api_version = info->GetAPIVersion(); this->api_version = info->GetAPIVersion();
/* Register the GameController */ /* Register the GameController */
SQGSController_Register(this->engine); SQGSController_Register(*this->engine);
ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), OWNER_DEITY); ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), OWNER_DEITY);
} }
@ -48,9 +48,9 @@ void GameInstance::RegisterAPI()
ScriptInstance::RegisterAPI(); ScriptInstance::RegisterAPI();
/* Register all classes */ /* Register all classes */
SQGS_RegisterAll(this->engine); SQGS_RegisterAll(*this->engine);
RegisterGameTranslation(this->engine); RegisterGameTranslation(*this->engine);
if (!this->LoadCompatibilityScripts(GAME_DIR, GameInfo::ApiVersions)) this->Died(); if (!this->LoadCompatibilityScripts(GAME_DIR, GameInfo::ApiVersions)) this->Died();
} }

View File

@ -28,7 +28,7 @@ std::string GameScannerInfo::GetScriptName(ScriptInfo *info)
return info->GetName(); return info->GetName();
} }
void GameScannerInfo::RegisterAPI(class Squirrel *engine) void GameScannerInfo::RegisterAPI(class Squirrel &engine)
{ {
GameInfo::RegisterAPI(engine); GameInfo::RegisterAPI(engine);
} }
@ -81,7 +81,7 @@ std::string GameScannerLibrary::GetScriptName(ScriptInfo *info)
return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName()); return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName());
} }
void GameScannerLibrary::RegisterAPI(class Squirrel *engine) void GameScannerLibrary::RegisterAPI(class Squirrel &engine)
{ {
GameLibrary::RegisterAPI(engine); GameLibrary::RegisterAPI(engine);
} }

View File

@ -30,7 +30,7 @@ protected:
std::string_view GetFileName() const override { return PATHSEP "info.nut"; } std::string_view GetFileName() const override { return PATHSEP "info.nut"; }
Subdirectory GetDirectory() const override { return GAME_DIR; } Subdirectory GetDirectory() const override { return GAME_DIR; }
std::string_view GetScannerName() const override { return "Game Scripts"; } std::string_view GetScannerName() const override { return "Game Scripts"; }
void RegisterAPI(class Squirrel *engine) override; void RegisterAPI(class Squirrel &engine) override;
}; };
@ -51,7 +51,7 @@ protected:
std::string_view GetFileName() const override { return PATHSEP "library.nut"; } std::string_view GetFileName() const override { return PATHSEP "library.nut"; }
Subdirectory GetDirectory() const override { return GAME_LIBRARY_DIR; } Subdirectory GetDirectory() const override { return GAME_LIBRARY_DIR; }
std::string_view GetScannerName() const override { return "GS Libraries"; } std::string_view GetScannerName() const override { return "GS Libraries"; }
void RegisterAPI(class Squirrel *engine) override; void RegisterAPI(class Squirrel &engine) override;
}; };
#endif /* GAME_SCANNER_HPP */ #endif /* GAME_SCANNER_HPP */

View File

@ -356,12 +356,12 @@ const std::string &GetGameStringName(StringIndexInTab id)
* Register the current translation to the Squirrel engine. * Register the current translation to the Squirrel engine.
* @param engine The engine to update/ * @param engine The engine to update/
*/ */
void RegisterGameTranslation(Squirrel *engine) void RegisterGameTranslation(Squirrel &engine)
{ {
_current_gamestrings_data = LoadTranslations(); _current_gamestrings_data = LoadTranslations();
if (_current_gamestrings_data == nullptr) return; if (_current_gamestrings_data == nullptr) return;
HSQUIRRELVM vm = engine->GetVM(); HSQUIRRELVM vm = engine.GetVM();
sq_pushroottable(vm); sq_pushroottable(vm);
sq_pushstring(vm, "GSText", -1); sq_pushstring(vm, "GSText", -1);
if (SQ_FAILED(sq_get(vm, -2))) return; if (SQ_FAILED(sq_get(vm, -2))) return;

View File

@ -33,7 +33,7 @@ using StringParamsList = std::vector<StringParams>;
std::string_view GetGameStringPtr(StringIndexInTab id); std::string_view GetGameStringPtr(StringIndexInTab id);
const StringParams &GetGameStringParams(StringIndexInTab id); const StringParams &GetGameStringParams(StringIndexInTab id);
const std::string &GetGameStringName(StringIndexInTab id); const std::string &GetGameStringName(StringIndexInTab id);
void RegisterGameTranslation(class Squirrel *engine); void RegisterGameTranslation(class Squirrel &engine);
void ReconsiderGameScriptLanguage(); void ReconsiderGameScriptLanguage();
/** Container for the raw (unencoded) language strings of a language. */ /** Container for the raw (unencoded) language strings of a language. */

View File

@ -9,7 +9,7 @@
template <> SQInteger PushClassName<ScriptController, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm, "AIController", -1); return 1; } 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"); DefSQClass<ScriptController, ScriptType::AI> SQAIController("AIController");
SQAIController.PreRegister(engine); SQAIController.PreRegister(engine);

View File

@ -9,7 +9,7 @@
template <> SQInteger PushClassName<ScriptController, ScriptType::GS>(HSQUIRRELVM vm) { sq_pushstring(vm, "GSController", -1); return 1; } 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"); DefSQClass<ScriptController, ScriptType::GS> SQGSController("GSController");
SQGSController.PreRegister(engine); SQGSController.PreRegister(engine);

View File

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

View File

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

View File

@ -115,7 +115,7 @@ protected:
/** /**
* Register the API for this ScriptInfo. * 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. * Get the type of the script, in plural.

View File

@ -30,20 +30,20 @@ public:
* This defines a method inside a class for Squirrel. * This defines a method inside a class for Squirrel.
*/ */
template <typename Func> 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; 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!). * This defines a method inside a class for Squirrel, which has access to the 'engine' (experts only!).
*/ */
template <typename Func> 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; 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! * of the code, but without it calling your function will fail!
*/ */
template <typename Func> 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; 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. * This defines a static method inside a class for Squirrel.
*/ */
template <typename Func> 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; 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!). * This defines a static method inside a class for Squirrel, which has access to the 'engine' (experts only!).
*/ */
template <typename Func> 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; 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! * of the code, but without it calling your function will fail!
*/ */
template <typename Func> 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; 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> 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> template <typename Func, int Tnparam>
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, Tnparam>, params);
} }
void AddSQAdvancedConstructor(Squirrel *engine) void AddSQAdvancedConstructor(Squirrel &engine)
{ {
using namespace SQConvert; 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();
} }
}; };