summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/Lua/FunctionRegistry.h')
-rw-r--r--Sluift/Lua/FunctionRegistry.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/Sluift/Lua/FunctionRegistry.h b/Sluift/Lua/FunctionRegistry.h
new file mode 100644
index 0000000..e3ad620
--- /dev/null
+++ b/Sluift/Lua/FunctionRegistry.h
@@ -0,0 +1,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;
+ };
+ }
+}