summaryrefslogtreecommitdiff
path: root/source/3rd-party/Luax/luax_class.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/3rd-party/Luax/luax_class.hpp')
-rw-r--r--source/3rd-party/Luax/luax_class.hpp65
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 );