diff options
| author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-20 22:46:55 +0100 |
|---|---|---|
| committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-21 07:29:13 +0100 |
| commit | 4559ca444daacfd02ebb05f1657148a2b4cf3d8b (patch) | |
| tree | 8410fe19f397e70d43a8542c6ba7339d61d9bc0e /src/scripting/script.h | |
| parent | ad1d58b795681cad74642c0f4818b66a3f869794 (diff) | |
Introduced Script::Context
This should allow to finally call functions to lua without having to care
about working around situations where a lua call causes a c++ call which
needs to call to lua again.
Tested against the source of tales repository data.
Diffstat (limited to 'src/scripting/script.h')
| -rw-r--r-- | src/scripting/script.h | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/src/scripting/script.h b/src/scripting/script.h index 8dee23a..574d1b9 100644 --- a/src/scripting/script.h +++ b/src/scripting/script.h @@ -27,6 +27,7 @@ #include <list> #include <string> #include <vector> +#include <stack> #include <sigc++/trackable.h> @@ -40,6 +41,15 @@ class Entity; class Script : public sigc::trackable { public: + struct Context + { + MapComposite *map; + + Context() + : map(0) + {} + }; + /** * Defines a function that creates a Script instance. */ @@ -87,9 +97,12 @@ class Script : public sigc::trackable Thread(Script *script); virtual ~Thread(); + Context &getContext() + { return mContext; } + Script * const mScript; ThreadState mState; - MapComposite *mMap; + Context mContext; }; Script(); @@ -102,14 +115,18 @@ class Script : public sigc::trackable * * @param prog the program text to load * @param name the name of the text, used for error reporting + * @param context the context that is supposed to be used for loading */ - virtual void load(const char *prog, const char *name) = 0; + virtual void load(const char *prog, + const char *name, + const Context &context = Context()) = 0; /** * Loads a text file into script context and executes its global * statements. */ - virtual bool loadFile(const std::string &); + virtual bool loadFile(const std::string &, + const Context &context = Context()); /** * Loads a chunk of text and considers it as an NPC handler. This @@ -119,7 +136,8 @@ class Script : public sigc::trackable int id, ManaServ::BeingGender gender, int x, int y, - const char *); + const char *, + MapComposite *map); /** * Called every tick for the script to manage its data. @@ -174,9 +192,17 @@ class Script : public sigc::trackable /** * Executes the function being prepared. + * @param context the context that is supposed to be used for executing * @return the value returned by the script. */ - virtual int execute() = 0; + virtual int execute(const Context &context = Context()) = 0; + + /** + * Executes the function being prepared. + * @param the map which is set as context + * @return the value returned by the script. + */ + int execute(MapComposite *map); /** * Starts or resumes the current thread. Deletes the thread when it is @@ -207,16 +233,10 @@ class Script : public sigc::trackable { return mCurrentThread; } /** - * Sets associated map. - */ - void setMap(MapComposite *m) - { mMap = m; } - - /** - * Gets associated map. + * Returns the current context. */ - MapComposite *getMap() const - { return mMap; } + const Context *getContext() const + { return mContext; } virtual void processDeathEvent(Being *entity) = 0; @@ -231,9 +251,9 @@ class Script : public sigc::trackable protected: std::string mScriptFile; Thread *mCurrentThread; + const Context *mContext; private: - MapComposite *mMap; std::vector<Thread*> mThreads; static Ref mCreateNpcDelayedCallback; |
