diff options
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | src/gl/data.c | 66 | ||||
-rw-r--r-- | src/gl/drawing.c | 56 | ||||
-rw-r--r-- | src/gl/gl.c | 57 | ||||
-rw-r--r-- | src/gl/shader.c | 95 | ||||
-rw-r--r-- | src/gl/texture.c | 93 | ||||
-rw-r--r-- | src/gl/window.c | 339 | ||||
-rw-r--r-- | src/main.c | 4 |
8 files changed, 373 insertions, 349 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d8ebc4b..bfba57b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ target_include_directories( ${LIB_ROOT} ${LIB_ROOT}/lua-5.1.5/src ${CMAKE_SOURCE_DIR}/src - ${LIB_ROOT}/honeysuckle/src ${LIB_ROOT}/glfw-3.3.8/include ${LIB_ROOT}/cglm/include ${LIB_ROOT}/miniaudio @@ -32,24 +31,17 @@ add_definitions(-DCGLM_ALL_UNALIGNED) # link to third-party included libraries target_link_directories( honey PUBLIC - ${LIB_ROOT}/honeysuckle ${LIB_ROOT}/glfw-3.3.8/src ) add_subdirectory(${LIB_ROOT}/lua-5.1.5) -add_subdirectory(${LIB_ROOT}/honeysuckle) add_subdirectory(${LIB_ROOT}/cglm) add_subdirectory(${LIB_ROOT}/glfw-3.3.8) add_subdirectory(${LIB_ROOT}/cargs) add_subdirectory(${LIB_ROOT}/ode-0.16.1) add_subdirectory(${LIB_ROOT}/nanovg) -target_include_directories( - honeysuckle PUBLIC - ${LIB_ROOT}/lua-5.1.5/src -) - -set(LIBRARIES lua5.1 honeysuckle glfw cargs ODE nanovg OpenGL::GL) +set(LIBRARIES lua5.1 glfw cargs ODE nanovg OpenGL::GL) if (UNIX) set(LIBRARIES ${LIBRARIES} dl pthread m) endif() @@ -65,7 +57,7 @@ add_executable(test EXCLUDE_FROM_ALL) set_target_properties(test PROPERTIES C_STANDARD 99 CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wpedantic") -target_link_libraries(test lua5.1 honeysuckle glfw dl) +target_link_libraries(test lua5.1 glfw dl) add_subdirectory(${SRC_ROOT}/audio) diff --git a/src/gl/data.c b/src/gl/data.c index d36608b..b7dc581 100644 --- a/src/gl/data.c +++ b/src/gl/data.c @@ -3,7 +3,7 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> #include "util/util.h" #include "gl.h" @@ -19,29 +19,31 @@ int gl_vertex_array_enable_attrib(lua_State *L); void setup_data(lua_State *L, int gl_index) { - int tbl = hs_create_table(L, + struct honey_tbl_t tbl[] = { /* functions */ - hs_str_cfunc("GenBuffers", gl_create_buffer), - hs_str_cfunc("BindBuffer", gl_bind_buffer), - hs_str_cfunc("BufferData", gl_buffer_data), + H_FUNC("GenBuffers", gl_create_buffer), + H_FUNC("BindBuffer", gl_bind_buffer), + H_FUNC("BufferData", gl_buffer_data), - hs_str_cfunc("GenVertexArrays", gl_vertex_array_create), - hs_str_cfunc("BindVertexArray", gl_vertex_array_bind), - hs_str_cfunc("VertexAttribPointer", gl_vertex_attrib_pointer), - hs_str_cfunc("EnableVertexAttribArray", gl_vertex_array_enable_attrib), + H_FUNC("GenVertexArrays", gl_vertex_array_create), + H_FUNC("BindVertexArray", gl_vertex_array_bind), + H_FUNC("VertexAttribPointer", gl_vertex_attrib_pointer), + H_FUNC("EnableVertexAttribArray", gl_vertex_array_enable_attrib), /******** enums ********/ /* buffer bind targets */ - hs_str_int("ARRAY_BUFFER", GL_ARRAY_BUFFER), - hs_str_int("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER), + H_INT("ARRAY_BUFFER", GL_ARRAY_BUFFER), + H_INT("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER), /* buffer usage patters */ - hs_str_int("STREAM_DRAW", GL_STREAM_DRAW), - hs_str_int("STATIC_DRAW", GL_STATIC_DRAW), - hs_str_int("DYNAMIC_DRAW", GL_DYNAMIC_DRAW), - ); - - append_table(L, gl_index, tbl); + H_INT("STREAM_DRAW", GL_STREAM_DRAW), + H_INT("STATIC_DRAW", GL_STATIC_DRAW), + H_INT("DYNAMIC_DRAW", GL_DYNAMIC_DRAW), + + H_END + }; + create_table(L, tbl); + append_table(L, gl_index, lua_gettop(L)); lua_pop(L, 1); } @@ -57,8 +59,8 @@ int gl_create_buffer(lua_State *L) int gl_bind_buffer(lua_State *L) { - lua_Integer target, buf; - hs_parse_args(L, hs_int(target), hs_int(buf)); + int target = luaL_checkinteger(L, 1); + int buf = luaL_checkinteger(L, 2); glBindBuffer(target, buf); return 0; } @@ -70,11 +72,11 @@ int gl_bind_buffer(lua_State *L) *sz = len * sizeof(type); \ type *buf = malloc(*sz); \ if (buf == NULL) \ - hs_throw_error(L, "failed to allocate intermediary buffer"); \ + luaL_error(L, "failed to allocate intermediary buffer"); \ for (int i=0; i<len; i++) { \ lua_rawgeti(L, tbl, i+1); \ if (!lua_isnumber(L, -1)) \ - hs_throw_error(L, "all elements must be numbers (failed at index %d)", i); \ + luaL_error(L, "all elements must be numbers (failed at index %d)", i); \ buf[i] = conversion(L, -1); \ lua_pop(L, 1); \ } \ @@ -88,8 +90,11 @@ GET_BUFFER_TYPE(float, float, lua_tonumber) int gl_buffer_data(lua_State *L) { lua_Integer target, type, usage; - int table; - hs_parse_args(L, hs_int(target), hs_int(type), hs_tbl(table), hs_int(usage)); + target = luaL_checkinteger(L, 1); + type = luaL_checkinteger(L, 2); + luaL_checktype(L, 3, LUA_TTABLE); + int table = 3; + usage = luaL_checkinteger(L, 4); /* build raw buffer */ void *buf; size_t len; @@ -107,7 +112,7 @@ int gl_buffer_data(lua_State *L) break; default: - hs_throw_error(L, "invalid type"); + luaL_error(L, "invalid type"); } /* call */ @@ -128,8 +133,7 @@ int gl_vertex_array_create(lua_State *L) int gl_vertex_array_bind(lua_State *L) { - lua_Integer array; - hs_parse_args(L, hs_int(array)); + lua_Integer array = luaL_checkinteger(L, 1); glBindVertexArray(array); return 0; } @@ -139,7 +143,12 @@ int gl_vertex_attrib_pointer(lua_State *L) { lua_Integer index, size, stride, offset; bool normalized; - hs_parse_args(L, hs_int(index), hs_int(size), hs_bool(normalized), hs_int(stride), hs_int(offset)); + index = luaL_checkinteger(L, 1); + size = luaL_checkinteger(L, 2); + normalized = lua_toboolean(L, 3); + stride = luaL_checkinteger(L, 4); + offset = luaL_checkinteger(L, 5); + glVertexAttribPointer(index, size, GL_FLOAT, normalized, stride*sizeof(float), (void*) (offset*sizeof(float))); @@ -149,8 +158,7 @@ int gl_vertex_attrib_pointer(lua_State *L) int gl_vertex_array_enable_attrib(lua_State *L) { - lua_Integer index; - hs_parse_args(L, hs_int(index)); + lua_Integer index = luaL_checkinteger(L, 1); glEnableVertexAttribArray(index); return 0; } diff --git a/src/gl/drawing.c b/src/gl/drawing.c index d772cda..eeb0496 100644 --- a/src/gl/drawing.c +++ b/src/gl/drawing.c @@ -1,7 +1,7 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> #include "util/util.h" int gl_set_viewport(lua_State *L); @@ -15,34 +15,39 @@ int gl_framebuffer_texture_2d(lua_State *L); void setup_drawing(lua_State *L, int gl_index) { - int tbl = hs_create_table(L, + struct honey_tbl_t tbl[] = { /* functions */ - hs_str_cfunc("DrawArrays", gl_draw_arrays), - hs_str_cfunc("DrawElements", gl_draw_elements), - hs_str_cfunc("ClearColor", gl_set_clear_color), - hs_str_cfunc("Clear", gl_clear), - hs_str_cfunc("Viewport", gl_set_viewport), + H_FUNC("DrawArrays", gl_draw_arrays), + H_FUNC("DrawElements", gl_draw_elements), + H_FUNC("ClearColor", gl_set_clear_color), + H_FUNC("Clear", gl_clear), + H_FUNC("Viewport", gl_set_viewport), /******** enums ********/ /* rendering primitives */ - hs_str_int("POINTS", GL_POINTS), - hs_str_int("LINES", GL_LINES), - hs_str_int("TRIANGLES", GL_TRIANGLES), + H_INT("POINTS", GL_POINTS), + H_INT("LINES", GL_LINES), + H_INT("TRIANGLES", GL_TRIANGLES), /* clear bitmasks */ - hs_str_int("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT), - hs_str_int("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), - hs_str_int("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT), - ); - - append_table(L, gl_index, tbl); + H_INT("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT), + H_INT("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), + H_INT("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT), + + H_END + }; + create_table(L, tbl); + append_table(L, gl_index, lua_gettop(L)); lua_pop(L, 1); } int gl_set_clear_color(lua_State *L) { lua_Number r, g, b, a; - hs_parse_args(L, hs_num(r), hs_num(g), hs_num(b), hs_num(a)); + r = luaL_checknumber(L, 1); + g = luaL_checknumber(L, 2); + b = luaL_checknumber(L, 3); + a = luaL_checknumber(L, 4); glClearColor(r, g, b, a); return 0; } @@ -50,8 +55,7 @@ int gl_set_clear_color(lua_State *L) int gl_clear(lua_State *L) { - lua_Integer mask; - hs_parse_args(L, hs_int(mask)); + lua_Integer mask = luaL_checkinteger(L, 1); glClear(mask); return 0; } @@ -60,7 +64,9 @@ int gl_clear(lua_State *L) int gl_draw_arrays(lua_State *L) { lua_Integer mode, first, count; - hs_parse_args(L, hs_int(mode), hs_int(first), hs_int(count)); + mode = luaL_checkinteger(L, 1); + first = luaL_checkinteger(L, 2); + count = luaL_checkinteger(L, 3); glDrawArrays(mode, first, count); return 0; } @@ -69,7 +75,10 @@ int gl_draw_arrays(lua_State *L) int gl_draw_elements(lua_State *L) { lua_Integer mode, count, type, offset; - hs_parse_args(L, hs_int(mode), hs_int(count), hs_int(type), hs_int(offset)); + mode = luaL_checkinteger(L, 1); + count = luaL_checkinteger(L, 2); + type = luaL_checkinteger(L, 3); + offset = luaL_checkinteger(L, 4); glDrawElements(mode, count, type, (const void*)offset); return 0; } @@ -78,7 +87,10 @@ int gl_draw_elements(lua_State *L) int gl_set_viewport(lua_State *L) { lua_Integer x, y, w, h; - hs_parse_args(L, hs_int(x), hs_int(y), hs_int(w), hs_int(h)); + x = luaL_checkinteger(L, 1); + y = luaL_checkinteger(L, 2); + w = luaL_checkinteger(L, 3); + h = luaL_checkinteger(L, 4); glViewport(x, y, w, h); return 0; } diff --git a/src/gl/gl.c b/src/gl/gl.c index 03d97af..b8da1ec 100644 --- a/src/gl/gl.c +++ b/src/gl/gl.c @@ -3,7 +3,8 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> +#include "util/util.h" #include "gl.h" /* needs to be here because glad uses macros to define glBufferData */ @@ -22,34 +23,38 @@ int gl_disable(lua_State *L); void setup_gl(lua_State *L, int honey_index) { - int gl_index = hs_create_table(L, + struct honey_tbl_t tbl[] = { /* functions */ - hs_str_cfunc("Init", gl_init), - hs_str_cfunc("InitGlad", glad_init), - hs_str_cfunc("Terminate", gl_terminate), - hs_str_cfunc("GetError", gl_get_error), - hs_str_cfunc("Enable", gl_enable), - hs_str_cfunc("Disable", gl_disable), + H_FUNC("Init", gl_init), + H_FUNC("InitGlad", glad_init), + H_FUNC("Terminate", gl_terminate), + H_FUNC("GetError", gl_get_error), + H_FUNC("Enable", gl_enable), + H_FUNC("Disable", gl_disable), /******** enums ********/ /* data types */ - hs_str_int("UNSIGNED_BYTE", GL_UNSIGNED_BYTE), - hs_str_int("UNSIGNED_INT", GL_UNSIGNED_INT), - hs_str_int("INT", GL_INT), - hs_str_int("FLOAT", GL_FLOAT), + H_INT("UNSIGNED_BYTE", GL_UNSIGNED_BYTE), + H_INT("UNSIGNED_INT", GL_UNSIGNED_INT), + H_INT("INT", GL_INT), + H_INT("FLOAT", GL_FLOAT), /* error types */ - hs_str_int("NO_ERROR", GL_NO_ERROR), - hs_str_int("INVALID_ENUM", GL_INVALID_ENUM), - hs_str_int("INVALID_VALUE", GL_INVALID_VALUE), - hs_str_int("INVALID_OPERATION", GL_INVALID_OPERATION), - hs_str_int("INVALID_FRAMEBUFFER_OPERATION", GL_INVALID_FRAMEBUFFER_OPERATION), - hs_str_int("OUT_OF_MEMORY", GL_OUT_OF_MEMORY), + H_INT("NO_ERROR", GL_NO_ERROR), + H_INT("INVALID_ENUM", GL_INVALID_ENUM), + H_INT("INVALID_VALUE", GL_INVALID_VALUE), + H_INT("INVALID_OPERATION", GL_INVALID_OPERATION), + H_INT("INVALID_FRAMEBUFFER_OPERATION", GL_INVALID_FRAMEBUFFER_OPERATION), + H_INT("OUT_OF_MEMORY", GL_OUT_OF_MEMORY), /* opengl capabilities */ - hs_str_int("DEPTH_TEST", GL_DEPTH_TEST), - hs_str_int("CULL_FACE", GL_CULL_FACE), - ); + H_INT("DEPTH_TEST", GL_DEPTH_TEST), + H_INT("CULL_FACE", GL_CULL_FACE), + + H_END + }; + create_table(L, tbl); + int gl_index = lua_gettop(L); setup_shader(L, gl_index); setup_drawing(L, gl_index); @@ -63,7 +68,7 @@ void setup_gl(lua_State *L, int honey_index) int gl_init(lua_State *L) { if (!glfwInit()) { - hs_throw_error(L, "failed to initialize GLFW"); + luaL_error(L, "failed to initialize GLFW"); } return 0; } @@ -72,7 +77,7 @@ int gl_init(lua_State *L) int glad_init(lua_State *L) { if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { - hs_throw_error(L, "failed to initialize GLAD"); + luaL_error(L, "failed to initialize GLAD"); } } @@ -93,8 +98,7 @@ int gl_get_error(lua_State *L) int gl_enable(lua_State *L) { - lua_Integer cap; - hs_parse_args(L, hs_int(cap)); + lua_Integer cap = luaL_checkinteger(L, 1); glEnable(cap); return 0; } @@ -102,8 +106,7 @@ int gl_enable(lua_State *L) int gl_disable(lua_State *L) { - lua_Integer cap; - hs_parse_args(L, hs_int(cap)); + lua_Integer cap = luaL_checkinteger(L, 1); glDisable(cap); return 0; } diff --git a/src/gl/shader.c b/src/gl/shader.c index 412fe2b..d78b1ef 100644 --- a/src/gl/shader.c +++ b/src/gl/shader.c @@ -1,7 +1,8 @@ +#include <stdbool.h> #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> #include "util/util.h" int gl_create_shader(lua_State *L); @@ -25,41 +26,42 @@ int gl_uniform_matrix_4fv(lua_State *L); void setup_shader(lua_State *L, int gl_index) { - int tbl = hs_create_table(L, + struct honey_tbl_t tbl[] = { /* functions */ - hs_str_cfunc("CreateShader", gl_create_shader), - hs_str_cfunc("ShaderSource", gl_shader_set_source), - hs_str_cfunc("CompileShader", gl_shader_compile), - hs_str_cfunc("DeleteShader", gl_shader_delete), + H_FUNC("CreateShader", gl_create_shader), + H_FUNC("ShaderSource", gl_shader_set_source), + H_FUNC("CompileShader", gl_shader_compile), + H_FUNC("DeleteShader", gl_shader_delete), - hs_str_cfunc("CreateProgram", gl_program_create), - hs_str_cfunc("AttachShader", gl_program_attach_shader), - hs_str_cfunc("LinkProgram", gl_program_link), - hs_str_cfunc("UseProgram", gl_program_use), + H_FUNC("CreateProgram", gl_program_create), + H_FUNC("AttachShader", gl_program_attach_shader), + H_FUNC("LinkProgram", gl_program_link), + H_FUNC("UseProgram", gl_program_use), - hs_str_cfunc("GetUniformLocation", gl_uniform_get_location), - hs_str_cfunc("Uniform1i", gl_uniform_1i), - hs_str_cfunc("Uniform1f", gl_uniform_1i), - hs_str_cfunc("Uniform3f", gl_uniform_1i), - hs_str_cfunc("Uniform4f", gl_uniform_4f), + H_FUNC("GetUniformLocation", gl_uniform_get_location), + H_FUNC("Uniform1i", gl_uniform_1i), + H_FUNC("Uniform1f", gl_uniform_1i), + H_FUNC("Uniform3f", gl_uniform_1i), + H_FUNC("Uniform4f", gl_uniform_4f), - hs_str_cfunc("UniformMatrix4fv", gl_uniform_matrix_4fv), + H_FUNC("UniformMatrix4fv", gl_uniform_matrix_4fv), /******** enums ********/ /* shader types */ - hs_str_int("VERTEX_SHADER", GL_VERTEX_SHADER), - hs_str_int("FRAGMENT_SHADER", GL_FRAGMENT_SHADER), - ); + H_INT("VERTEX_SHADER", GL_VERTEX_SHADER), + H_INT("FRAGMENT_SHADER", GL_FRAGMENT_SHADER), - append_table(L, gl_index, tbl); + H_END + }; + create_table(L, tbl); + append_table(L, gl_index, lua_gettop(L)); lua_pop(L, 1); } int gl_create_shader(lua_State *L) { - lua_Integer type; - hs_parse_args(L, hs_int(type)); + lua_Integer type = luaL_checkinteger(L, 1); lua_Integer shader = glCreateShader(type); lua_pushinteger(L, shader); return 1; @@ -68,9 +70,8 @@ int gl_create_shader(lua_State *L) int gl_shader_set_source(lua_State *L) { - lua_Integer shader; - char *code; - hs_parse_args(L, hs_int(shader), hs_str(code)); + lua_Integer shader = luaL_checkinteger(L, 1); + const char *code = luaL_checkstring(L, 2); glShaderSource(shader, 1, (const GLchar * const*)&code, NULL); return 0; } @@ -78,14 +79,13 @@ int gl_shader_set_source(lua_State *L) int gl_shader_compile(lua_State *L) { - lua_Integer shader; - hs_parse_args(L, hs_int(shader)); + lua_Integer shader = luaL_checkinteger(L, 1); glCompileShader(shader); int success; char log[1024]; glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(shader, 1024, NULL, log); - hs_throw_error(L, "shader compilation failed: %s", log); + luaL_error(L, "shader compilation failed: %s", log); } return 0; } @@ -93,8 +93,7 @@ int gl_shader_compile(lua_State *L) int gl_shader_delete(lua_State *L) { - lua_Integer shader; - hs_parse_args(L, hs_int(shader)); + lua_Integer shader = luaL_checkinteger(L, 1); glDeleteShader(shader); return 0; } @@ -111,7 +110,8 @@ int gl_program_create(lua_State *L) int gl_program_attach_shader(lua_State *L) { lua_Integer program, shader; - hs_parse_args(L, hs_int(program), hs_int(shader)), + program = luaL_checkinteger(L, 1); + shader = luaL_checkinteger(L, 2); glAttachShader(program, shader); return 0; } @@ -119,14 +119,13 @@ int gl_program_attach_shader(lua_State *L) int gl_program_link(lua_State *L) { - lua_Integer program; - hs_parse_args(L, hs_int(program)); + lua_Integer program = luaL_checkinteger(L, 1); glLinkProgram(program); int success; char log[1024]; glGetProgramiv(program, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(program, 1024, NULL, log); - hs_throw_error(L, "shader linking failed: %s", log); + luaL_error(L, "shader linking failed: %s", log); } return 0; } @@ -134,8 +133,7 @@ int gl_program_link(lua_State *L) int gl_program_use(lua_State *L) { - lua_Integer program; - hs_parse_args(L, hs_int(program)); + lua_Integer program = luaL_checkinteger(L, 1); glUseProgram(program); return 0; } @@ -143,9 +141,8 @@ int gl_program_use(lua_State *L) int gl_uniform_get_location(lua_State *L) { - lua_Integer program; - char *name; - hs_parse_args(L, hs_int(program), hs_str(name)); + lua_Integer program = luaL_checkinteger(L, 1); + const char *name = luaL_checkstring(L, 2); int location = glGetUniformLocation(program, (const GLchar*)name); lua_pushinteger(L, location); return 1; @@ -155,7 +152,8 @@ int gl_uniform_get_location(lua_State *L) int gl_uniform_1i(lua_State *L) { lua_Integer location, v0; - hs_parse_args(L, hs_int(location), hs_int(v0)); + location = luaL_checkinteger(L, 1); + v0 = luaL_checkinteger(L, 2); glUniform1i(location, v0); return 0; } @@ -183,9 +181,11 @@ int gl_uniform_3f(lua_State *L) int gl_uniform_4f(lua_State *L) { - lua_Integer location; - lua_Number v0, v1, v2, v3; - hs_parse_args(L, hs_int(location), hs_num(v0), hs_num(v1), hs_num(v2), hs_num(v3)); + lua_Integer location = luaL_checkinteger(L, 1); + lua_Number v0 = luaL_checknumber(L, 2); + lua_Number v1 = luaL_checknumber(L, 3); + lua_Number v2 = luaL_checknumber(L, 4); + lua_Number v3 = luaL_checknumber(L, 5); glUniform4f(location, v0, v1, v2, v3); return 0; } @@ -193,12 +193,9 @@ int gl_uniform_4f(lua_State *L) int gl_uniform_matrix_4fv(lua_State *L) { - lua_Integer location; - bool transpose; - void *ptr; - hs_parse_args(L, hs_int(location), hs_bool(transpose), hs_user(ptr)); - - float *value = ptr; + lua_Integer location = luaL_checkinteger(L, 1); + bool transpose = lua_toboolean(L, 2); + float *value = lua_touserdata(L, 3); glUniformMatrix4fv(location, 1, transpose, value); return 0; } diff --git a/src/gl/texture.c b/src/gl/texture.c index 2284511..13b23c0 100644 --- a/src/gl/texture.c +++ b/src/gl/texture.c @@ -1,7 +1,7 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> #include "util/util.h" @@ -15,50 +15,52 @@ int gl_tex_parameter_i(lua_State *L); void setup_texture(lua_State *L, int gl_index) { - int tbl = hs_create_table(L, + struct honey_tbl_t tbl[] = { /* functions */ - hs_str_cfunc("GenTextures", gl_texture_create), - hs_str_cfunc("BindTexture", gl_texture_bind), - hs_str_cfunc("TexImage2D", gl_texture_image_2d), - hs_str_cfunc("GenerateMipmap", gl_texture_generate_mipmaps), - hs_str_cfunc("ActiveTexture", gl_texture_set_active), - hs_str_cfunc("TexParameteri", gl_tex_parameter_i), + H_FUNC("GenTextures", gl_texture_create), + H_FUNC("BindTexture", gl_texture_bind), + H_FUNC("TexImage2D", gl_texture_image_2d), + H_FUNC("GenerateMipmap", gl_texture_generate_mipmaps), + H_FUNC("ActiveTexture", gl_texture_set_active), + H_FUNC("TexParameteri", gl_tex_parameter_i), /******** enums ********/ /* texture binding targets */ - hs_str_int("TEXTURE_2D", GL_TEXTURE_2D), + H_INT("TEXTURE_2D", GL_TEXTURE_2D), /* texture data formats */ - hs_str_int("RGB", GL_RGB), - hs_str_int("RGBA", GL_RGBA), + H_INT("RGB", GL_RGB), + H_INT("RGBA", GL_RGBA), /* texture parameters */ - hs_str_int("TEXTURE_WRAP_S", GL_TEXTURE_WRAP_S), - hs_str_int("TEXTURE_WRAP_T", GL_TEXTURE_WRAP_T), - hs_str_int("TEXTURE_MIN_FILTER", GL_TEXTURE_MIN_FILTER), - hs_str_int("TEXTURE_MAG_FILTER", GL_TEXTURE_MAG_FILTER), - hs_str_int("TEXTURE_SWIZZLE_R", GL_TEXTURE_SWIZZLE_R), - hs_str_int("TEXTURE_SWIZZLE_G", GL_TEXTURE_SWIZZLE_G), - hs_str_int("TEXTURE_SWIZZLE_B", GL_TEXTURE_SWIZZLE_B), - hs_str_int("TEXTURE_SWIZZLE_A", GL_TEXTURE_SWIZZLE_A), + H_INT("TEXTURE_WRAP_S", GL_TEXTURE_WRAP_S), + H_INT("TEXTURE_WRAP_T", GL_TEXTURE_WRAP_T), + H_INT("TEXTURE_MIN_FILTER", GL_TEXTURE_MIN_FILTER), + H_INT("TEXTURE_MAG_FILTER", GL_TEXTURE_MAG_FILTER), + H_INT("TEXTURE_SWIZZLE_R", GL_TEXTURE_SWIZZLE_R), + H_INT("TEXTURE_SWIZZLE_G", GL_TEXTURE_SWIZZLE_G), + H_INT("TEXTURE_SWIZZLE_B", GL_TEXTURE_SWIZZLE_B), + H_INT("TEXTURE_SWIZZLE_A", GL_TEXTURE_SWIZZLE_A), /* wrapping types */ - hs_str_int("REPEAT", GL_REPEAT), + H_INT("REPEAT", GL_REPEAT), /* filter types */ - hs_str_int("NEAREST", GL_NEAREST), - hs_str_int("LINEAR", GL_LINEAR), + H_INT("NEAREST", GL_NEAREST), + H_INT("LINEAR", GL_LINEAR), /* swizzle targets */ - hs_str_int("RED", GL_RED), - hs_str_int("GREEN", GL_GREEN), - hs_str_int("BLUE", GL_BLUE), - hs_str_int("ALPHA", GL_ALPHA), - hs_str_int("ZERO", GL_ZERO), - hs_str_int("ONE", GL_ONE), - ); - - append_table(L, gl_index, tbl); + H_INT("RED", GL_RED), + H_INT("GREEN", GL_GREEN), + H_INT("BLUE", GL_BLUE), + H_INT("ALPHA", GL_ALPHA), + H_INT("ZERO", GL_ZERO), + H_INT("ONE", GL_ONE), + + H_END + }; + create_table(L, tbl); + append_table(L, gl_index, lua_gettop(L)); lua_pop(L, 1); } @@ -75,7 +77,8 @@ int gl_texture_create(lua_State *L) int gl_texture_bind(lua_State *L) { lua_Integer target, texture; - hs_parse_args(L, hs_int(target), hs_int(texture)); + target = luaL_checkinteger(L, 1); + texture = luaL_checkinteger(L, 2); glBindTexture(target, texture); return 0; } @@ -87,14 +90,14 @@ int gl_texture_image_2d(lua_State *L) internal_format, width, height, format, type; - void *data; - hs_parse_args(L, - hs_int(target), hs_int(mipmap_level), - hs_int(internal_format), - hs_int(width), hs_int(height), - hs_int(format), hs_int(type), - hs_light(data) - ); + target = luaL_checkinteger(L, 1); + mipmap_level = luaL_checkinteger(L, 2); + internal_format = luaL_checkinteger(L, 3); + width = luaL_checkinteger(L, 4); + height = luaL_checkinteger(L, 5); + format = luaL_checkinteger(L, 6); + type = luaL_checkinteger(L, 7); + void *data = lua_touserdata(L, 8); glTexImage2D(target, mipmap_level, internal_format, width, height, 0, format, type, data); return 0; @@ -103,8 +106,7 @@ int gl_texture_image_2d(lua_State *L) int gl_texture_generate_mipmaps(lua_State *L) { - lua_Integer target; - hs_parse_args(L, hs_int(target)); + lua_Integer target = luaL_checkinteger(L, 1); glGenerateMipmap(target); return 0; } @@ -112,8 +114,7 @@ int gl_texture_generate_mipmaps(lua_State *L) int gl_texture_set_active(lua_State *L) { - lua_Integer unit; - hs_parse_args(L, hs_int(unit)); + lua_Integer unit = luaL_checkinteger(L, 1); glActiveTexture(GL_TEXTURE0 + unit); return 0; } @@ -122,7 +123,9 @@ int gl_texture_set_active(lua_State *L) int gl_tex_parameter_i(lua_State *L) { lua_Integer target, pname, param; - hs_parse_args(L, hs_int(target), hs_int(pname), hs_int(param)); + target = luaL_checkinteger(L, 1); + pname = luaL_checkinteger(L, 2); + param = luaL_checkinteger(L, 3); glTexParameteri(target, pname, param); return 0; } diff --git a/src/gl/window.c b/src/gl/window.c index 46e9c35..46bc2f5 100644 --- a/src/gl/window.c +++ b/src/gl/window.c @@ -2,7 +2,8 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <lua.h> -#include <honeysuckle.h> +#include <lauxlib.h> +#include "util/util.h" struct window_data { lua_State *L; @@ -42,171 +43,177 @@ void setup_window(lua_State *L, int honey_index) luaL_newmetatable(L, window_tname); lua_pop(L, 1); - int hint_types = hs_create_table(L, - hs_str_int("contextVersionMajor", GLFW_CONTEXT_VERSION_MAJOR), - hs_str_int("contextVersionMinor", GLFW_CONTEXT_VERSION_MINOR), - hs_str_int("openGlProfile", GLFW_OPENGL_PROFILE), - ); - - int profile_types = hs_create_table(L, - hs_str_int("openGlCoreProfile", GLFW_OPENGL_CORE_PROFILE), - ); - - struct hs_tbl_entry tbl[] = { - hs_str_cfunc("create", window_create), - hs_str_cfunc("destroy", window_destroy), - hs_str_cfunc("makeContextCurrent", window_make_context_current), - hs_str_cfunc("setHint", window_set_hint), - hs_str_cfunc("shouldClose", window_should_close), - hs_str_cfunc("setShouldClose", window_set_should_close), - hs_str_cfunc("pollEvents", window_poll_events), - 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_cfunc("getCursorPos", window_get_cursor_pos), - hs_str_cfunc("setInputMode", window_set_input_mode), - - hs_str_tbl("hintType", hint_types), - hs_str_tbl("profileType", profile_types), + struct honey_tbl_t tbl[] = { + H_FUNC("create", window_create), + H_FUNC("destroy", window_destroy), + H_FUNC("makeContextCurrent", window_make_context_current), + H_FUNC("setHint", window_set_hint), + H_FUNC("shouldClose", window_should_close), + H_FUNC("setShouldClose", window_set_should_close), + H_FUNC("pollEvents", window_poll_events), + H_FUNC("swapBuffers", window_swap_buffers), + H_FUNC("setFramebufferSizeCallback", window_set_framebuffer_size_callback), + H_FUNC("getTime", window_get_time), + H_FUNC("getKey", window_get_key), + H_FUNC("getCursorPos", window_get_cursor_pos), + H_FUNC("setInputMode", window_set_input_mode), /* input modes */ - hs_str_int("CURSOR", GLFW_CURSOR), + H_INT("CURSOR", GLFW_CURSOR), /* cursor modes */ - hs_str_int("CURSOR_NORMAL", GLFW_CURSOR_NORMAL), - hs_str_int("CURSOR_HIDDEN", GLFW_CURSOR_HIDDEN), - hs_str_int("CURSOR_DISABLED", GLFW_CURSOR_DISABLED), + H_INT("CURSOR_NORMAL", GLFW_CURSOR_NORMAL), + H_INT("CURSOR_HIDDEN", GLFW_CURSOR_HIDDEN), + H_INT("CURSOR_DISABLED", GLFW_CURSOR_DISABLED), /* key states */ - hs_str_int("PRESS", GLFW_PRESS), - hs_str_int("RELEASE", GLFW_RELEASE), + H_INT("PRESS", GLFW_PRESS), + H_INT("RELEASE", GLFW_RELEASE), /* key buttons */ - hs_str_int("KEY_UNKNOWN", GLFW_KEY_UNKNOWN), - hs_str_int("KEY_SPACE", GLFW_KEY_SPACE), - hs_str_int("KEY_APOSTROPHE", GLFW_KEY_APOSTROPHE), - hs_str_int("KEY_COMMA", GLFW_KEY_COMMA), - hs_str_int("KEY_MINUS", GLFW_KEY_MINUS), - hs_str_int("KEY_PERIOD", GLFW_KEY_PERIOD), - hs_str_int("KEY_SLASH", GLFW_KEY_SLASH), - hs_str_int("KEY_0", GLFW_KEY_0), - hs_str_int("KEY_1", GLFW_KEY_1), - hs_str_int("KEY_2", GLFW_KEY_2), - hs_str_int("KEY_3", GLFW_KEY_3), - hs_str_int("KEY_4", GLFW_KEY_4), - hs_str_int("KEY_5", GLFW_KEY_5), - hs_str_int("KEY_6", GLFW_KEY_6), - hs_str_int("KEY_7", GLFW_KEY_7), - hs_str_int("KEY_8", GLFW_KEY_8), - hs_str_int("KEY_9", GLFW_KEY_9), - hs_str_int("KEY_SEMICOLON", GLFW_KEY_SEMICOLON), - hs_str_int("KEY_EQUAL", GLFW_KEY_EQUAL), - hs_str_int("KEY_A", GLFW_KEY_A), - hs_str_int("KEY_B", GLFW_KEY_B), - hs_str_int("KEY_C", GLFW_KEY_C), - hs_str_int("KEY_D", GLFW_KEY_D), - hs_str_int("KEY_E", GLFW_KEY_E), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_G", GLFW_KEY_G), - hs_str_int("KEY_H", GLFW_KEY_H), - hs_str_int("KEY_I", GLFW_KEY_I), - hs_str_int("KEY_J", GLFW_KEY_J), - hs_str_int("KEY_K", GLFW_KEY_K), - hs_str_int("KEY_L", GLFW_KEY_L), - hs_str_int("KEY_M", GLFW_KEY_M), - hs_str_int("KEY_N", GLFW_KEY_N), - hs_str_int("KEY_O", GLFW_KEY_O), - hs_str_int("KEY_P", GLFW_KEY_P), - hs_str_int("KEY_Q", GLFW_KEY_Q), - hs_str_int("KEY_R", GLFW_KEY_R), - hs_str_int("KEY_S", GLFW_KEY_S), - hs_str_int("KEY_T", GLFW_KEY_T), - hs_str_int("KEY_U", GLFW_KEY_U), - hs_str_int("KEY_V", GLFW_KEY_V), - hs_str_int("KEY_W", GLFW_KEY_W), - hs_str_int("KEY_X", GLFW_KEY_X), - hs_str_int("KEY_Y", GLFW_KEY_Y), - hs_str_int("KEY_Z", GLFW_KEY_Z), - hs_str_int("KEY_LEFT_BRACKET", GLFW_KEY_LEFT_BRACKET), - hs_str_int("KEY_BACKSLASH", GLFW_KEY_BACKSLASH), - hs_str_int("KEY_RIGHT_BRACKET", GLFW_KEY_RIGHT_BRACKET), - hs_str_int("KEY_GRAVE_ACCENT", GLFW_KEY_GRAVE_ACCENT), - hs_str_int("KEY_WORLD_1", GLFW_KEY_WORLD_1), - hs_str_int("KEY_WORLD_2", GLFW_KEY_WORLD_2), - hs_str_int("KEY_ESCAPE", GLFW_KEY_ESCAPE), - hs_str_int("KEY_ENTER", GLFW_KEY_ENTER), - hs_str_int("KEY_TAB", GLFW_KEY_TAB), - hs_str_int("KEY_BACKSPACE", GLFW_KEY_BACKSPACE), - hs_str_int("KEY_INSERT", GLFW_KEY_INSERT), - hs_str_int("KEY_DELETE", GLFW_KEY_DELETE), - hs_str_int("KEY_RIGHT", GLFW_KEY_RIGHT), - hs_str_int("KEY_LEFT", GLFW_KEY_LEFT), - hs_str_int("KEY_DOWN", GLFW_KEY_DOWN), - hs_str_int("KEY_UP", GLFW_KEY_UP), - hs_str_int("KEY_PAGE_UP", GLFW_KEY_PAGE_UP), - hs_str_int("KEY_PAGE_DOWN", GLFW_KEY_PAGE_DOWN), - hs_str_int("KEY_HOME", GLFW_KEY_HOME), - hs_str_int("KEY_END", GLFW_KEY_END), - hs_str_int("KEY_CAPS_LOCK", GLFW_KEY_CAPS_LOCK), - hs_str_int("KEY_SCROLL_LOCK", GLFW_KEY_SCROLL_LOCK), - hs_str_int("KEY_NUM_LOCK", GLFW_KEY_NUM_LOCK), - hs_str_int("KEY_PRINT_SCREEN", GLFW_KEY_PRINT_SCREEN), - hs_str_int("KEY_PAUSE", GLFW_KEY_PAUSE), - hs_str_int("KEY_F1", GLFW_KEY_F1), - hs_str_int("KEY_F2", GLFW_KEY_F2), - hs_str_int("KEY_F3", GLFW_KEY_F3), - hs_str_int("KEY_F4", GLFW_KEY_F4), - hs_str_int("KEY_F5", GLFW_KEY_F5), - hs_str_int("KEY_F6", GLFW_KEY_F6), - hs_str_int("KEY_F7", GLFW_KEY_F7), - hs_str_int("KEY_F8", GLFW_KEY_F8), - hs_str_int("KEY_F9", GLFW_KEY_F9), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_F", GLFW_KEY_F), - hs_str_int("KEY_KP_0", GLFW_KEY_KP_0), - hs_str_int("KEY_KP_1", GLFW_KEY_KP_1), - hs_str_int("KEY_KP_2", GLFW_KEY_KP_2), - hs_str_int("KEY_KP_3", GLFW_KEY_KP_3), - hs_str_int("KEY_KP_4", GLFW_KEY_KP_4), - hs_str_int("KEY_KP_5", GLFW_KEY_KP_5), - hs_str_int("KEY_KP_6", GLFW_KEY_KP_6), - hs_str_int("KEY_KP_7", GLFW_KEY_KP_7), - hs_str_int("KEY_KP_8", GLFW_KEY_KP_8), - hs_str_int("KEY_KP_9", GLFW_KEY_KP_9), - hs_str_int("KEY_KP_DECIMAL", GLFW_KEY_KP_DECIMAL), - hs_str_int("KEY_KP_DIVIDE", GLFW_KEY_KP_DIVIDE), - hs_str_int("KEY_KP_MULTIPLY", GLFW_KEY_KP_MULTIPLY), - hs_str_int("KEY_KP_SUBTRACT", GLFW_KEY_KP_SUBTRACT), - hs_str_int("KEY_KP_ADD", GLFW_KEY_KP_ADD), - hs_str_int("KEY_KP_ENTER", GLFW_KEY_KP_ENTER), - hs_str_int("KEY_KP_EQUAL", GLFW_KEY_KP_EQUAL), - hs_str_int("KEY_LEFT_SHIFT", GLFW_KEY_LEFT_SHIFT), - hs_str_int("KEY_LEFT_CONTROL", GLFW_KEY_LEFT_CONTROL), - hs_str_int("KEY_LEFT_ALT", GLFW_KEY_LEFT_ALT), - hs_str_int("KEY_LEFT_SUPER", GLFW_KEY_LEFT_SUPER), - hs_str_int("KEY_RIGHT_SHIFT", GLFW_KEY_RIGHT_SHIFT), - hs_str_int("KEY_RIGHT_CONTROL", GLFW_KEY_RIGHT_CONTROL), - hs_str_int("KEY_RIGHT_ALT", GLFW_KEY_RIGHT_ALT), - hs_str_int("KEY_RIGHT_SUPER", GLFW_KEY_RIGHT_SUPER), - hs_str_int("KEY_MENU", GLFW_KEY_MENU), + H_INT("KEY_UNKNOWN", GLFW_KEY_UNKNOWN), + H_INT("KEY_SPACE", GLFW_KEY_SPACE), + H_INT("KEY_APOSTROPHE", GLFW_KEY_APOSTROPHE), + H_INT("KEY_COMMA", GLFW_KEY_COMMA), + H_INT("KEY_MINUS", GLFW_KEY_MINUS), + H_INT("KEY_PERIOD", GLFW_KEY_PERIOD), + H_INT("KEY_SLASH", GLFW_KEY_SLASH), + H_INT("KEY_0", GLFW_KEY_0), + H_INT("KEY_1", GLFW_KEY_1), + H_INT("KEY_2", GLFW_KEY_2), + H_INT("KEY_3", GLFW_KEY_3), + H_INT("KEY_4", GLFW_KEY_4), + H_INT("KEY_5", GLFW_KEY_5), + H_INT("KEY_6", GLFW_KEY_6), + H_INT("KEY_7", GLFW_KEY_7), + H_INT("KEY_8", GLFW_KEY_8), + H_INT("KEY_9", GLFW_KEY_9), + H_INT("KEY_SEMICOLON", GLFW_KEY_SEMICOLON), + H_INT("KEY_EQUAL", GLFW_KEY_EQUAL), + H_INT("KEY_A", GLFW_KEY_A), + H_INT("KEY_B", GLFW_KEY_B), + H_INT("KEY_C", GLFW_KEY_C), + H_INT("KEY_D", GLFW_KEY_D), + H_INT("KEY_E", GLFW_KEY_E), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_G", GLFW_KEY_G), + H_INT("KEY_H", GLFW_KEY_H), + H_INT("KEY_I", GLFW_KEY_I), + H_INT("KEY_J", GLFW_KEY_J), + H_INT("KEY_K", GLFW_KEY_K), + H_INT("KEY_L", GLFW_KEY_L), + H_INT("KEY_M", GLFW_KEY_M), + H_INT("KEY_N", GLFW_KEY_N), + H_INT("KEY_O", GLFW_KEY_O), + H_INT("KEY_P", GLFW_KEY_P), + H_INT("KEY_Q", GLFW_KEY_Q), + H_INT("KEY_R", GLFW_KEY_R), + H_INT("KEY_S", GLFW_KEY_S), + H_INT("KEY_T", GLFW_KEY_T), + H_INT("KEY_U", GLFW_KEY_U), + H_INT("KEY_V", GLFW_KEY_V), + H_INT("KEY_W", GLFW_KEY_W), + H_INT("KEY_X", GLFW_KEY_X), + H_INT("KEY_Y", GLFW_KEY_Y), + H_INT("KEY_Z", GLFW_KEY_Z), + H_INT("KEY_LEFT_BRACKET", GLFW_KEY_LEFT_BRACKET), + H_INT("KEY_BACKSLASH", GLFW_KEY_BACKSLASH), + H_INT("KEY_RIGHT_BRACKET", GLFW_KEY_RIGHT_BRACKET), + H_INT("KEY_GRAVE_ACCENT", GLFW_KEY_GRAVE_ACCENT), + H_INT("KEY_WORLD_1", GLFW_KEY_WORLD_1), + H_INT("KEY_WORLD_2", GLFW_KEY_WORLD_2), + H_INT("KEY_ESCAPE", GLFW_KEY_ESCAPE), + H_INT("KEY_ENTER", GLFW_KEY_ENTER), + H_INT("KEY_TAB", GLFW_KEY_TAB), + H_INT("KEY_BACKSPACE", GLFW_KEY_BACKSPACE), + H_INT("KEY_INSERT", GLFW_KEY_INSERT), + H_INT("KEY_DELETE", GLFW_KEY_DELETE), + H_INT("KEY_RIGHT", GLFW_KEY_RIGHT), + H_INT("KEY_LEFT", GLFW_KEY_LEFT), + H_INT("KEY_DOWN", GLFW_KEY_DOWN), + H_INT("KEY_UP", GLFW_KEY_UP), + H_INT("KEY_PAGE_UP", GLFW_KEY_PAGE_UP), + H_INT("KEY_PAGE_DOWN", GLFW_KEY_PAGE_DOWN), + H_INT("KEY_HOME", GLFW_KEY_HOME), + H_INT("KEY_END", GLFW_KEY_END), + H_INT("KEY_CAPS_LOCK", GLFW_KEY_CAPS_LOCK), + H_INT("KEY_SCROLL_LOCK", GLFW_KEY_SCROLL_LOCK), + H_INT("KEY_NUM_LOCK", GLFW_KEY_NUM_LOCK), + H_INT("KEY_PRINT_SCREEN", GLFW_KEY_PRINT_SCREEN), + H_INT("KEY_PAUSE", GLFW_KEY_PAUSE), + H_INT("KEY_F1", GLFW_KEY_F1), + H_INT("KEY_F2", GLFW_KEY_F2), + H_INT("KEY_F3", GLFW_KEY_F3), + H_INT("KEY_F4", GLFW_KEY_F4), + H_INT("KEY_F5", GLFW_KEY_F5), + H_INT("KEY_F6", GLFW_KEY_F6), + H_INT("KEY_F7", GLFW_KEY_F7), + H_INT("KEY_F8", GLFW_KEY_F8), + H_INT("KEY_F9", GLFW_KEY_F9), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_F", GLFW_KEY_F), + H_INT("KEY_KP_0", GLFW_KEY_KP_0), + H_INT("KEY_KP_1", GLFW_KEY_KP_1), + H_INT("KEY_KP_2", GLFW_KEY_KP_2), + H_INT("KEY_KP_3", GLFW_KEY_KP_3), + H_INT("KEY_KP_4", GLFW_KEY_KP_4), + H_INT("KEY_KP_5", GLFW_KEY_KP_5), + H_INT("KEY_KP_6", GLFW_KEY_KP_6), + H_INT("KEY_KP_7", GLFW_KEY_KP_7), + H_INT("KEY_KP_8", GLFW_KEY_KP_8), + H_INT("KEY_KP_9", GLFW_KEY_KP_9), + H_INT("KEY_KP_DECIMAL", GLFW_KEY_KP_DECIMAL), + H_INT("KEY_KP_DIVIDE", GLFW_KEY_KP_DIVIDE), + H_INT("KEY_KP_MULTIPLY", GLFW_KEY_KP_MULTIPLY), + H_INT("KEY_KP_SUBTRACT", GLFW_KEY_KP_SUBTRACT), + H_INT("KEY_KP_ADD", GLFW_KEY_KP_ADD), + H_INT("KEY_KP_ENTER", GLFW_KEY_KP_ENTER), + H_INT("KEY_KP_EQUAL", GLFW_KEY_KP_EQUAL), + H_INT("KEY_LEFT_SHIFT", GLFW_KEY_LEFT_SHIFT), + H_INT("KEY_LEFT_CONTROL", GLFW_KEY_LEFT_CONTROL), + H_INT("KEY_LEFT_ALT", GLFW_KEY_LEFT_ALT), + H_INT("KEY_LEFT_SUPER", GLFW_KEY_LEFT_SUPER), + H_INT("KEY_RIGHT_SHIFT", GLFW_KEY_RIGHT_SHIFT), + H_INT("KEY_RIGHT_CONTROL", GLFW_KEY_RIGHT_CONTROL), + H_INT("KEY_RIGHT_ALT", GLFW_KEY_RIGHT_ALT), + H_INT("KEY_RIGHT_SUPER", GLFW_KEY_RIGHT_SUPER), + H_INT("KEY_MENU", GLFW_KEY_MENU), + + H_END }; + create_table(L, tbl); + int window_tbl = lua_gettop(L); + + struct honey_tbl_t hint_types[] = { + H_INT("contextVersionMajor", GLFW_CONTEXT_VERSION_MAJOR), + H_INT("contextVersionMinor", GLFW_CONTEXT_VERSION_MINOR), + H_INT("openGlProfile", GLFW_OPENGL_PROFILE), + H_END + }; + create_table(L, hint_types); + lua_setfield(L, window_tbl, "hintType"); + + struct honey_tbl_t profile_types[] = { + H_INT("openGlCoreProfile", GLFW_OPENGL_CORE_PROFILE), + H_END + }; + create_table(L, profile_types); + lua_setfield(L, window_tbl, "profileType"); - hs_create_table_(L, sizeof(tbl)/sizeof(struct hs_tbl_entry), tbl); lua_setfield(L, honey_index, "window"); } @@ -214,25 +221,27 @@ void setup_window(lua_State *L, int honey_index) static void framebuffer_size_callback_(GLFWwindow *win, int width, int height) { struct window_data *wdata = glfwGetWindowUserPointer(win); + lua_State *L = wdata->L; if (wdata->framebuffer_size_callback != LUA_NOREF) { - hs_rload(wdata->L, wdata->framebuffer_size_callback); - lua_pushlightuserdata(wdata->L, win); - lua_pushinteger(wdata->L, width); - lua_pushinteger(wdata->L, height); - lua_call(wdata->L, 3, 0); + lua_rawgeti(L, LUA_REGISTRYINDEX, wdata->framebuffer_size_callback); + lua_pushlightuserdata(L, win); + lua_pushinteger(L, width); + lua_pushinteger(L, height); + lua_call(L, 3, 0); } } int window_create(lua_State *L) { lua_Integer width, height; - char *title; - hs_parse_args(L, hs_int(width), hs_int(height), hs_str(title)); + width = luaL_checkinteger(L, 1); + height = luaL_checkinteger(L, 2); + const char *title = luaL_checkstring(L, 3); GLFWwindow **win = lua_newuserdata(L, sizeof(GLFWwindow *)); *win = glfwCreateWindow(width, height, title, NULL, NULL); if (*win == NULL) - hs_throw_error(L, "failed to create window"); + luaL_error(L, "failed to create window"); struct window_data *wdata = create_window_data(L); glfwSetWindowUserPointer(*win, wdata); @@ -317,7 +326,7 @@ int window_set_framebuffer_size_callback(lua_State *L) struct window_data *wdata = glfwGetWindowUserPointer(*win); lua_pushvalue(L, func); - wdata->framebuffer_size_callback = hs_rstore(L); + wdata->framebuffer_size_callback = luaL_ref(L, LUA_REGISTRYINDEX); return 0; } @@ -1,8 +1,8 @@ #include <lua.h> #include <lauxlib.h> #include <lualib.h> -#include <honeysuckle.h> #include "options/options.h" +#include "util/util.h" #include "modules.h" @@ -37,7 +37,7 @@ int main(int argc, char **argv) } /* run */ - err = hs_call(L, 0, 0); + err = h_call(L, 0, 0); if (err != 0) { const char *err_str = lua_tostring(L, -1); printf("failed to run: \n%s\n", err_str); |