summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-10-03 21:12:22 -0500
committersanine <sanine.not@pm.me>2022-10-03 21:12:22 -0500
commitc4241b7cc97e9b0a341d54f2a4d172500c1d5399 (patch)
tree7a9d53c14d31fcc6deffd910a0604f51524faf2a
parent99574e9e679208d629884b924424ed8a54423920 (diff)
add window.getKey
-rw-r--r--demo/bouncing_ball/main.lua4
-rw-r--r--demo/minimal/main.lua1
-rw-r--r--src/gl/window.c18
3 files changed, 23 insertions, 0 deletions
diff --git a/demo/bouncing_ball/main.lua b/demo/bouncing_ball/main.lua
index ecbff7b..f98a032 100644
--- a/demo/bouncing_ball/main.lua
+++ b/demo/bouncing_ball/main.lua
@@ -98,6 +98,10 @@ local dtAverage = 0
local dtCount = 0
while not window.shouldClose(w) do
+ if window.getKey(w, window.KEY_ESCAPE) == window.PRESS then
+ break
+ end
+
local newTime = window.getTime()
local dt = newTime - time
dtAverage = dtAverage + dt
diff --git a/demo/minimal/main.lua b/demo/minimal/main.lua
new file mode 100644
index 0000000..8eaa5c1
--- /dev/null
+++ b/demo/minimal/main.lua
@@ -0,0 +1 @@
+print('hello, world!')
diff --git a/src/gl/window.c b/src/gl/window.c
index 04302e7..db807f6 100644
--- a/src/gl/window.c
+++ b/src/gl/window.c
@@ -28,6 +28,7 @@ int window_poll_events(lua_State *L);
int window_swap_buffers(lua_State *L);
int window_set_framebuffer_size_callback(lua_State *L);
int window_get_time(lua_State *L);
+int window_get_key(lua_State *L);
static const char *window_tname = "window";
@@ -58,9 +59,17 @@ void setup_window(lua_State *L, int honey_index)
hs_str_cfunc("swapBuffers", window_swap_buffers),
hs_str_cfunc("setFramebufferSizeCallback", window_set_framebuffer_size_callback),
hs_str_cfunc("getTime", window_get_time),
+ hs_str_cfunc("getKey", window_get_key),
hs_str_tbl("hintType", hint_types),
hs_str_tbl("profileType", profile_types),
+
+ /* key states */
+ hs_str_int("PRESS", GLFW_PRESS),
+ hs_str_int("RELEASE", GLFW_RELEASE),
+
+ /* key buttons */
+ hs_str_int("KEY_ESCAPE", GLFW_KEY_ESCAPE),
);
lua_setfield(L, honey_index, "window");
}
@@ -172,3 +181,12 @@ int window_get_time(lua_State *L)
lua_pushnumber(L, glfwGetTime());
return 1;
}
+
+
+int window_get_key(lua_State *L)
+{
+ GLFWwindow **win = luaL_checkudata(L, 1, window_tname);
+ int key = luaL_checkinteger(L, 2);
+ lua_pushinteger(L, glfwGetKey(*win, key));
+ return 1;
+}