summaryrefslogtreecommitdiffstats
blob: e3ad620161129f424a00a018fdf64a2a1ffb8cb2 (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
/*
 * Copyright (c) 2013 Remko Tronçon
 * Licensed under the GNU General Public License.
 * See the COPYING file for more information.
 */

#pragma once

#include <Swiften/Base/Override.h>
#include <lua.hpp>
#include <string>
#include <vector>

namespace Swift {
	namespace Lua {
		class FunctionRegistry {
			public:
				~FunctionRegistry();
				static FunctionRegistry& getInstance();

				void addFunction(const std::string& name, lua_CFunction function, const std::string& type);

				static std::string getMetaTableNameForType(const std::string& type);
				void registerTypeMetaTable(lua_State* L, const std::string& type);

				void createFunctionTable(lua_State* L, const std::string& type);

				/**
				 * Adds the functions to the table on the top of the stack.
				 */
				void addFunctionsToTable(lua_State* L, const std::string& type);

			private:
				FunctionRegistry();


			private:
				struct Registration {
					std::string name;
					lua_CFunction function;
					std::string type;
				};
				std::vector<Registration> registrations;
		};
	}
}