| 123 | } |
| 124 | |
| 125 | bool 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 | |
| 155 | ScriptInstance::~ScriptInstance() |
| 156 | { |
no test coverage detected