Răsfoiți Sursa

LuaEnvironmente provides funcionality for loading modules for crown-lua

mikymod 12 ani în urmă
părinte
comite
c9001282b7
2 a modificat fișierele cu 88 adăugiri și 0 ștergeri
  1. 38 0
      lua/LuaEnvironment.cpp
  2. 50 0
      lua/LuaEnvironment.h

+ 38 - 0
lua/LuaEnvironment.cpp

@@ -0,0 +1,38 @@
+#include <cassert>
+#include "LuaEnvironment.h"
+
+
+namespace crown
+{
+
+LuaEnvironment::LuaEnvironment(lua_State* L) :
+	m_state(L)
+{
+
+}
+
+//-----------------------------------------------------------
+void LuaEnvironment::load_module_function(const char* module, const char* name, const lua_CFunction func)
+{
+	luaL_Reg entry[2];
+
+	entry[0].name = name;
+	entry[0].func = func;
+
+	entry[1].name = NULL;
+	entry[1].func = NULL;
+
+	luaL_register(m_state, module, entry);
+}
+
+extern "C"
+{
+	int luaopen_libcrownlua(lua_State* L)
+	{
+		LuaEnvironment env(L);
+
+		load_vec2(env);
+	}
+}
+
+} // namespace crown

+ 50 - 0
lua/LuaEnvironment.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include "lua.hpp"
+#include "Types.h"
+
+namespace crown
+{
+
+struct ModuleEntry
+{
+	const char* 	module;
+	luaL_Reg		entry[2];
+};
+
+class LuaEnvironment
+{
+
+public:
+	/// Constructor
+					LuaEnvironment(lua_State* L);
+	/// Load a function to proper module
+	void			load_module_function(const char* module, const char* name, const lua_CFunction func);
+	/// Create library based on each module which will be opened by luaopen_*
+	void			create_module_library();
+
+private:
+
+	lua_State*		m_state;
+};
+
+extern "C"
+{
+	int luaopen_crownlua(lua_State* L);
+}
+
+void load_vec2(LuaEnvironment& env);
+void load_vec3(LuaEnvironment& env);
+void load_mat4(LuaEnvironment& env);
+void load_quat(LuaEnvironment& env);
+void load_math(LuaEnvironment& env);
+
+void load_mouse(LuaEnvironment& env);
+void load_keyboard(LuaEnvironment& env);
+void load_touch(LuaEnvironment& env);
+void load_accelerometer(LuaEnvironment& env);
+
+void load_camera(LuaEnvironment& env);
+
+
+} // namespace crown