summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/LuaBindUtility.h
blob: bf138e4af705154a8ee06d73f80eaf84b91e1877 (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
#ifndef __LUA_BIND_UTILITY_H__
#define __LUA_BIND_UTILITY_H__

// 导出native接口

// RegisterClass 注册类的方法和成员,比如枚举、常量等到class table GetNativeClassName 获得工厂的类名,
// 同时用来避免注册时错误注册为了singleton,通过编译时报错避免
// RegisterClass和win32的宏冲突,所以加个下划线
#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_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)) {\
		luaL_error(state, "Unexcepted parameters.");\
		return 0;\
	}

#define luaxport private

#endif