From a6b4e59963561cefde5660c2ded9bd0b2801f2fc Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 25 May 2014 19:53:46 +0000 Subject: (svn r26617) -Fix [FS#5973]: [Script] Loading/parsing of info .nuts was done in the same VM, causing e.g. constants to break the loading of info of other scripts --- src/script/script_scanner.cpp | 17 ++++++++++------- src/script/script_scanner.hpp | 4 ++++ src/script/squirrel.cpp | 29 ++++++++++++++++++++--------- src/script/squirrel.hpp | 15 ++++++++++----- 4 files changed, 44 insertions(+), 21 deletions(-) (limited to 'src') 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 */ @@ -548,12 +553,23 @@ 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. @@ -248,11 +253,6 @@ public: */ bool HasScriptCrashed(); - /** - * Reset the crashed status. - */ - void ResetCrashed(); - /** * Set the script status to crashed. */ @@ -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 */ -- cgit v1.2.3-54-g00ecf