From c2329b4c8258baa9429c77566c9def97d00e96d7 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 10 Mar 2023 02:33:42 -0600 Subject: demonstrate working glfw refactored bindings --- src/glfw/setup.c | 11 +++++++++++ src/glfw/setup.h | 1 + src/glfw/window.c | 12 +++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src/glfw') diff --git a/src/glfw/setup.c b/src/glfw/setup.c index 0abab35..4ba49a4 100644 --- a/src/glfw/setup.c +++ b/src/glfw/setup.c @@ -1,5 +1,6 @@ #include #include +#include #include "util/util.h" #include "setup.h" @@ -29,5 +30,15 @@ void setup_glfw(lua_State *L, int honey_tbl) }; create_table(L, tbl); + int t = lua_gettop(L); + + GLFWwindow ** window_null = create_window(L); + *window_null = NULL; + lua_setfield(L, t, "window_NULL"); + + GLFWmonitor ** monitor_null = create_monitor(L); + *monitor_null = NULL; + lua_setfield(L, t, "monitor_NULL"); + lua_setfield(L, honey_tbl, "glfw"); } diff --git a/src/glfw/setup.h b/src/glfw/setup.h index 1b30728..4226c3b 100644 --- a/src/glfw/setup.h +++ b/src/glfw/setup.h @@ -29,6 +29,7 @@ struct h_glfw_window_data_t { }; +GLFWwindow ** create_window(lua_State *L); GLFWmonitor ** create_monitor(lua_State *L); diff --git a/src/glfw/window.c b/src/glfw/window.c index 1aafeb4..0199fb0 100644 --- a/src/glfw/window.c +++ b/src/glfw/window.c @@ -19,11 +19,18 @@ GLFWwindow ** create_window(lua_State *L) luaL_getmetatable(L, glfw_window_tname); lua_setmetatable(L, -2); - /* configure window data struct */ d->data.L = L; lua_pushvalue(L, self); d->data.self_ref = luaL_ref(L, LUA_REGISTRYINDEX); + return window; +} + +static void configure_window(GLFWwindow **window) +{ + struct window_data_t *d = (struct window_data_t *) window; + + /* configure window data struct */ d->data.key_cb_ref = LUA_NOREF; d->data.char_cb_ref = LUA_NOREF; d->data.char_mods_cb_ref = LUA_NOREF; @@ -43,8 +50,6 @@ GLFWwindow ** create_window(lua_State *L) d->data.content_scale_cb_ref = LUA_NOREF; glfwSetWindowUserPointer(*window, &(d->data)); - - return window; } @@ -83,6 +88,7 @@ int glfwCreateWindow_bind(lua_State *L) GLFWwindow ** window = create_window(L); *window = glfwCreateWindow(width, height, title, *monitor, *share); + configure_window(window); return 1; } -- cgit v1.2.1