mirror of https://github.com/OpenTTD/OpenTTD
(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
parent
105306609f
commit
a6b4e59963
|
@ -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;
|
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->ResetEngine();
|
||||||
this->engine->ResetCrashed();
|
|
||||||
this->engine->LoadScript(filename);
|
this->engine->LoadScript(filename);
|
||||||
|
|
||||||
return true;
|
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)
|
void ScriptScanner::Initialize(const char *name)
|
||||||
{
|
{
|
||||||
this->engine = new Squirrel(name);
|
this->engine = new Squirrel(name);
|
||||||
|
|
||||||
/* Mark this class as global pointer */
|
|
||||||
this->engine->SetGlobalPointer(this);
|
|
||||||
|
|
||||||
this->RegisterAPI(this->engine);
|
|
||||||
this->RescanDir();
|
this->RescanDir();
|
||||||
|
|
||||||
this->engine->ResetCrashed();
|
this->ResetEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptScanner::~ScriptScanner()
|
ScriptScanner::~ScriptScanner()
|
||||||
|
|
|
@ -128,6 +128,10 @@ protected:
|
||||||
*/
|
*/
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the engine to ensure a clean environment for further steps.
|
||||||
|
*/
|
||||||
|
void ResetEngine();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SCRIPT_SCANNER_HPP */
|
#endif /* SCRIPT_SCANNER_HPP */
|
||||||
|
|
|
@ -335,12 +335,17 @@ bool Squirrel::CreateClassInstance(const char *class_name, void *real_instance,
|
||||||
}
|
}
|
||||||
|
|
||||||
Squirrel::Squirrel(const char *APIName) :
|
Squirrel::Squirrel(const char *APIName) :
|
||||||
global_pointer(NULL),
|
|
||||||
print_func(NULL),
|
|
||||||
crashed(false),
|
|
||||||
overdrawn_ops(0),
|
|
||||||
APIName(APIName)
|
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);
|
this->vm = sq_open(1024);
|
||||||
|
|
||||||
/* Handle compile-errors ourself, so we can display it nicely */
|
/* Handle compile-errors ourself, so we can display it nicely */
|
||||||
|
@ -548,12 +553,23 @@ bool Squirrel::LoadScript(const char *script)
|
||||||
}
|
}
|
||||||
|
|
||||||
Squirrel::~Squirrel()
|
Squirrel::~Squirrel()
|
||||||
|
{
|
||||||
|
this->Uninitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Squirrel::Uninitialize()
|
||||||
{
|
{
|
||||||
/* Clean up the stuff */
|
/* Clean up the stuff */
|
||||||
sq_pop(this->vm, 1);
|
sq_pop(this->vm, 1);
|
||||||
sq_close(this->vm);
|
sq_close(this->vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Squirrel::Reset()
|
||||||
|
{
|
||||||
|
this->Uninitialize();
|
||||||
|
this->Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
void Squirrel::InsertResult(bool result)
|
void Squirrel::InsertResult(bool result)
|
||||||
{
|
{
|
||||||
sq_pushbool(this->vm, result);
|
sq_pushbool(this->vm, result);
|
||||||
|
@ -587,11 +603,6 @@ bool Squirrel::HasScriptCrashed()
|
||||||
return this->crashed;
|
return this->crashed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squirrel::ResetCrashed()
|
|
||||||
{
|
|
||||||
this->crashed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Squirrel::CrashOccurred()
|
void Squirrel::CrashOccurred()
|
||||||
{
|
{
|
||||||
this->crashed = true;
|
this->crashed = true;
|
||||||
|
|
|
@ -41,6 +41,11 @@ private:
|
||||||
*/
|
*/
|
||||||
const char *GetAPIName() { return this->APIName; }
|
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:
|
protected:
|
||||||
/**
|
/**
|
||||||
* The CompileError handler.
|
* The CompileError handler.
|
||||||
|
@ -248,11 +253,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool HasScriptCrashed();
|
bool HasScriptCrashed();
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the crashed status.
|
|
||||||
*/
|
|
||||||
void ResetCrashed();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the script status to crashed.
|
* Set the script status to crashed.
|
||||||
*/
|
*/
|
||||||
|
@ -267,6 +267,11 @@ public:
|
||||||
* How many operations can we execute till suspension?
|
* How many operations can we execute till suspension?
|
||||||
*/
|
*/
|
||||||
SQInteger GetOpsTillSuspend();
|
SQInteger GetOpsTillSuspend();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completely reset the engine; start from scratch.
|
||||||
|
*/
|
||||||
|
void Reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SQUIRREL_HPP */
|
#endif /* SQUIRREL_HPP */
|
||||||
|
|
Loading…
Reference in New Issue