From c4241b7cc97e9b0a341d54f2a4d172500c1d5399 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 3 Oct 2022 21:12:22 -0500 Subject: add window.getKey --- src/gl/window.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') 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; +} -- cgit v1.2.1