diff options
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 |