forked from teamnwah/openmw-tes3coop
Issue #352: refactored script execution in console
This commit is contained in:
parent
90de02b901
commit
23f8595b87
2 changed files with 29 additions and 22 deletions
|
@ -175,6 +175,32 @@ namespace MWGui
|
||||||
print("#FF2222" + msg + "\n");
|
print("#FF2222" + msg + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Console::execute (const std::string& command)
|
||||||
|
{
|
||||||
|
// Log the command
|
||||||
|
print("#FFFFFF> " + command + "\n");
|
||||||
|
|
||||||
|
Compiler::Locals locals;
|
||||||
|
Compiler::Output output (locals);
|
||||||
|
|
||||||
|
if (compile (command + "\n", output))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ConsoleInterpreterContext interpreterContext (*this, mPtr);
|
||||||
|
Interpreter::Interpreter interpreter;
|
||||||
|
MWScript::installOpcodes (interpreter, mConsoleOnlyScripts);
|
||||||
|
std::vector<Interpreter::Type_Code> code;
|
||||||
|
output.getCode (code);
|
||||||
|
interpreter.run (&code[0], code.size(), interpreterContext);
|
||||||
|
}
|
||||||
|
catch (const std::exception& error)
|
||||||
|
{
|
||||||
|
printError (std::string ("An exception has been thrown: ") + error.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Console::keyPress(MyGUI::WidgetPtr _sender,
|
void Console::keyPress(MyGUI::WidgetPtr _sender,
|
||||||
MyGUI::KeyCode key,
|
MyGUI::KeyCode key,
|
||||||
MyGUI::Char _char)
|
MyGUI::Char _char)
|
||||||
|
@ -236,28 +262,7 @@ namespace MWGui
|
||||||
current = command_history.end();
|
current = command_history.end();
|
||||||
editString.clear();
|
editString.clear();
|
||||||
|
|
||||||
// Log the command
|
execute (cm);
|
||||||
print("#FFFFFF> " + cm + "\n");
|
|
||||||
|
|
||||||
Compiler::Locals locals;
|
|
||||||
Compiler::Output output (locals);
|
|
||||||
|
|
||||||
if (compile (cm + "\n", output))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ConsoleInterpreterContext interpreterContext (*this, mPtr);
|
|
||||||
Interpreter::Interpreter interpreter;
|
|
||||||
MWScript::installOpcodes (interpreter, mConsoleOnlyScripts);
|
|
||||||
std::vector<Interpreter::Type_Code> code;
|
|
||||||
output.getCode (code);
|
|
||||||
interpreter.run (&code[0], code.size(), interpreterContext);
|
|
||||||
}
|
|
||||||
catch (const std::exception& error)
|
|
||||||
{
|
|
||||||
printError (std::string ("An exception has been thrown: ") + error.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
command->setCaption("");
|
command->setCaption("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,8 @@ namespace MWGui
|
||||||
/// Error message
|
/// Error message
|
||||||
void printError(const std::string &msg);
|
void printError(const std::string &msg);
|
||||||
|
|
||||||
|
void execute (const std::string& command);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void keyPress(MyGUI::WidgetPtr _sender,
|
void keyPress(MyGUI::WidgetPtr _sender,
|
||||||
|
|
Loading…
Reference in a new issue