diff options
author | chai <chaifix@163.com> | 2020-11-15 09:59:32 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-11-15 09:59:32 +0800 |
commit | d2e4b2839bc7ce874370ff4c52dcfdadf666ff52 (patch) | |
tree | b83e34c2d66cf80b94af5c9a420b6c9c206c138c /Runtime/Scripting/LuaBindUtility.h | |
parent | 64f89347883d519b202711a11d2ea175bd80be37 (diff) |
+lua binding
Diffstat (limited to 'Runtime/Scripting/LuaBindUtility.h')
-rw-r--r-- | Runtime/Scripting/LuaBindUtility.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Runtime/Scripting/LuaBindUtility.h b/Runtime/Scripting/LuaBindUtility.h new file mode 100644 index 0000000..0643315 --- /dev/null +++ b/Runtime/Scripting/LuaBindUtility.h @@ -0,0 +1,66 @@ +#ifndef __LUA_BIND_UTILITY_H__ +#define __LUA_BIND_UTILITY_H__ + +// 导出native接口 + +/// RegisterLuaBindClass 注册类的方法和成员,比如枚举、常量等到class table LuaBindGetFactoryName 获得工厂的类名, +/// 同时用来避免注册时错误注册为了singleton,通过编译时报错避免 +#define LUA_BIND_DECL_FACTORY(type, ...) \ + friend class LuaBind::LuaBindState; \ + friend class LuaBind::LuaBindNativeClass<type,##__VA_ARGS__>; \ + static void RegisterLuaBindClass(LuaBind::LuaBindState&); \ + static void RegisterLuaBindPostprocess(LuaBind::LuaBindState&); \ + static const char* GetLuaBindFactoryName() { return #type; };\ + static const char* GetLuaBindClassName() { return #type; };\ + static bool IsLuaBindClassSingleton() { return false; } + +/// 作为基类的抽象工厂类可以使用此宏,注册一个入口,在派生类的注册函数中调用,注册基类的这些方法。 +#define LUA_BIND_DECL_ABSTRACT_FACTORY() \ + static void RegisterLuaBindClass(LuaBind::LuaBindState&);\ + static void RegisterLuaBindPostprocess(LuaBind::LuaBindState&) + +/// RegisterLuaBindClass 注册类的方法和成员,比如枚举、常量等到class table LuaBindGetSingletonName 获得单例的类名 +#define LUA_BIND_DECL_SINGLETON(type, ...) \ + friend class LuaBind::LuaBindState; \ + friend class LuaBind::LuaBindNativeClass<type,##__VA_ARGS__>; \ + static void RegisterLuaBindClass(LuaBind::LuaBindState&); \ + static void RegisterLuaBindPostprocess(LuaBind::LuaBindState&); \ + static const char* GetLuaBindSingletonName() { return #type; }; \ + static const char* GetLuaBindClassName() { return #type; }; \ + static bool IsLuaBindClassSingleton() { return true; } + +#define LUA_BIND_DECL_METHOD(mtd) static int mtd(lua_State* L) + +#define LUA_BIND_DECL_ENUM(e, under_line_index) + +/// 标明方法实现的宏。上下文里有一个L。 +#define LUA_BIND_IMPL_METHOD(type, f) int type::f(lua_State* L) + +/// 由应用程序实现的两个接口。上下文里有一个state。 +#define LUA_BIND_REGISTRY(type) void type::RegisterLuaBindClass(LuaBind::LuaBindState& state) +#define LUA_BIND_POSTPROCESS(type) void type::RegisterLuaBindPostprocess(LuaBind::LuaBindState& state) + +/// 用来注册的宏。之前这里忘了用可变宏,导致没有luaclastable ref没有注册对。 +#define LUA_BIND_REGISTER_FACTORY(state, param) state.RegisterFactory<param>() +#define LUA_BIND_REGISTER_SINGLETON(state, param) state.RegisterSingleton<param>() +#define LUA_BIND_REGISTER_ABSTRACT_FACTORY(state, type) type::RegisterLuaBindPostprocess(state) +#define LUA_BIND_REGISTER_METHODS(state, ...) \ + do{ \ + luaL_Reg __m[] = {__VA_ARGS__,{0, 0}}; \ + state.RegisterMethods(__m); \ + }while(0) +#define LUA_BIND_REGISTER_ENUM(state, name, ...) \ + do{ \ + LuaBind::LuaBindEnum __e[] = {__VA_ARGS__,{0, 0}}; \ + state.RegisterEnum(name, __e); \ + }while(0) + +#define LUA_BIND_PREPARE(L, T) \ + LUA_BIND_STATE(L); \ + T* self = state.GetUserdata<T>(1); + +#define LUA_BIND_INHERIT(state, type) type::RegisterLuaBindClass(state) + +#define luaxport private + +#endif
\ No newline at end of file |