summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script_instance.cpp23
-rw-r--r--src/script/script_instance.hpp10
2 files changed, 33 insertions, 0 deletions
diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp
index 5b515c52f..95fcf6f0d 100644
--- a/src/script/script_instance.cpp
+++ b/src/script/script_instance.cpp
@@ -27,6 +27,7 @@
#include "../company_base.h"
#include "../company_func.h"
+#include "../fileio_func.h"
ScriptStorage::~ScriptStorage()
{
@@ -104,6 +105,28 @@ void ScriptInstance::RegisterAPI()
squirrel_register_std(this->engine);
}
+bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirectory dir)
+{
+ char script_name[32];
+ seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version);
+ char buf[MAX_PATH];
+ Searchpath sp;
+ FOR_ALL_SEARCHPATHS(sp) {
+ FioAppendDirectory(buf, MAX_PATH, sp, dir);
+ ttd_strlcat(buf, script_name, MAX_PATH);
+ if (!FileExists(buf)) continue;
+
+ if (this->engine->LoadScript(buf)) return true;
+
+ ScriptLog::Error("Failed to load API compatibility script");
+ DEBUG(script, 0, "Error compiling / running API compatibility script: %s", buf);
+ return false;
+ }
+
+ ScriptLog::Warning("API compatibility script not found");
+ return true;
+}
+
ScriptInstance::~ScriptInstance()
{
ScriptObject::ActiveInstance active(this);
diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp
index 7a02237b8..0cda170f4 100644
--- a/src/script/script_instance.hpp
+++ b/src/script/script_instance.hpp
@@ -17,6 +17,7 @@
#include "../command_type.h"
#include "../company_type.h"
+#include "../fileio_type.h"
static const uint SQUIRREL_MAX_DEPTH = 25; ///< The maximum recursive depth for items stored in the savegame.
@@ -176,6 +177,7 @@ public:
protected:
class Squirrel *engine; ///< A wrapper around the squirrel vm.
+ const char *versionAPI; ///< Current API used by this script.
/**
* Register all API functions to the VM.
@@ -183,6 +185,14 @@ protected:
virtual void RegisterAPI();
/**
+ * Load squirrel scripts to emulate an older API.
+ * @param api_version: API version to load scripts for
+ * @param dir Subdirectory to find the scripts in
+ * @return true iff script loading should proceed
+ */
+ bool LoadCompatibilityScripts(const char *api_version, Subdirectory dir);
+
+ /**
* Tell the script it died.
*/
virtual void Died();