implemented script compiler for console

actorid
Marc Zinnschlag 15 years ago
parent 5ff9344a87
commit d72ed19460

@ -206,11 +206,12 @@ void OMW::Engine::go()
mOgre.getScene()); mOgre.getScene());
// Create window manager - this manages all the MW-specific GUI windows // 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, mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
mEnvironment); mEnvironment);

@ -4,11 +4,70 @@
#include <openengine/gui/layout.hpp> #include <openengine/gui/layout.hpp>
#include <list> #include <list>
#include <string> #include <string>
#include <vector>
#include <components/compiler/errorhandler.hpp>
#include <components/compiler/lineparser.hpp>
#include <components/compiler/scanner.hpp>
#include <components/compiler/locals.hpp>
#include <components/compiler/literals.hpp>
#include <components/compiler/exception.hpp>
#include "../mwscript/compilercontext.hpp"
namespace MWGui 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<Interpreter::Type_Code> 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: public:
MyGUI::EditPtr command; MyGUI::EditPtr command;
MyGUI::EditPtr history; MyGUI::EditPtr history;
@ -20,8 +79,9 @@ namespace MWGui
StringList::iterator current; StringList::iterator current;
std::string editString; std::string editString;
Console(int w, int h) Console(int w, int h, MWWorld::Environment& environment, const Compiler::Extensions& extensions)
: Layout("openmw_console_layout.xml") : Layout("openmw_console_layout.xml"),
mCompilerContext (MWScript::CompilerContext::Type_Console, environment)
{ {
setCoord(10,10, w-10, h/2); setCoord(10,10, w-10, h/2);
@ -38,6 +98,9 @@ namespace MWGui
history->setOverflowToTheLeft(true); history->setOverflowToTheLeft(true);
history->setEditStatic(true); history->setEditStatic(true);
history->setVisibleVScroll(true); history->setVisibleVScroll(true);
// compiler
mCompilerContext.setExtensions (&extensions);
} }
void enable() void enable()
@ -130,14 +193,10 @@ namespace MWGui
// Log the command // Log the command
print("#FFFFFF> " + cm + "\n"); print("#FFFFFF> " + cm + "\n");
/* NOTE: This is where the console command should be if (compile (cm))
handled. {
// TODO execute command
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);
command->setCaption(""); command->setCaption("");
} }

@ -7,7 +7,8 @@
using namespace MWGui; 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) : gui(_gui), mode(GM_Game), shown(GW_ALL), allowed(GW_ALL)
{ {
// Get size info from the Gui object // Get size info from the Gui object
@ -19,7 +20,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui)
menu = new MainMenu(w,h); menu = new MainMenu(w,h);
map = new MapWindow(); map = new MapWindow();
stats = new StatsWindow(); stats = new StatsWindow();
console = new Console(w,h); console = new Console(w,h, environment, extensions);
// The HUD is always on // The HUD is always on
hud->setVisible(true); hud->setVisible(true);

@ -15,6 +15,16 @@ namespace MyGUI
class Gui; class Gui;
} }
namespace Compiler
{
class Extensions;
}
namespace MWWorld
{
class Environment;
}
namespace MWGui namespace MWGui
{ {
class HUD; class HUD;
@ -91,7 +101,8 @@ namespace MWGui
public: public:
/// The constructor needs the main Gui object /// The constructor needs the main Gui object
WindowManager(MyGUI::Gui *_gui); WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment,
const Compiler::Extensions& extensions);
virtual ~WindowManager(); virtual ~WindowManager();
void setMode(GuiMode newMode) void setMode(GuiMode newMode)

@ -1 +1 @@
Subproject commit c04d72cbe380217c2d1d60f8a2c6e4810fe4c050 Subproject commit 82a3c071e56f2df451618e1371424c39aa299690
Loading…
Cancel
Save