implemented local script execution

This commit is contained in:
Marc Zinnschlag 2010-07-02 18:08:00 +02:00
parent 8e2732c60e
commit 474b412b47
7 changed files with 147 additions and 13 deletions

View file

@ -1,8 +1,6 @@
#include "scriptmanager.hpp"
#include <components/compiler/scanner.hpp>
#include <cassert>
#include <iostream>
#include <sstream>
@ -11,6 +9,12 @@
#include <components/esm/loadscpt.hpp>
#include <components/esm_store/store.hpp>
#include <components/compiler/scanner.hpp>
#include <components/interpreter/installopcodes.hpp>
#include <components/interpreter/interpreter.hpp>
namespace MWScript
{
ScriptManager::ScriptManager (const ESMS::ESMStore& store, bool verbose,
@ -70,8 +74,7 @@ namespace MWScript
return false;
}
void ScriptManager::run (const std::string& name/*,
Interpreter::Context& interpreterContext*/, Locals& locals)
void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext)
{
// compile script
std::map<std::string, std::vector<Interpreter::Type_Code> >::iterator iter =
@ -92,7 +95,18 @@ namespace MWScript
}
// execute script
if (!iter->second.empty())
try
{
Interpreter::Interpreter interpreter (interpreterContext);
Interpreter::installOpcodes (interpreter);
interpreter.run (&iter->second[0], iter->second.size());
}
catch (...)
{
std::cerr << "exeution of script " << name << " failed." << std::endl;
iter->second.clear(); // don't execute again.
}
}
}