diff options
author | chai <chaifix@163.com> | 2019-03-27 22:18:14 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-27 22:18:14 +0800 |
commit | 69f7d1bd745ed5680b9bc4e3cfdd882ff2a5ad26 (patch) | |
tree | 729e563da8fea6cf8c5455f3afdb3c6ce0aecde4 /source/3rd-party/Luax/luax_state.h | |
parent | 66c5fdc564dd892ed265132d6c1378dbe3cebcee (diff) |
+threading
Diffstat (limited to 'source/3rd-party/Luax/luax_state.h')
-rw-r--r-- | source/3rd-party/Luax/luax_state.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/source/3rd-party/Luax/luax_state.h b/source/3rd-party/Luax/luax_state.h index 20d5189..e9c394a 100644 --- a/source/3rd-party/Luax/luax_state.h +++ b/source/3rd-party/Luax/luax_state.h @@ -193,13 +193,13 @@ namespace Luax //------------------------------------------------------------------------------------------------------------ - private: + protected: friend class LuaxContext; LuaxState(lua_State* state); LuaxState(const LuaxState& state); - ~LuaxState(); + virtual ~LuaxState(); /// /// ζLuaxStateĵַز @@ -258,6 +258,39 @@ namespace Luax #define LUAX_STATE(L) \ Luax::LuaxState& state = Luax::LuaxRuntime::Get().GetLuaxState(L) + //-------------------------------------------------------------------------------------------------------------- + + /// + /// ȷȫluaܹڵ֮صstack״̬ + /// + class LuaxScopedState + : public LuaxState + { + public: + LuaxScopedState(lua_State* state) + : LuaxState(state) + { + mRestoreTop = lua_gettop(mState); + } + LuaxScopedState(const LuaxState& state) + : LuaxState(state) + { + mRestoreTop = lua_gettop(mState); + } + ~LuaxScopedState() + { + if (mState) { + if (lua_gettop(mState) != mRestoreTop) { + lua_settop(mState, mRestoreTop); + } + } + } + private: + void* operator new(size_t); + int mRestoreTop; + + }; + } #endif
\ No newline at end of file |