diff options
author | chai <chaifix@163.com> | 2019-03-25 23:46:59 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-25 23:46:59 +0800 |
commit | 03b3b8ae80559745f98ef94569b421adddeb441f (patch) | |
tree | 7bf46892fef7453d4c25172333bd4fbddb29ee16 /source/3rd-party/Luax/luax_class.hpp | |
parent | 82956beb1fe17e1226327638c8ab22b5f5adfc1d (diff) |
*misc
Diffstat (limited to 'source/3rd-party/Luax/luax_class.hpp')
-rw-r--r-- | source/3rd-party/Luax/luax_class.hpp | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index 539ff1a..3d7ede6 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -62,28 +62,47 @@ namespace Luax state.RegisterEnum(name, __e); \ }while(0) +#define LUAX_PREPARE(L, T) \ + LUAX_STATE(L); \ + T* self = state.GetUserdata<T>(1); + + /// + /// ࣬Ϊʵֶ̬ҪЩӿڵⲿҪ̳д֮࣬оͻöӦʵķע̳д + /// ʱʵķʵLuaxNativeClassУʵֻᵼ¶ԡ + /// + class ILuaxNativeAccessor + { + public: + + /// + /// Աùʵref tableáȡ + /// + virtual bool PushLuaxMemberRef(LuaxState& state, int refID) { assert(false); return false; }; + + }; + /// /// Ҫ¶luanative classҪ̳дࡣͨluaʵҪȷüȷԣڶ߳Ҫȷͷš /// template<class T> - class LuaxNativeClass + class LuaxNativeClass : public virtual ILuaxNativeAccessor { public: + static bool IsTypeOf(ILuaxNativeAccessor); + /// - /// userdataΪkeyref tableuserdataһãάuserdataڡ + /// userdataΪkeyref tableuserdataһãάuserdataڡȽmember ref + /// ʵᱻαͬʵõƵЩʵ壬luaƵĵgc⡣ /// - template<class U> void LuaRetain(LuaxState& state, U* userdata); + template<class U> void LuaxRetain(LuaxState& state, U* userdata); /// /// userdataһref tableԳԻuserdata /// - template<class U> void LuaRelease(LuaxState& state, U* userdata); + template<class U> void LuaxRelease(LuaxState& state, U* userdata); - protected: - - LuaxNativeClass(); - virtual ~LuaxNativeClass(); + bool PushLuaxMemberRef(LuaxState& state, int refID) override; /// /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջһá @@ -92,12 +111,17 @@ namespace Luax bool PushLuaxMemberTable(LuaxState& state); bool PushLuaxRefTable(LuaxState& state); + protected: + /// /// Աùʵref tableáȡ /// - void SetMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx); - bool PushMemberRef(LuaxState& state, LuaxMemberRef& memRef); - void ClearMemberRef(LuaxState& state, LuaxMemberRef& memRef); + void SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx); + bool PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef); + void ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef); + + LuaxNativeClass(); + virtual ~LuaxNativeClass(); private: @@ -122,14 +146,16 @@ namespace Luax /// void BindToLua(LuaxState& state); - //------------------------------------------------------------------------------------------------------------ - /// - /// LuaxNativeClass<T>͵ʵ + /// class table͵С + /// + static LuaxStrongRef mClassTable; /// - static LuaxStrongRef mClassTable; // class table͵ - static LuaxStrongRef mSingletonRefTable; // ǵsingletonijԱԱ֤ᱻͨ - // ref tableijԱȫڵģֱ_LUAX_STRONGREF_TABLE + /// ǵsingletonùϵԱ֤ᱻͨref tableijԱȫڵģ + /// ֱ_LUAX_STRONGREF_TABLEuserdataLuaxRetain\LuaxReleasemember refʱʵͬ + /// Ǵref tableģtable_LUAX_STRONGREF_TABLE + /// + static LuaxStrongRef mSingletonRefTable; /// /// ͨuserdataõ: @@ -141,16 +167,12 @@ namespace Luax public: - //------------------------------------------------------------------------------------------------------------ // - LUAX_DECL_METHOD( l___tostring ); LUAX_DECL_METHOD( l_GetClass ); LUAX_DECL_METHOD( l_GetClassName ); - //------------------------------------------------------------------------------------------------------------ // - LUAX_DECL_METHOD( l___gc ); #if LUAX_ENABLE_NATIVE_EXTEND LUAX_DECL_METHOD( l_ExtendFactory ); @@ -158,7 +180,6 @@ namespace Luax LUAX_DECL_METHOD( l_GetRefTable ); LUAX_DECL_METHOD( l_New ); - //------------------------------------------------------------------------------------------------------------ // #if LUAX_ENABLE_NATIVE_EXTEND LUAX_DECL_METHOD( l_ExtendSingleton ); |