diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-09 21:30:42 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-10 18:07:29 +0100 |
commit | 78c912fb4007c3e5f0b43de02646772acb21ecf2 (patch) | |
tree | e45409ff061de75b0e4273763a87f5a25de6a65b /src/scripting/luascript.h | |
parent | 2fa7d1f39b24714ee6dc72b6b9e61ec5a1997724 (diff) | |
download | manaserv-78c912fb4007c3e5f0b43de02646772acb21ecf2.tar.gz manaserv-78c912fb4007c3e5f0b43de02646772acb21ecf2.tar.xz manaserv-78c912fb4007c3e5f0b43de02646772acb21ecf2.zip |
Moved the managing of NPC script coroutines into C++
Rather than wrapping NPC functions up in coroutines in the Lua side, they
are now managed on the C++ side as "script threads", which are essentially
the same thing.
The main purpose is that the server can now know whether any of these long
running script interactions are still active, which will probably be useful
when adding the ability to reload scripts.
Reviewed-by: Erik Schilling
Diffstat (limited to 'src/scripting/luascript.h')
-rw-r--r-- | src/scripting/luascript.h | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/scripting/luascript.h b/src/scripting/luascript.h index e26fd9e..57b8dc1 100644 --- a/src/scripting/luascript.h +++ b/src/scripting/luascript.h @@ -44,8 +44,12 @@ class LuaScript : public Script void load(const char *prog, const char *name); + Thread *newThread(); + void prepare(Ref function); + void prepareResume(Thread *thread); + void push(int); void push(const std::string &); @@ -56,25 +60,24 @@ class LuaScript : public Script int execute(); + bool resume(); + void assignCallback(Ref &function); - static void getQuestCallback(Character *, const std::string &, - const std::string &, Script *); + static void getQuestCallback(Character *, + const std::string &value, + Script *); - static void getPostCallback(Character *, const std::string &, - const std::string &, Script *); + static void getPostCallback(Character *, + const std::string &sender, + const std::string &letter, + Script *); void processDeathEvent(Being *thing); void processRemoveEvent(Thing *thing); - static void setQuestReplyCallback(Script *script) - { script->assignCallback(mQuestReplyCallback); } - - static void setPostReplyCallback(Script *script) - { script->assignCallback(mPostReplyCallback); } - static void setDeathNotificationCallback(Script *script) { script->assignCallback(mDeathNotificationCallback); } @@ -84,13 +87,24 @@ class LuaScript : public Script static const char registryKey; private: - lua_State *mState; + class LuaThread : public Thread + { + public: + LuaThread(LuaScript *script); + ~LuaThread(); + + lua_State *mState; + int mRef; + }; + + lua_State *mRootState; + lua_State *mCurrentState; int nbArgs; - static Ref mQuestReplyCallback; - static Ref mPostReplyCallback; static Ref mDeathNotificationCallback; static Ref mRemoveNotificationCallback; + + friend class LuaThread; }; static Script *LuaFactory() |