From 51c7235d4e0a2df109dd5050328a0ad4a1878ae4 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 10 Mar 2023 02:05:18 -0600 Subject: refactor: move glfw functions into separate table --- src/glfw/monitor.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 src/glfw/monitor.c (limited to 'src/glfw/monitor.c') diff --git a/src/glfw/monitor.c b/src/glfw/monitor.c new file mode 100644 index 0000000..0f1b3fc --- /dev/null +++ b/src/glfw/monitor.c @@ -0,0 +1,250 @@ +#include +#include +#include +#include +#include "setup.h" + + +GLFWmonitor ** create_monitor(lua_State *L) +{ + GLFWmonitor ** monitor = lua_newuserdata(L, sizeof(GLFWmonitor *)); + luaL_getmetatable(L, glfw_monitor_tname); + lua_setmetatable(L, -2); + return monitor; +} + +int glfwGetMonitors_bind(lua_State *L) +{ + int count; + GLFWmonitor ** bind_result = glfwGetMonitors(&count); + lua_createtable(L, count, 0); + int tbl = lua_gettop(L); + for (int i=0; isize, 0); + int ramp_tbl = lua_gettop(L); + for (int i=0; isize; i++) { + lua_createtable(L, 3, 0); + int tbl = lua_gettop(L); + lua_pushinteger(L, ramp->red[i]); + lua_rawseti(L, tbl, 1); + lua_pushinteger(L, ramp->green[i]); + lua_rawseti(L, tbl, 2); + lua_pushinteger(L, ramp->blue[i]); + lua_rawseti(L, tbl, 3); + lua_rawseti(L, ramp_tbl, i+1); + } + + return 1; +} + + +int glfwSetGammaRamp_bind(lua_State *L) +{ + GLFWmonitor * monitor = luaL_checkudata(L, 1, glfw_monitor_tname); + luaL_checktype(L, 2, LUA_TTABLE); + + GLFWgammaramp ramp = { NULL, NULL, NULL, 0 }; + size_t len = lua_objlen(L, 2); + ramp.red = malloc(len * sizeof(unsigned short)); + ramp.green = malloc(len * sizeof(unsigned short)); + ramp.blue = malloc(len * sizeof(unsigned short)); + ramp.size = len; + if ( + ramp.red == NULL || + ramp.green == NULL || + ramp.blue == NULL + ) { + return luaL_error( + L, + "failed to allocate one or more gamma ramp " + "color buffers of %lu bytes each", + len * sizeof(unsigned short) + ); + } + + for (int i=0; i