Browse Source

Add Accelerometer and Keyboard lua bindings - need additional work

Daniele Bartolini 12 years ago
parent
commit
25c7f86f62
2 changed files with 89 additions and 0 deletions
  1. 35 0
      lua/AccelerometerBinds.cpp
  2. 54 0
      lua/KeyboardBinds.cpp

+ 35 - 0
lua/AccelerometerBinds.cpp

@@ -0,0 +1,35 @@
+#include "LuaStack.h"
+#include "Device.h"
+#include "LuaEnvironment.h"
+#include "Accelerometer.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+extern Vec3* next_vec3();
+
+//-----------------------------------------------------------------------------
+int32_t accelerometer_orientation(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* orientation = next_vec3();
+	*orientation = device()->accelerometer()->orientation();
+
+	stack.push_lightudata(orientation);
+
+	return 1;
+}
+
+} // extern "C"
+
+//-----------------------------------------------------------------------------
+void load_accelerometer(LuaEnvironment& env)
+{
+	env.load_module_function("Accelerometer", "orientation", accelerometer_orientation);
+}
+
+} // namespace crown

+ 54 - 0
lua/KeyboardBinds.cpp

@@ -0,0 +1,54 @@
+#include "LuaStack.h"
+#include "Device.h"
+#include "LuaEnvironment.h"
+#include "Keyboard.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+int32_t keyboard_modifier_pressed(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t modifier = stack.get_int(1);
+
+	stack.push_bool(device()->keyboard()->modifier_pressed((ModifierKey) modifier));
+
+	return 1;
+}
+
+int32_t keyboard_key_pressed(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t key = stack.get_int(1);
+
+	stack.push_bool(device()->keyboard()->key_pressed((KeyCode) key));
+
+	return 1;
+}
+
+int32_t keyboard_key_released(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t key = stack.get_int(1);
+
+	stack.push_bool(device()->keyboard()->key_released((KeyCode) key));
+
+	return 1;
+}
+
+} // extern "C"
+
+void load_keyboard(LuaEnvironment& env)
+{
+	env.load_module_function("Keyboard", "modifier_pressed",	keyboard_modifier_pressed);
+	env.load_module_function("Keyboard", "key_pressed",			keyboard_key_pressed);
+	env.load_module_function("Keyboard", "key_released",		keyboard_key_released);
+}
+
+} // namespace crown