diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 0ea6c9040..2a93561fe 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -206,11 +206,12 @@ void OMW::Engine::go() mOgre.getScene()); // Create window manager - this manages all the MW-specific GUI windows - mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui()); + MWScript::registerExtensions (mExtensions); - mEnvironment.mSoundManager = new MWSound::SoundManager; + mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui(), mEnvironment, + mExtensions); - MWScript::registerExtensions (mExtensions); + mEnvironment.mSoundManager = new MWSound::SoundManager; mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, mEnvironment); diff --git a/apps/openmw/mwgui/console.hpp b/apps/openmw/mwgui/console.hpp index c4597b3b7..54ba50330 100644 --- a/apps/openmw/mwgui/console.hpp +++ b/apps/openmw/mwgui/console.hpp @@ -4,11 +4,70 @@ #include #include #include +#include + +#include +#include +#include +#include +#include +#include + +#include "../mwscript/compilercontext.hpp" namespace MWGui { - class Console : private OEngine::GUI::Layout + class Console : private OEngine::GUI::Layout, private Compiler::ErrorHandler { + private: + + MWScript::CompilerContext mCompilerContext; + + bool compile (const std::string& cmd) + { + try + { + std::istringstream input (cmd + '\n'); + + Compiler::Scanner scanner (*this, input, mCompilerContext.getExtensions()); + + Compiler::Locals locals; + Compiler::Literals literals; + std::vector code; + Compiler::LineParser parser (*this, mCompilerContext, locals, literals, code); + + scanner.scan (parser); + + return isGood(); + } + catch (const Compiler::SourceException&) + { + // error has already been reported via error handler + } + catch (const std::exception& error) + { + printError (std::string ("An exception has been thrown: ") + error.what()); + } + + return false; + } + + /// Report error to the user. + virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type) + { + std::ostringstream error; + error << "column " << loc.mColumn << " (" << loc.mLiteral << "):"; + + printError (error.str()); + printError ((type==ErrorMessage ? "error: " : "warning: ") + message); + } + + /// Report a file related error + virtual void report (const std::string& message, Type type) + { + printError ((type==ErrorMessage ? "error: " : "warning: ") + message); + } + public: MyGUI::EditPtr command; MyGUI::EditPtr history; @@ -20,8 +79,9 @@ namespace MWGui StringList::iterator current; std::string editString; - Console(int w, int h) - : Layout("openmw_console_layout.xml") + Console(int w, int h, MWWorld::Environment& environment, const Compiler::Extensions& extensions) + : Layout("openmw_console_layout.xml"), + mCompilerContext (MWScript::CompilerContext::Type_Console, environment) { setCoord(10,10, w-10, h/2); @@ -38,6 +98,9 @@ namespace MWGui history->setOverflowToTheLeft(true); history->setEditStatic(true); history->setVisibleVScroll(true); + + // compiler + mCompilerContext.setExtensions (&extensions); } void enable() @@ -130,14 +193,10 @@ namespace MWGui // Log the command print("#FFFFFF> " + cm + "\n"); - /* NOTE: This is where the console command should be - handled. - - The console command is in the string 'cm'. Output from the - command should be put back into the console with the - printOK() or printError() functions. - */ - printOK("OK - echoing line " + cm); + if (compile (cm)) + { + // TODO execute command + } command->setCaption(""); } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index d96c93e8e..e83e09650 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -7,7 +7,8 @@ using namespace MWGui; -WindowManager::WindowManager(MyGUI::Gui *_gui) +WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, + const Compiler::Extensions& extensions) : gui(_gui), mode(GM_Game), shown(GW_ALL), allowed(GW_ALL) { // Get size info from the Gui object @@ -19,7 +20,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui) menu = new MainMenu(w,h); map = new MapWindow(); stats = new StatsWindow(); - console = new Console(w,h); + console = new Console(w,h, environment, extensions); // The HUD is always on hud->setVisible(true); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index f95454aea..2246dbd9f 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -15,6 +15,16 @@ namespace MyGUI class Gui; } +namespace Compiler +{ + class Extensions; +} + +namespace MWWorld +{ + class Environment; +} + namespace MWGui { class HUD; @@ -91,7 +101,8 @@ namespace MWGui public: /// The constructor needs the main Gui object - WindowManager(MyGUI::Gui *_gui); + WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, + const Compiler::Extensions& extensions); virtual ~WindowManager(); void setMode(GuiMode newMode) diff --git a/libs/openengine b/libs/openengine index c04d72cbe..82a3c071e 160000 --- a/libs/openengine +++ b/libs/openengine @@ -1 +1 @@ -Subproject commit c04d72cbe380217c2d1d60f8a2c6e4810fe4c050 +Subproject commit 82a3c071e56f2df451618e1371424c39aa299690