#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