1
0
Fork 0

Codechange: Get/pass engine by reference instead of pointer.

pull/14339/head
Peter Nelson 2025-06-06 22:24:27 +01:00
parent 49bc9d03cb
commit a1b855669e
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
6 changed files with 16 additions and 16 deletions

View File

@ -97,8 +97,8 @@ ScriptController::ScriptController(::CompanyID company) :
/* static */ HSQOBJECT ScriptController::Import(const std::string &library, const std::string &class_name, int version)
{
ScriptController &controller = ScriptObject::GetActiveInstance().GetController();
Squirrel *engine = ScriptObject::GetActiveInstance().engine;
HSQUIRRELVM vm = engine->GetVM();
Squirrel &engine = *ScriptObject::GetActiveInstance().engine;
HSQUIRRELVM vm = engine.GetVM();
ScriptInfo *lib = ScriptObject::GetActiveInstance().FindLibrary(library, version);
if (lib == nullptr) {
@ -128,7 +128,7 @@ ScriptController::ScriptController(::CompanyID company) :
sq_pushstring(vm, fake_class);
sq_newclass(vm, SQFalse);
/* Load the library */
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
if (!engine.LoadScript(vm, lib->GetMainScript(), false)) {
throw sq_throwerror(vm, fmt::format("there was a compile error when importing '{}' version {}", library, version));
}
/* Create the fake class */

View File

@ -310,8 +310,8 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
IncreaseDoCommandCosts(res.GetCost());
if (!_generating_world) {
/* Charge a nominal fee for asynchronously executed commands */
Squirrel *engine = ScriptObject::GetActiveInstance().engine;
Squirrel::DecreaseOps(engine->GetVM(), 100);
Squirrel &engine = *ScriptObject::GetActiveInstance().engine;
Squirrel::DecreaseOps(engine.GetVM(), 100);
}
if (callback != nullptr) {
/* Insert return value into to stack and throw a control code that

View File

@ -98,7 +98,7 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
void ScriptInstance::RegisterAPI()
{
squirrel_register_std(this->engine);
squirrel_register_std(*this->engine);
}
bool ScriptInstance::LoadCompatibilityScript(std::string_view api_version, Subdirectory dir)

View File

@ -536,7 +536,7 @@ void Squirrel::Initialize()
sq_setforeignptr(this->vm, this);
sq_pushroottable(this->vm);
squirrel_register_global_std(this);
squirrel_register_global_std(*this);
/* Set consts table as delegate of root table, so consts/enums defined via require() are accessible */
sq_pushconsttable(this->vm);

View File

@ -82,20 +82,20 @@ SQInteger SquirrelStd::notifyallexceptions(HSQUIRRELVM vm)
return SQ_ERROR;
}
void squirrel_register_global_std(Squirrel *engine)
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, ".s");
engine->AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b");
engine.AddMethod("require", &SquirrelStd::require, ".s");
engine.AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b");
}
void squirrel_register_std(Squirrel *engine)
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, ".ii");
engine->AddMethod("max", &SquirrelStd::max, ".ii");
engine.AddMethod("min", &SquirrelStd::min, ".ii");
engine.AddMethod("max", &SquirrelStd::max, ".ii");
sqstd_register_mathlib(engine->GetVM());
sqstd_register_mathlib(engine.GetVM());
}

View File

@ -52,12 +52,12 @@ public:
/**
* Register all standard functions we want to give to a script.
*/
void squirrel_register_std(Squirrel *engine);
void squirrel_register_std(Squirrel &engine);
/**
* Register all standard functions that are available on first startup.
* @note this set is very limited, and is only meant to load other scripts and things like that.
*/
void squirrel_register_global_std(Squirrel *engine);
void squirrel_register_global_std(Squirrel &engine);
#endif /* SQUIRREL_STD_HPP */