MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadCompatibilityScripts

Method LoadCompatibilityScripts

src/script/script_instance.cpp:125–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::span<const std::string_view> api_versions)
126{
127 /* Don't try to load compatibility scripts for the current version. */
128 if (this->api_version == api_versions.back()) return true;
129
130 ScriptLog::Info(fmt::format("Downgrading API to be compatible with version {}", this->api_version));
131
132 HSQUIRRELVM vm = this->engine->GetVM();
133 sq_pushroottable(vm);
134 sq_pushstring(vm, "CompatScriptRootTable");
135 sq_pushroottable(vm);
136 sq_newslot(vm, -3, SQFalse);
137 sq_pop(vm, 1);
138
139 /* Downgrade the API till we are the same version as the script. The last
140 * entry in the list is always the current version, so skip that one. */
141 for (auto it = std::rbegin(api_versions) + 1; it != std::rend(api_versions); ++it) {
142 if (!this->LoadCompatibilityScript(*it, dir)) return false;
143
144 if (*it == this->api_version) break;
145 }
146
147 sq_pushroottable(vm);
148 sq_pushstring(vm, "CompatScriptRootTable");
149 sq_deleteslot(vm, -2, SQFalse);
150 sq_pop(vm, 1);
151
152 return true;
153}
154
155ScriptInstance::~ScriptInstance()
156{

Callers 2

RegisterAPIMethod · 0.80
RegisterAPIMethod · 0.80

Calls 10

sq_pushroottableFunction · 0.85
sq_pushstringFunction · 0.85
sq_newslotFunction · 0.85
sq_popFunction · 0.85
rbeginFunction · 0.85
rendFunction · 0.85
sq_deleteslotFunction · 0.85
GetVMMethod · 0.80
formatFunction · 0.50

Tested by

no test coverage detected