From ecd7883521cbde02f4f1a6b23a7b3b601c32dbef Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 29 Jul 2019 09:06:09 +0800 Subject: *misc --- source/external/Luax/luax_class.hpp | 79 +------------------------------------ source/external/Luax/luax_utility.h | 66 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 78 deletions(-) create mode 100644 source/external/Luax/luax_utility.h (limited to 'source/external') diff --git a/source/external/Luax/luax_class.hpp b/source/external/Luax/luax_class.hpp index fd9f75a..12eb268 100644 --- a/source/external/Luax/luax_class.hpp +++ b/source/external/Luax/luax_class.hpp @@ -13,88 +13,13 @@ #include "luax_memberref.h" #include "luax_cfunctions.h" #include "luax_watchdog.h" +#include "luax_utility.h" namespace Luax { class LuaxVM; -/// -/// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table -/// LuaxGetFactoryName 获得工厂的类名,同时用来避免注册时错误注册为了singleton,通过编译 -/// 时报错避免 -/// -#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; };\ - static const char* GetLuaxClassName() { return #type; };\ - static bool IsLuaxClassSingleton() { return false; } - -/// -/// 作为基类的抽象工厂类可以使用此宏,注册一个入口,在派生类的注册函数中调用,注册基类的这些 -/// 方法。 -/// -#define LUAX_DECL_ABSTRACT_FACTORY() \ - static void RegisterLuaxClass(Luax::LuaxState&);\ - static void RegisterLuaxPostprocess(Luax::LuaxState&) - -/// -/// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table -/// LuaxGetSingletonName 获得单例的类名 -/// -#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; }; \ - static const char* GetLuaxClassName() { return #type; }; \ - static bool IsLuaxClassSingleton() { return true; } - -#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State* L) - -#define LUAX_DECL_ENUM(e, under_line_index) - -/// -/// 标明方法实现的宏。上下文里有一个L。 -/// -#define LUAX_IMPL_METHOD(type, f) int type::f(lua_State* L) - -/// -/// 由应用程序实现的两个接口。上下文里有一个state。 -/// -#define LUAX_REGISTRY(type) void type::RegisterLuaxClass(Luax::LuaxState& state) -#define LUAX_POSTPROCESS(type) void type::RegisterLuaxPostprocess(Luax::LuaxState& state) - -/// -/// 用来注册的宏。之前这里忘了用可变宏,导致没有luaclastable ref没有注册对。 -/// -#define LUAX_REGISTER_FACTORY(state, param) state.RegisterFactory() -#define LUAX_REGISTER_SINGLETON(state, param) state.RegisterSingleton() -#define LUAX_REGISTER_ABSTRACT_FACTORY(state, type) type::RegisterLuaxPostprocess(state) -#define LUAX_REGISTER_METHODS(state, ...) \ - do{ \ - luaL_Reg __m[] = {__VA_ARGS__,{0, 0}}; \ - state.RegisterMethods(__m); \ - }while(0) -#define LUAX_REGISTER_ENUM(state, name, ...) \ - do{ \ - Luax::LuaxEnum __e[] = {__VA_ARGS__,{0, 0}}; \ - state.RegisterEnum(name, __e); \ - }while(0) - -#define LUAX_PREPARE(L, T) \ - LUAX_STATE(L); \ - T* self = state.GetUserdata(1); - -#define LUAX_INHERIT(state, type) type::RegisterLuaxClass(state) - -#define luaxport private - - /// /// 虚基类,为了实现多态。需要访问下面这些接口的外部基类需要虚继承此类,之后再派生链中就会 /// 调用对应实体的方法。注意继承此类时不能实现下面的方法,实现在LuaxNativeClass中,实现会 @@ -244,9 +169,7 @@ namespace Luax /// LuaxWeakRef mUserdata; - /// /// 通过后才能删除 - /// LuaxWatchDog mWatchDog; #if LUAX_PROFILER diff --git a/source/external/Luax/luax_utility.h b/source/external/Luax/luax_utility.h new file mode 100644 index 0000000..79601e0 --- /dev/null +++ b/source/external/Luax/luax_utility.h @@ -0,0 +1,66 @@ +#ifndef __LUAX_UTILITY_H__ +#define __LUAX_UTILITY_H__ + +// 导出native接口 + +/// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table LuaxGetFactoryName 获得工厂的类名, +/// 同时用来避免注册时错误注册为了singleton,通过编译时报错避免 +#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; };\ + static const char* GetLuaxClassName() { return #type; };\ + static bool IsLuaxClassSingleton() { return false; } + +/// 作为基类的抽象工厂类可以使用此宏,注册一个入口,在派生类的注册函数中调用,注册基类的这些方法。 +#define LUAX_DECL_ABSTRACT_FACTORY() \ + static void RegisterLuaxClass(Luax::LuaxState&);\ + static void RegisterLuaxPostprocess(Luax::LuaxState&) + +/// RegisterLuaxClass 注册类的方法和成员,比如枚举、常量等到class table LuaxGetSingletonName 获得单例的类名 +#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; }; \ + static const char* GetLuaxClassName() { return #type; }; \ + static bool IsLuaxClassSingleton() { return true; } + +#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State* L) + +#define LUAX_DECL_ENUM(e, under_line_index) + +/// 标明方法实现的宏。上下文里有一个L。 +#define LUAX_IMPL_METHOD(type, f) int type::f(lua_State* L) + +/// 由应用程序实现的两个接口。上下文里有一个state。 +#define LUAX_REGISTRY(type) void type::RegisterLuaxClass(Luax::LuaxState& state) +#define LUAX_POSTPROCESS(type) void type::RegisterLuaxPostprocess(Luax::LuaxState& state) + +/// 用来注册的宏。之前这里忘了用可变宏,导致没有luaclastable ref没有注册对。 +#define LUAX_REGISTER_FACTORY(state, param) state.RegisterFactory() +#define LUAX_REGISTER_SINGLETON(state, param) state.RegisterSingleton() +#define LUAX_REGISTER_ABSTRACT_FACTORY(state, type) type::RegisterLuaxPostprocess(state) +#define LUAX_REGISTER_METHODS(state, ...) \ + do{ \ + luaL_Reg __m[] = {__VA_ARGS__,{0, 0}}; \ + state.RegisterMethods(__m); \ + }while(0) +#define LUAX_REGISTER_ENUM(state, name, ...) \ + do{ \ + Luax::LuaxEnum __e[] = {__VA_ARGS__,{0, 0}}; \ + state.RegisterEnum(name, __e); \ + }while(0) + +#define LUAX_PREPARE(L, T) \ + LUAX_STATE(L); \ + T* self = state.GetUserdata(1); + +#define LUAX_INHERIT(state, type) type::RegisterLuaxClass(state) + +#define luaxport private + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0