mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-02 06:47:59 +03:00
deal with script execution from within a script (Fixes #2964)
(cherry picked from commit 8eb6d337d5
)
This commit is contained in:
parent
71077fda6a
commit
aa31704d5d
2 changed files with 55 additions and 11 deletions
|
@ -133,7 +133,34 @@ namespace Interpreter
|
|||
throw std::runtime_error (error.str());
|
||||
}
|
||||
|
||||
Interpreter::Interpreter()
|
||||
void Interpreter::begin()
|
||||
{
|
||||
if (mRunning)
|
||||
{
|
||||
mCallstack.push (mRuntime);
|
||||
mRuntime.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Interpreter::end()
|
||||
{
|
||||
if (mCallstack.empty())
|
||||
{
|
||||
mRuntime.clear();
|
||||
mRunning = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mRuntime = mCallstack.top();
|
||||
mCallstack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
Interpreter::Interpreter() : mRunning (false)
|
||||
{}
|
||||
|
||||
Interpreter::~Interpreter()
|
||||
|
@ -203,19 +230,29 @@ namespace Interpreter
|
|||
{
|
||||
assert (codeSize>=4);
|
||||
|
||||
mRuntime.configure (code, codeSize, context);
|
||||
begin();
|
||||
|
||||
int opcodes = static_cast<int> (code[0]);
|
||||
|
||||
const Type_Code *codeBlock = code + 4;
|
||||
|
||||
while (mRuntime.getPC()>=0 && mRuntime.getPC()<opcodes)
|
||||
try
|
||||
{
|
||||
Type_Code code = codeBlock[mRuntime.getPC()];
|
||||
mRuntime.setPC (mRuntime.getPC()+1);
|
||||
execute (code);
|
||||
mRuntime.configure (code, codeSize, context);
|
||||
|
||||
int opcodes = static_cast<int> (code[0]);
|
||||
|
||||
const Type_Code *codeBlock = code + 4;
|
||||
|
||||
while (mRuntime.getPC()>=0 && mRuntime.getPC()<opcodes)
|
||||
{
|
||||
Type_Code code = codeBlock[mRuntime.getPC()];
|
||||
mRuntime.setPC (mRuntime.getPC()+1);
|
||||
execute (code);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
end();
|
||||
throw;
|
||||
}
|
||||
|
||||
mRuntime.clear();
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue