diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-21 07:29:58 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-21 07:29:58 +0100 |
commit | f93b4c25242370982715e1a83c11e667b17f20af (patch) | |
tree | 07b392040bd858e205d12cf8f0977cf82fcc2c90 /src/scripting/luascript.cpp | |
parent | bcb3f283bda155bec33c83c4627f59acb4616dd8 (diff) | |
parent | 4559ca444daacfd02ebb05f1657148a2b4cf3d8b (diff) | |
download | manaserv-f93b4c25242370982715e1a83c11e667b17f20af.tar.gz manaserv-f93b4c25242370982715e1a83c11e667b17f20af.tar.bz2 manaserv-f93b4c25242370982715e1a83c11e667b17f20af.tar.xz manaserv-f93b4c25242370982715e1a83c11e667b17f20af.zip |
Merge branch 'master' into lpc2012
Diffstat (limited to 'src/scripting/luascript.cpp')
-rw-r--r-- | src/scripting/luascript.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp index f4ea39ac..e9f4492d 100644 --- a/src/scripting/luascript.cpp +++ b/src/scripting/luascript.cpp @@ -118,10 +118,12 @@ void LuaScript::push(const std::list<InventoryItem> &itemList) ++nbArgs; } -int LuaScript::execute() +int LuaScript::execute(const Context &context) { assert(nbArgs >= 0); + const Context *previousContext = mContext; + mContext = &context; const int tmpNbArgs = nbArgs; nbArgs = -1; @@ -139,7 +141,7 @@ int LuaScript::execute() } res = lua_tointeger(mCurrentState, -1); lua_pop(mCurrentState, 1); - setMap(0); + mContext = previousContext; return res; } @@ -148,7 +150,9 @@ bool LuaScript::resume() assert(nbArgs >= 0); assert(mCurrentThread); - setMap(mCurrentThread->mMap); + const Context *previousContext = mContext; + mContext = &mCurrentThread->getContext(); + const int tmpNbArgs = nbArgs; nbArgs = -1; #if LUA_VERSION_NUM < 502 @@ -156,7 +160,6 @@ bool LuaScript::resume() #else int result = lua_resume(mCurrentState, NULL, tmpNbArgs); #endif - setMap(0); if (result == 0) // Thread is done { @@ -181,6 +184,7 @@ bool LuaScript::resume() } lua_settop(mCurrentState, 0); + mContext = previousContext; const bool done = result != LUA_YIELD; if (done) @@ -215,8 +219,11 @@ void LuaScript::unref(Ref &ref) } } -void LuaScript::load(const char *prog, const char *name) +void LuaScript::load(const char *prog, const char *name, + const Context &context) { + const Context *previousContext = mContext; + mContext = &context; int res = luaL_loadbuffer(mRootState, prog, std::strlen(prog), name); if (res) { @@ -238,19 +245,18 @@ void LuaScript::load(const char *prog, const char *name) << lua_tostring(mRootState, -1)); lua_pop(mRootState, 1); } - setMap(0); + mContext = previousContext; } void LuaScript::processDeathEvent(Being *entity) { if (mDeathNotificationCallback.isValid()) { - setMap(entity->getMap()); prepare(mDeathNotificationCallback); push(entity); //TODO: get and push a list of creatures who contributed to killing the // being. This might be very interesting for scripting quests. - execute(); + Script::execute(entity->getMap()); } } @@ -258,12 +264,11 @@ void LuaScript::processRemoveEvent(Entity *entity) { if (mRemoveNotificationCallback.isValid()) { - setMap(entity->getMap()); prepare(mRemoveNotificationCallback); push(entity); //TODO: get and push a list of creatures who contributed to killing the // being. This might be very interesting for scripting quests. - execute(); + Script::execute(entity->getMap()); } } |