From 69f7d1bd745ed5680b9bc4e3cfdd882ff2a5ad26 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Mar 2019 22:18:14 +0800 Subject: +threading --- source/3rd-party/Luax/luax_class.hpp | 4 ++++ source/3rd-party/Luax/luax_config.h | 4 ++-- source/3rd-party/Luax/luax_state.h | 37 ++++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) (limited to 'source/3rd-party/Luax') diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index af52b5f..cfac2a5 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -81,6 +81,10 @@ namespace Luax /// virtual bool PushLuaxMemberRef(LuaxState& state, int refID) { assert(false); return false; }; + virtual bool PushLuaxUserdata(LuaxState& state) { assert(false); return false; }; + virtual bool PushLuaxMemberTable(LuaxState& state) { assert(false); return false; }; + virtual bool PushLuaxRefTable(LuaxState& state) { assert(false); return false; }; + }; /// diff --git a/source/3rd-party/Luax/luax_config.h b/source/3rd-party/Luax/luax_config.h index d95ae8b..0ace00b 100644 --- a/source/3rd-party/Luax/luax_config.h +++ b/source/3rd-party/Luax/luax_config.h @@ -52,8 +52,8 @@ namespace Luax #define LUAX_ENABLE_NATIVE_EXTEND 0 -#define LUAX_ENABLE_PLAIN_CLASS 1 -#define LUAX_ENABLE_PLAIN_ENUM 1 +#define LUAX_ENABLE_PLAIN_CLASS 0 +#define LUAX_ENABLE_PLAIN_ENUM 0 } 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 -- cgit v1.1-26-g67d0