From e47baca4f23db43ec91fbf64d5d06d7c0dbee495 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 6 Apr 2019 07:39:49 +0800 Subject: *misc --- source/3rd-party/Luax/luax_class.hpp | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'source/3rd-party/Luax/luax_class.hpp') diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index c41adbd..e6e0696 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -12,7 +12,7 @@ #include "luax_ref.h" #include "luax_memberref.h" #include "luax_cfunctions.h" -#include "luax_dog.h" +#include "luax_watchdog.h" namespace Luax { @@ -24,8 +24,9 @@ namespace Luax /// LuaxGetFactoryName 获得工厂的类名,同时用来避免注册时错误注册为了singleton,通过编译 /// 时报错避免 /// -#define LUAX_DECL_FACTORY(type) \ +#define LUAX_DECL_FACTORY(type, ...) \ friend class Luax::LuaxState; \ + friend class Luax::LuaxNativeClass; \ static void RegisterLuaxClass(Luax::LuaxState&); \ static void RegisterLuaxPostprocess(Luax::LuaxState&); \ static const char* GetLuaxFactoryName() { return #type; };\ @@ -44,8 +45,9 @@ namespace Luax /// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table /// LuaxGetSingletonName 获得单例的类名 /// -#define LUAX_DECL_SINGLETON(type) \ +#define LUAX_DECL_SINGLETON(type, ...) \ friend class Luax::LuaxState; \ + friend class Luax::LuaxNativeClass; \ static void RegisterLuaxClass(Luax::LuaxState&); \ static void RegisterLuaxPostprocess(Luax::LuaxState&); \ static const char* GetLuaxSingletonName() { return #type; }; \ @@ -114,13 +116,14 @@ namespace Luax virtual bool PushLuaxRefTable(LuaxState& state) = 0; /// - /// 被LuaxNativeClass实现。 + /// 被LuaxNativeClass实现。保持和释放native资源。 /// virtual void Retain() = 0; virtual void Release() = 0; }; + // TODO: 将公共部分提取出来,不要重复生成代码 //class LuaxNativeClassBase //{ //} @@ -139,12 +142,12 @@ namespace Luax /// 相比较member ref,这个用在实体会被多次被不同其他实体引用的情况,并频繁销毁这些实体, /// 避免lua频繁的调用gc检测。 /// - template void LuaxRetain(LuaxState& state, USERDATA* userdata); + template void LuaxRetain(LuaxState& state, DATATYPE* userdata); /// /// 对userdata减少一个引用在ref table里,以尝试回收userdata。 /// - template void LuaxRelease(LuaxState& state, USERDATA* userdata); + template void LuaxRelease(LuaxState& state, DATATYPE* userdata); /// /// 将userdata push到栈顶,如果没有初始化mUserdata,初始化设置好元表并把初始化好的 @@ -162,8 +165,8 @@ namespace Luax /// /// 这两个函数是native接口。 /// - void Retain() override; - void Release() override; + void Retain() override final; + void Release() override final; #if LUAX_PROFILER // 对堆上创建的实例进行delete保险检查 @@ -201,21 +204,18 @@ namespace Luax //------------------------------------------------------------------------------// // 公共内容 - LUAX_DECL_METHOD(__tostring); - LUAX_DECL_METHOD(_GetClass); - LUAX_DECL_METHOD(_GetClassName); - + static int __tostring (lua_State*); + static int _GetClass (lua_State*); + static int _GetClassName (lua_State*); + // 工厂类相关 - LUAX_DECL_METHOD(__gc); -#if LUAX_ENABLE_NATIVE_EXTEND - LUAX_DECL_METHOD(_ExtendFactory); -#endif - LUAX_DECL_METHOD(_GetRefTable); - LUAX_DECL_METHOD(_New); + static int __gc (lua_State*); + static int _GetRefTable (lua_State*); + static int _New (lua_State*); - // 单例类相关 #if LUAX_ENABLE_NATIVE_EXTEND - LUAX_DECL_METHOD(_ExtendSingleton); + static int _ExtendFactory (lua_State*); + static int _ExtendSingleton (lua_State*); #endif //--------------------------------------------------------------------------------// @@ -244,7 +244,7 @@ namespace Luax /// /// 通过后才能删除 /// - LuaxDog mWatchDog; + LuaxWatchDog mWatchDog; #if LUAX_PROFILER // 托管此对象的虚拟机 -- cgit v1.1-26-g67d0