summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/LuaBindUtility.h
blob: c5807c17a09cbce916e3dc466dc4e894b555230d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef __LUA_BIND_UTILITY_H__
#define __LUA_BIND_UTILITY_H__

// 导出native接口

// RegisterClass 注册类的方法和成员,比如枚举、常量等到class table GetNativeClassName 获得工厂的类名,
// 同时用来避免注册时错误注册为了singleton,通过编译时报错避免
#define LUA_BIND_DECL_CLASS(type, ...) \
	friend class       LuaBind::State; \
	friend class       LuaBind::NativeClass<type,##__VA_ARGS__>; \
	static void        RegisterClass(LuaBind::State&); \
	static void        RegisterPostprocess(LuaBind::State&); \
	static const char* GetNativeClassName() { return #type; };
	//static const char* GetClassName() { return #type; };

// 作为基类的抽象工厂类可以使用此宏,注册一个入口,在派生类的注册函数中调用,注册基类的这些方法。
#define LUA_BIND_DECL_ABSTRACT_CLASS() \
	static void RegisterClass(::State&);\
	static void RegisterPostprocess(::State&)

#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::RegisterClass(LuaBind::State& state)
#define LUA_BIND_POSTPROCESS(type) void type::RegisterPostprocess(LuaBind::State& state)

// 用来注册的宏。之前这里忘了用可变宏,导致没有luaclastable ref没有注册对。
#define LUA_BIND_REGISTER_CLASS(state, param) state.RegisterNativeClass<param>()
#define LUA_BIND_REGISTER_ABSTRACT_CLASS(state, type) type::RegisterPostprocess(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{ \
	::Enum __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_CHECK(L, params)\
	if(!state.CheckParams(1, params)) return 0

#define LUA_BIND_INHERIT(state, type) type::RegisterClass(state)

#define luaxport private

#endif