From d29f5f4aebd90b1e256967801b28a5990249b2e7 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 16 Mar 2019 19:29:23 +0800 Subject: *luax --- Source/3rdParty/Luax/luax_class.hpp | 44 ++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'Source/3rdParty/Luax/luax_class.hpp') diff --git a/Source/3rdParty/Luax/luax_class.hpp b/Source/3rdParty/Luax/luax_class.hpp index a76d501..539093c 100644 --- a/Source/3rdParty/Luax/luax_class.hpp +++ b/Source/3rdParty/Luax/luax_class.hpp @@ -5,6 +5,7 @@ #include "luax_config.h" #include "luax_ref.h" +#include "luax_memberref.h" namespace Luax { @@ -30,6 +31,7 @@ namespace Luax /// #define LUAX_DECL_SINGLETON(type) \ static void RegisterLuaxClass(Luax::LuaxState&); \ + static void RegisterLuaxPostprocess(Luax::LuaxState&); \ static const char* GetLuaxSingletonName() { return #type; }; \ static const char* GetLuaxClassName() { return #type; }; \ static bool IsLuaxClassSingleton() { return true; }; @@ -42,8 +44,15 @@ namespace Luax { public: - void Retain(); - void Release(); + /// + /// 将userdata作为key,在ref table里对userdata添加一个引用,以维持userdata的生命周期。 + /// + template void LuaRetain(LuaxState& state, U* userdata); + + /// + /// 对userdata减少一个引用在ref table里,以尝试回收userdata。 + /// + template void LuaRelease(LuaxState& state, U* userdata); protected: @@ -57,6 +66,13 @@ namespace Luax bool PushLuaxMemberTable(LuaxState& state); bool PushLuaxRefTable(LuaxState& state); + /// + /// 成员引用管理,在实例的ref table里。设置、取、清除 + /// + void SetMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx); + bool PushMemberRef(LuaxState& state, LuaxMemberRef& memRef); + void ClearMemberRef(LuaxState& state, LuaxMemberRef& memRef); + private: friend class LuaxState; @@ -80,7 +96,7 @@ namespace Luax void* operator &(); /// - /// 创建userdata,绑定实例到state,如果本类是工厂 + /// 创建userdata,绑定实例到state。 /// void BindToLua(LuaxState& state); @@ -102,30 +118,22 @@ namespace Luax /// LuaxWeakRef mUserdata; - /// - /// 引用计数,用来处理线程间共享 - /// - int mRC; - - /// - /// 确保析构函数只能通过Release调用的safer,这样只要继承了LuaxClass的类,如果使用delete直接析构,就会报错 - /// - bool mSafer; - public: //------------------------------------------------------------------------------------------------------------ // 公共内容 - LUAX_DECL_METHOD( l_GetClassName ); - LUAX_DECL_METHOD( l_GetInterfaceTable ); - LUAX_DECL_METHOD( l___tostring ); + LUAX_DECL_METHOD( l___tostring ); + LUAX_DECL_METHOD( l_GetClassName ); //------------------------------------------------------------------------------------------------------------ // 工厂类相关 - LUAX_DECL_METHOD( l_ExtendFactory ); - LUAX_DECL_METHOD( l___gc ); + LUAX_DECL_METHOD( l___gc ); + LUAX_DECL_METHOD( l_ExtendFactory ); + LUAX_DECL_METHOD( l_GetClass ); + LUAX_DECL_METHOD( l_GetInterfaceTable ); + LUAX_DECL_METHOD( l_GetRefTable ); //------------------------------------------------------------------------------------------------------------ // 单例类相关 -- cgit v1.1-26-g67d0