summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/script/script_scanner.cpp17
-rw-r--r--src/script/script_scanner.hpp4
-rw-r--r--src/script/squirrel.cpp29
-rw-r--r--src/script/squirrel.hpp15
4 files changed, 44 insertions, 21 deletions
diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp
index 98bc1f385..57265669f 100644
--- a/src/script/script_scanner.cpp
+++ b/src/script/script_scanner.cpp
@@ -53,9 +53,9 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const
if (!FioCheckFileExists(filename, this->subdir) || !FioCheckFileExists(this->main_script, this->subdir)) return false;
- /* We don't care if one of the other scripts failed to load. */
- this->engine->ResetCrashed();
+ this->ResetEngine();
this->engine->LoadScript(filename);
+
return true;
}
@@ -66,17 +66,20 @@ ScriptScanner::ScriptScanner() :
{
}
+void ScriptScanner::ResetEngine()
+{
+ this->engine->Reset();
+ this->engine->SetGlobalPointer(this);
+ this->RegisterAPI(this->engine);
+}
+
void ScriptScanner::Initialize(const char *name)
{
this->engine = new Squirrel(name);
- /* Mark this class as global pointer */
- this->engine->SetGlobalPointer(this);
-
- this->RegisterAPI(this->engine);
this->RescanDir();
- this->engine->ResetCrashed();
+ this->ResetEngine();
}
ScriptScanner::~ScriptScanner()
diff --git a/src/script/script_scanner.hpp b/src/script/script_scanner.hpp
index 5418dbd85..50dad02ad 100644
--- a/src/script/script_scanner.hpp
+++ b/src/script/script_scanner.hpp
@@ -128,6 +128,10 @@ protected:
*/
void Reset();
+ /**
+ * Reset the engine to ensure a clean environment for further steps.
+ */
+ void ResetEngine();
};
#endif /* SCRIPT_SCANNER_HPP */
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 7b80b24b6..9c101c7aa 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -335,12 +335,17 @@ bool Squirrel::CreateClassInstance(const char *class_name, void *real_instance,
}
Squirrel::Squirrel(const char *APIName) :
- global_pointer(NULL),
- print_func(NULL),
- crashed(false),
- overdrawn_ops(0),
APIName(APIName)
{
+ this->Initialize();
+}
+
+void Squirrel::Initialize()
+{
+ this->global_pointer = NULL;
+ this->print_func = NULL;
+ this->crashed = false;
+ this->overdrawn_ops = 0;
this->vm = sq_open(1024);
/* Handle compile-errors ourself, so we can display it nicely */
@@ -549,11 +554,22 @@ bool Squirrel::LoadScript(const char *script)
Squirrel::~Squirrel()
{
+ this->Uninitialize();
+}
+
+void Squirrel::Uninitialize()
+{
/* Clean up the stuff */
sq_pop(this->vm, 1);
sq_close(this->vm);
}
+void Squirrel::Reset()
+{
+ this->Uninitialize();
+ this->Initialize();
+}
+
void Squirrel::InsertResult(bool result)
{
sq_pushbool(this->vm, result);
@@ -587,11 +603,6 @@ bool Squirrel::HasScriptCrashed()
return this->crashed;
}
-void Squirrel::ResetCrashed()
-{
- this->crashed = false;
-}
-
void Squirrel::CrashOccurred()
{
this->crashed = true;
diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp
index 4e31d3247..4fdde85a1 100644
--- a/src/script/squirrel.hpp
+++ b/src/script/squirrel.hpp
@@ -41,6 +41,11 @@ private:
*/
const char *GetAPIName() { return this->APIName; }
+ /** Perform all initialization steps to create the engine. */
+ void Initialize();
+ /** Perform all the cleanups for the engine. */
+ void Uninitialize();
+
protected:
/**
* The CompileError handler.
@@ -249,11 +254,6 @@ public:
bool HasScriptCrashed();
/**
- * Reset the crashed status.
- */
- void ResetCrashed();
-
- /**
* Set the script status to crashed.
*/
void CrashOccurred();
@@ -267,6 +267,11 @@ public:
* How many operations can we execute till suspension?
*/
SQInteger GetOpsTillSuspend();
+
+ /**
+ * Completely reset the engine; start from scratch.
+ */
+ void Reset();
};
#endif /* SQUIRREL_HPP */