-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaContext.h
More file actions
117 lines (92 loc) · 5.16 KB
/
LuaContext.h
File metadata and controls
117 lines (92 loc) · 5.16 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2006-12 HumaNature Studios Inc.
#ifndef __LUAFUNCTIONCONTEXT_H__
#define __LUAFUNCTIONCONTEXT_H__
#include "CoreLuaScript.h"
#include "LuaGlobalProcedureBindings.h"
#include "LuaMemberFunctionBindings.h"
namespace core {
class LuaContext
: public CoreLuaScript
{
public:
LuaContext(lua_State* preAllocatedState = nullptr);
virtual ~LuaContext();
//////////////////////////////////////////////////////////////////////////
/// Global functions
//////////////////////////////////////////////////////////////////////////
template <typename ReturnType>
void bindGlobal(const std::string& name, ReturnType (*globalFunction)())
{
setBinding(name, new LuaGlobalProcedureBinding0<ReturnType>(globalFunction));
}
template<typename ReturnType, typename P0>
void bindGlobal(const std::string& name, ReturnType (*globalFunction)(P0))
{
setBinding(name, new LuaGlobalProcedureBinding1<ReturnType, P0>(globalFunction));
}
template<typename ReturnType, typename P0, typename P1>
void bindGlobal(const std::string& name, ReturnType (*globalFunction)(P0, P1))
{
setBinding(name, new LuaGlobalProcedureBinding2<ReturnType, P0, P1>(globalFunction));
}
template<typename ReturnType, typename P0, typename P1, typename P2>
void bindGlobal(const std::string& name, ReturnType (*globalFunction)(P0, P1, P2))
{
setBinding(name, new LuaGlobalProcedureBinding3<ReturnType, P0, P1, P2>(globalFunction));
}
template<typename ReturnType, typename P0, typename P1, typename P2, typename P3>
void bindGlobal(const std::string& name, ReturnType (*globalFunction)(P0, P1, P2, P3))
{
setBinding(name, new LuaGlobalProcedureBinding4<ReturnType, P0, P1, P2, P3>(globalFunction));
}
template<typename ReturnType, typename P0, typename P1, typename P2, typename P3, typename P4>
void bindGlobal(const std::string& name, ReturnType (*globalFunction)(P0, P1, P2, P3, P4))
{
setBinding(name, new LuaGlobalProcedureBinding5<ReturnType, P0, P1, P2, P3, P4>(globalFunction));
}
//////////////////////////////////////////////////////////////////////////
/// Member functions
//////////////////////////////////////////////////////////////////////////
// Object = type of the pointer
// FunctionClass = type of the function container, since this can be a base class, we need
// to clarify the template parameter
template<typename Object, typename FunctionClass, typename ReturnType>
void bind(const std::string& name, Object* object, ReturnType (FunctionClass::*memberFunction)())
{
setBinding(name, new LuaMemberFunctionBinding0<Object, ReturnType>(object, memberFunction));
}
template<typename Object, typename FunctionClass, typename P0, typename ReturnType>
void bind(const std::string& name, Object* object, ReturnType (FunctionClass::*memberFunction)(P0))
{
setBinding(name, new LuaMemberFunctionBinding1<Object, P0, ReturnType>(object, memberFunction));
}
template<typename Object, typename FunctionClass, typename P0, typename P1, typename ReturnType>
void bind(const std::string& name, Object* object, ReturnType (FunctionClass::*memberFunction)(P0, P1))
{
setBinding(name, new LuaMemberFunctionBinding2<Object, P0, P1, ReturnType>(object, memberFunction));
}
template<typename Object, typename FunctionClass, typename P0, typename P1, typename P2, typename ReturnType>
void bind(const std::string& name, Object* object, ReturnType (FunctionClass::*memberFunction)(P0, P1, P2))
{
setBinding(name, new LuaMemberFunctionBinding3<Object, P0, P1, P2, ReturnType>(object, memberFunction));
}
template<typename Object, typename FunctionClass, typename P0, typename P1, typename P2, typename P3, typename ReturnType>
void bind(const std::string& name, Object* object, ReturnType (FunctionClass::*memberFunction)(P0, P1, P2, P3))
{
setBinding(name, new LuaMemberFunctionBinding4<Object, P0, P1, P2, P3, ReturnType>(object, memberFunction));
}
template<typename Object, typename FunctionClass, typename P0, typename P1, typename P2, typename P3, typename P4, typename ReturnType>
void bind(const std::string& name, Object* object, ReturnType (FunctionClass::*memberFunction)(P0, P1, P2, P3, P4))
{
setBinding(name, new LuaMemberFunctionBinding5<Object, P0, P1, P2, P3, P4, ReturnType>(object, memberFunction));
}
void unbind(const std::string& name);
void call(const std::string& name);
protected:
typedef std::map<std::string, LuaFunctionBinding*> BindingMap;
BindingMap mBindings;
void setBinding(const std::string& name, LuaFunctionBinding* binding);
static int luaEntryFunction(lua_State* L);
};
} // namespace core
#endif // __LUAFUNCTIONCONTEXT_H__