-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLuaFunction.hpp
76 lines (60 loc) · 2.61 KB
/
LuaFunction.hpp
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
// Copyright � 2013 Tom Tondeur
//
// This file is part of LuaLink.
//
// LuaLink is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// LuaLink is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with LuaLink. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include <lua.hpp>
#include "TemplateUtil.h"
#include <map>
#include <vector>
#include <string>
namespace LuaLink
{
template<typename T> class LuaStaticMethod;
template<typename T> class LuaMethod;
template<typename T> class LuaClass;
class LuaFunction
{
public:
template<typename _RetType, typename... _ArgTypes>
// // Add a C++ member function to the appropriate lookup table
static void Register(_RetType(*pFunc)(_ArgTypes...), const char* name);
static int DefaultErrorHandling(lua_State* L, int narg);
private:
template<typename T> friend class LuaStaticMethod; //LuaStaticMethod uses the same function table as LuaFunction
friend class LuaScript; //LuaScript needs access to Commit, rather befriend LuaScript than expose Commit to everything
template<typename T> friend class LuaClass;
template<typename T> friend class LuaMethod;
// // Pushes all registered member functions to the Lua environment
static void Commit(lua_State* pLuaState);
// // Throws out all references to functions that are left over from previous commits
static void Release(void);
static int OverloadedErrorHandling(lua_State* L, int narg);
// CALLBACK WRAPPERS
// Tries out all overloads until it finds an overload that matches the arguments used in the Lua call
static int LuaFunctionDispatch(lua_State* L);
//Disable default constructor, destructor, copy constructor & assignment operator
LuaFunction(void) = delete;
~LuaFunction(void) = delete;
LuaFunction(const LuaFunction& src) = delete;
LuaFunction& operator=(const LuaFunction& src) = delete;
};
namespace detail {
typedef int(*WrapperDoubleArg)(lua_State*, void*, ArgErrorCbType);
typedef int(*WrapperSingleArg)(lua_State*);
template<typename _RetType, typename... _ArgTypes> struct FunctionWrapper;
}
}
#include "LuaFunction.inl"