diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-10-25 21:23:38 +0000 |
---|---|---|
committer | andreas <andreas@daaaf23c-2e50-4459-9457-1e69db5a47bf> | 2014-10-25 21:23:38 +0000 |
commit | 250d6a4dbe61b6798cd090abeabdc0ece8237dd3 (patch) | |
tree | 05a15d388c8b8444b6ddd4c6806cd4f66169c2a0 /src/core/script | |
parent | dbb94be50c67ce2d4a132b0811c2a8dac825b49b (diff) |
some restructuring, added first version of the mozjs plugin
git-svn-id: file:///var/local/svn/basicwriter@78 daaaf23c-2e50-4459-9457-1e69db5a47bf
Diffstat (limited to 'src/core/script')
-rw-r--r-- | src/core/script/Object.hpp | 2 | ||||
-rw-r--r-- | src/core/script/ScriptEngine.cpp | 32 | ||||
-rw-r--r-- | src/core/script/ScriptEngine.hpp | 46 |
3 files changed, 33 insertions, 47 deletions
diff --git a/src/core/script/Object.hpp b/src/core/script/Object.hpp index fafe632..350f800 100644 --- a/src/core/script/Object.hpp +++ b/src/core/script/Object.hpp @@ -27,6 +27,8 @@ namespace ousia { namespace script { +// TODO: Check names for being proper identifiers! + /** * The Property struct represents an object property with corresponding getter * and setter function. diff --git a/src/core/script/ScriptEngine.cpp b/src/core/script/ScriptEngine.cpp index f34ccea..99f2d3f 100644 --- a/src/core/script/ScriptEngine.cpp +++ b/src/core/script/ScriptEngine.cpp @@ -23,21 +23,27 @@ namespace ousia { namespace script { -ScriptEngineException::ScriptEngineException(int line, int col, - const std::string &msg) : - line(line), col(col), - msg(std::to_string(line) + ":" + std::to_string(col) + " " + msg) {} +/* Class ScriptEngineException */ -ScriptEngineException::ScriptEngineException(const std::string &msg) : - line(-1), col(-1), msg(msg) {} +ScriptEngineException::ScriptEngineException(int line, int col, + const std::string &msg) + : line(line), + col(col), + msg(std::to_string(line) + ":" + std::to_string(col) + " " + msg) +{ +} -const char* ScriptEngineException::what() const noexcept +ScriptEngineException::ScriptEngineException(const std::string &msg) + : line(-1), col(-1), msg(msg) { - return msg.c_str(); } +const char *ScriptEngineException::what() const noexcept { return msg.c_str(); } + +/* Class ScriptEngineFactory */ + void ScriptEngineFactory::registerScriptEngine(const std::string &name, - ScriptEngine *engine) + ScriptEngine *engine) { registry[name] = engine; } @@ -47,10 +53,8 @@ bool ScriptEngineFactory::unregisterScriptEngine(const std::string &name) return registry.erase(name) > 0; } -/* Class ScriptEngineFactory */ - -ScriptEngineScope* ScriptEngineFactory::createScope( - const std::string &name) const +ScriptEngineScope *ScriptEngineFactory::createScope( + const std::string &name) const { auto it = registry.find(name); if (it != registry.end()) { @@ -58,8 +62,6 @@ ScriptEngineScope* ScriptEngineFactory::createScope( } return nullptr; } - - } } diff --git a/src/core/script/ScriptEngine.hpp b/src/core/script/ScriptEngine.hpp index 5443460..2341beb 100644 --- a/src/core/script/ScriptEngine.hpp +++ b/src/core/script/ScriptEngine.hpp @@ -35,7 +35,6 @@ namespace script { * in the script engine. */ class ScriptEngineException : public std::exception { - public: /** * Line and column at which the exception occured. Set to -1 if the error @@ -67,18 +66,15 @@ public: /** * Returns the error message. */ - virtual const char* what() const noexcept override; - + virtual const char *what() const noexcept override; }; /** * The ScriptEngineScope class represents an execution scope -- an execution - * scope is the base class + * scope is the base class */ class ScriptEngineScope { - private: - /** * Helper used to check the given identifiers for their validity. * @@ -93,29 +89,27 @@ private: } protected: - /** - * Implementation of the @see run function. + * Implementation of the run function. */ virtual Variant doRun(const std::string &code) = 0; /** - * Implementation of the @see setVariable function. + * Implementation of the setVariable function. */ virtual void doSetVariable(const std::string &name, const Variant &val, - bool constant) = 0; + bool constant) = 0; /** - * Implementation of the @see getVariable function. + * Implementation of the getVariable function. */ virtual Variant doGetVariable(const std::string &name) = 0; public: - /** * Virtual destructor. Must be overwritten by implementing classes. */ - virtual ~ScriptEngineScope() {}; + virtual ~ScriptEngineScope(){}; /** * Runs the given code in the excution context. @@ -124,10 +118,7 @@ public: * @return a variant containg the result of the executed code. * @throws ScriptEngineException if an error occured during code execution. */ - Variant run(const std::string &code) - { - return doRun(code); - } + Variant run(const std::string &code) { return doRun(code); } /** * Sets the value of a variable in the scope with the given name. @@ -140,7 +131,7 @@ public: * @throws ScriptEngineException if name is not a well-formed identifier. */ void setVariable(const std::string &name, const Variant &val, - bool constant = false) + bool constant = false) { checkIdentifier(name); doSetVariable(name, val, constant); @@ -159,7 +150,6 @@ public: checkIdentifier(name); return doGetVariable(name); } - }; /** @@ -168,14 +158,12 @@ public: * function which creates an execution scope. */ class ScriptEngine { - public: /** * Requests an execution scope from the script engine implementation. The * calling code is responsible for disposing the returned pointer. */ - virtual ScriptEngineScope* createScope() const = 0; - + virtual ScriptEngineScope *createScope() = 0; }; /** @@ -184,16 +172,14 @@ public: * language. */ class ScriptEngineFactory { - private: /** * Internal map between the script language name and the actual script * engine instance. */ - std::map<std::string, ScriptEngine*> registry; + std::map<std::string, ScriptEngine *> registry; public: - /** * Registers a ScriptEngine instance for a new scripting language. * @@ -206,7 +192,7 @@ public: /** * Removes a script engine from the registry. * - * @param name is the name of the script engine that + * @param name is the name of the script engine that */ bool unregisterScriptEngine(const std::string &name); @@ -218,16 +204,12 @@ public: * is being created. * @return a pointer to the new execution scope or null if a script engine * with the given name does not exist. The caller of this function is - * responsible + * responsible */ - ScriptEngineScope* createScope(const std::string &name) const; - + ScriptEngineScope *createScope(const std::string &name) const; }; - } } - #endif /* _OUSIA_SCRIPT_ENGINE_HPP_ */ - |