diff options
Diffstat (limited to 'src/gl/gl.c')
-rw-r--r-- | src/gl/gl.c | 57 |
1 files changed, 30 insertions, 27 deletions
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; } |