From 8d8c4ff1664625e7428d0d31cd798d9321680cb2 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 14 Mar 2019 09:08:07 +0800 Subject: *luax --- Source/3rdParty/Luax/luax_class.h | 145 -------------------------------------- 1 file changed, 145 deletions(-) delete mode 100644 Source/3rdParty/Luax/luax_class.h (limited to 'Source/3rdParty/Luax/luax_class.h') diff --git a/Source/3rdParty/Luax/luax_class.h b/Source/3rdParty/Luax/luax_class.h deleted file mode 100644 index bde9990..0000000 --- a/Source/3rdParty/Luax/luax_class.h +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef __LUAX_CLASS_H__ -#define __LUAX_CLASS_H__ - -#include - -#include "lua.hpp" -#include "luax_config.h" -#include "luax_state.h" -#include "luax_runtime.h" - -namespace Luax -{ - -#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State*) - - /// - /// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table - /// LuaxRegisterInterface 注册接口方法到interface table - /// LuaxGetFactoryName 获得工厂的类名,同时用来避免注册时错误注册为了singleton,通过编译时报错避免 - /// -#define LUAX_DECL_FACTORY(type) \ - static void RegisterLuaxClass(LuaxState&);\ - static void RegisterLuaxInterface(LuaxState&);\ - static const char* GetLuaxFactoryName() { return #type; };\ - static const char* GetLuaxClassName() { return #type; };\ - static bool IsLuaxClassSingleton() { return false; }; - - - /// - /// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table - /// LuaxGetSingletonName 获得单例的类名 - /// -#define LUAX_DECL_SINGLETON(type) \ - static void RegisterLuaxClass(LuaxState&); \ - static const char* GetLuaxSingletonName() { return #type; }; \ - static const char* GetLuaxClassName() { return #type; }; \ - static bool IsLuaxClassSingleton() { return true; }; - - - /// - /// 需要暴露给lua的class需要继承此类。通过lua管理的实例要确保引用计数的正确性,在多个线程中需要确定不会误释放。 - /// - class LuaxClass - { - public: - - void Retain(); - void Release(); - - protected: - - LuaxClass(); - virtual ~LuaxClass(); - - /// - /// 将userdata push到栈顶,如果没有初始化mUserdata,初始化设置好元表并把初始化好的userdata留在栈顶。 - /// - bool PushLuaUserdata(LuaxState& state); - - //------------------------------------------------------------------------------------------------------------ - - /// - /// 对类的reftable的管理 - /// - void Ref(); - - private: - - friend class LuaxState; - - template static void RegisterLuaxClass(LuaxState& state); - template static void RegisterLuaxFactoryClass(LuaxState& state); - template static void RegisterLuaxInterface(LuaxState& state); - template static void RegisterLuaxSingletonClass(LuaxState& state); - - /// - /// 屏蔽取地址运算符,如果需要地址,只能通过在堆上创建实例得到。在栈上和静态区的变量不能取地址。保证引用计数的准确。如 - /// 果需要穿引用,使用引用传递而不是传递地址。 - /// - void* operator &(); - - /// - /// 绑定到state,如果本类是工厂 - /// - void BindFactoryToLua(LuaxState& state); - - /// - /// 绑定到state,如果本类是单例 - /// - void BindSingletonToLua(LuaxState& state); - - //------------------------------------------------------------------------------------------------------------ - - LuaxStrongRef mInterfaceTable; // interface table - LuaxStrongRef mClassTable; // class table - - /// - /// 引用计数,用来处理线程间共享 - /// - int mRC; - - /// - /// 确保析构函数只能通过Release调用的safer,这样只要继承了LuaxClass的类,如果使用delete直接析构,就会报错 - /// - bool mSafer; - - public: - - //------------------------------------------------------------------------------------------------------------ - // 公共内容 - - template LUAX_DECL_METHOD(l_GetClassName); - template LUAX_DECL_METHOD(l_GetClassName2); - - LUAX_DECL_METHOD(l_ToString); // __tostring - - //------------------------------------------------------------------------------------------------------------ - // 工厂类相关 - - LUAX_DECL_METHOD(l_GC); // __gc - - //------------------------------------------------------------------------------------------------------------ - // 单例类相关 - - }; - - /// - /// 在成员方法里创建LuaxState并对参数进行检查。 - /// -#define LUAX_SETUP(L, params) \ - LuaxRuntime& runtime = LuaxRuntime::Get(); \ - LuaxState& state = runtime[L].state; \ - if(!state.CheckParams(1, params)) return 0 - -#define LUAX_STATE(L) \ - LuaxState& state = LuaxRuntime::Get().GetLuaxState(L) - -#define LUAX_RUNTIME() \ - LuaxRuntime& runtime = LuaxRuntime::Get() - -#include "luax_class.inl" - -} - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0