diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cglm_bindings.c | 56 | ||||
-rw-r--r-- | src/cglm_bindings.h | 47 | ||||
-rw-r--r-- | src/honey.c | 3 | ||||
-rw-r--r-- | src/honey.h | 7 |
4 files changed, 107 insertions, 6 deletions
diff --git a/src/cglm_bindings.c b/src/cglm_bindings.c new file mode 100644 index 0000000..c50114c --- /dev/null +++ b/src/cglm_bindings.c @@ -0,0 +1,56 @@ +#include "cglm_bindings.h" + +void honey_setup_cglm(lua_State* L) +{ + honey_lua_element cglm_elements[] = { + { "new_array_zero", HONEY_FUNC, { .function = honey_cglm_new_array_zero } }, + { "set_value", HONEY_FUNC, { .function = honey_cglm_array_set_value } }, + { "get_value", HONEY_FUNC, { .function = honey_cglm_array_get_value } }, + }; + + honey_lua_create_table(L, cglm_elements, 3); +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int honey_cglm_new_array_zero(lua_State* L) +{ + if (!honey_lua_validate_types(L, 1, HONEY_INT)) + lua_error(L); + + int size = lua_tointeger(L, 1); + + float* array = lua_newuserdata(L, size*sizeof(float)); + memset(array, 0, size*sizeof(float)); + return 1; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int honey_cglm_array_set_value(lua_State* L) +{ + if (!honey_lua_validate_types(L, 3, HONEY_USERDATA, HONEY_INT, HONEY_NUM)) + lua_error(L); + + float* array = lua_touserdata(L, 1); + int index = lua_tointeger(L, 2); + float value = lua_tonumber(L, 3); + + array[index] = value; + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int honey_cglm_array_get_value(lua_State* L) +{ + if (!honey_lua_validate_types(L, 2, HONEY_USERDATA, HONEY_INT)) + lua_error(L); + + float* array = lua_touserdata(L, 1); + int index = lua_tointeger(L, 2); + + lua_pushnumber(L, array[index]); + return 1; +} + diff --git a/src/cglm_bindings.h b/src/cglm_bindings.h new file mode 100644 index 0000000..eaadc98 --- /dev/null +++ b/src/cglm_bindings.h @@ -0,0 +1,47 @@ +#ifndef HONEY_CGLM_BINDINGS_H +#define HONEY_CGLM_BINDINGS_H + +#include "common.h" + +/** @brief Push the honey cglm binding functions to the lua stack. + * + * @returns Nothing. + */ +void honey_setup_cglm(lua_State* L); + +/** @brief Push a new float array to the lua stack. + * + * This function initializes the array to all zeros. + * + * @param[in] n The size of the floating-point array to create. + * + * @returns The vector so generated. + */ +int honey_cglm_new_array_zero(lua_State* L); + +/** @brief Set an element of a float array. + * + * This function does NOT check if your index is out of bounds. + * Use caution! + * + * @param[in] array The array to modify. + * @param[in] index The index to set. + * @param[in] value The value to set array[index] to. + * + * @returns Nothing. + */ +int honey_cglm_array_set_value(lua_State* L); + +/** @brief Get an element of a vec3. + * + * This function does NOT check if your index is out of bounds. + * Use caution! + * + * @param[in] array The array to inspect. + * @param[in] index The index to get. + * + * @returns The value at array[index]. + */ +int honey_cglm_array_get_value(lua_State* L); + +#endif diff --git a/src/honey.c b/src/honey.c index da55ca6..73fb285 100644 --- a/src/honey.c +++ b/src/honey.c @@ -70,6 +70,9 @@ bool honey_setup(lua_State** L) honey_setup_input(*L); lua_setfield(*L, -2, "input"); + honey_setup_cglm(*L); + lua_setfield(*L, -2, "cglm"); + lua_pushcfunction(*L, honey_exit); lua_setfield(*L, -2, "exit"); diff --git a/src/honey.h b/src/honey.h index caa92e7..8231b70 100644 --- a/src/honey.h +++ b/src/honey.h @@ -9,10 +9,10 @@ #include "common.h" #include "camera/camera.h" +#include "cglm_bindings.h" #include "input/input.h" #include "light/light.h" #include "mesh/mesh.h" -#include "model/model.h" #include "primitives/primitives.h" #include "shader/shader.h" #include "texture/texture.h" @@ -68,9 +68,4 @@ bool honey_run(lua_State* L, honey_options opts); */ int honey_get_callback(lua_State* L, char* callback); -#define honey_set_resize_callback glfwSetFramebufferSizeCallback -#define honey_set_mouse_move_callback glfwSetCursorPosCallback - -#define honey_quit glfwTerminate - #endif |