mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Get/pass engine by reference instead of pointer.
parent
49bc9d03cb
commit
a1b855669e
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue