diff options
author | sanine-a <sanine.not@pm.me> | 2020-10-23 21:52:10 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-10-23 21:52:10 -0500 |
commit | 4749e1a01e989999eef9f4131cf2edf6e3211ebc (patch) | |
tree | fb7716037e302bed236f9ff2134a5631d26b912e /src | |
parent | 78553e775f618d20e328bc85c635fbab4bf43d60 (diff) |
add key binding input functions
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 31 | ||||
-rw-r--r-- | src/honey_lua.c | 184 | ||||
-rw-r--r-- | src/input/input.c | 2041 | ||||
-rw-r--r-- | src/input/input.h | 11 | ||||
-rw-r--r-- | src/main.c | 153 |
5 files changed, 1327 insertions, 1093 deletions
diff --git a/src/common.h b/src/common.h index bf9a528..66500eb 100644 --- a/src/common.h +++ b/src/common.h @@ -74,16 +74,47 @@ void honey_error_set_string2(char* string); */ void honey_human_readable_error(char* error_string, honey_result error); +/** @brief Generate a string from a format string. + * + * This function allocates memory for the destination; the user is + * responsible for deallocating it. As a side effect of this, the destination + * pointer cannot overlap with any of the varargs. + * + * @param[out] string Pointer to the destination string. + * @param[in] format_string The format string used to generate the result. + * @param[in] ... The arguments for the format string. + * + * @returns HONEY_OK on success; HONEY_MEMORY_ALLOCATION_ERROR on a + * memory allocation error. + */ +honey_result honey_format_string(char** string, + char* format_string, + ...); + /* lua binding functions */ typedef enum { + HONEY_BOOL, HONEY_INT, HONEY_NUM, HONEY_STRING, HONEY_FUNC, HONEY_TABLE, + HONEY_NIL, + HONEY_ANY } honey_lua_type; +/** @brief Check that a functions' arguments are of the correct type. + * + * @param[in] L The lua state to validate. + * @param[in] n_types The number of types to validate. + * @param[in] ... Variadic list of honey_lua_types to validate against the stack. + * + * @returns true if the validation was successful; false otherwise, pushing an error message + * to the lua stack. + */ +bool honey_lua_validate_types(lua_State* L, unsigned int n_types, ...); + /** @brief Wrap C objects for lua. */ typedef struct honey_lua_element { char* name; diff --git a/src/honey_lua.c b/src/honey_lua.c index 1cbd483..f397872 100644 --- a/src/honey_lua.c +++ b/src/honey_lua.c @@ -1,46 +1,192 @@ #include "common.h" +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +honey_result honey_format_string(char** string, + char* format_string, + ...) +{ + honey_result res; + va_list args, args_; + va_start(args, format_string); + va_copy(args_, args); + + int string_size = vsnprintf(NULL, 0, format_string, args_); + va_end(args_); + *string = malloc((string_size+1) * sizeof(char)); + if (*string == NULL) + res = HONEY_MEMORY_ALLOCATION_ERROR; + else { + vsnprintf(*string, string_size+1, format_string, args); + res = HONEY_OK; + } + + va_end(args); + + return res; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +bool honey_lua_validate_types(lua_State* L, + unsigned int n_types, + ...) +{ + va_list args; + va_start(args, n_types); + + for (int i=0; i<n_types; i++) { + honey_lua_type expected_type = va_arg(args, honey_lua_type); + honey_result result; + char* error_message; + + switch(expected_type) { + case HONEY_BOOL: + if (!lua_isboolean(L, i+1)) { + result = honey_format_string(&error_message, + "Expected boolean in position %d", + i); + if (result != HONEY_OK) + lua_pushstring(L, "Expected boolean; allocation error occurred for more detailed message."); + else { + lua_pushstring(L, error_message); + free(error_message); + } + return false; + } + break; + + case HONEY_INT: + case HONEY_NUM: + if (!lua_isnumber(L, i+1)) { + result = honey_format_string(&error_message, + "Expected number in position %d", + i); + if (result != HONEY_OK) + lua_pushstring(L, "Expected number; allocation error occurred for more detailed message."); + else { + lua_pushstring(L, error_message); + free(error_message); + } + return false; + } + break; + + case HONEY_STRING: + if (!lua_isstring(L, i+1)) { + result = honey_format_string(&error_message, + "Expected string in position %d", + i); + if (result != HONEY_OK) + lua_pushstring(L, "Expected string; allocation error occurred for more detailed message."); + else { + lua_pushstring(L, error_message); + free(error_message); + } + return false; + } + break; + + case HONEY_FUNC: + if (!lua_isfunction(L, i+1)) { + result = honey_format_string(&error_message, + "Expected function in position %d", + i); + if (result != HONEY_OK) + lua_pushstring(L, "Expected function; allocation error occurred for more detailed message."); + else { + lua_pushstring(L, error_message); + free(error_message); + } + return false; + } + break; + + case HONEY_TABLE: + if (!lua_istable(L, i+1)) { + result = honey_format_string(&error_message, + "Expected table in position %d", + i); + if (result != HONEY_OK) + lua_pushstring(L, "Expected table; allocation error occurred for more detailed message."); + else { + lua_pushstring(L, error_message); + free(error_message); + } + return false; + } + break; + + case HONEY_NIL: + if (!lua_isnil(L, i+1)) { + result = honey_format_string(&error_message, + "Expected nil in position %d", + i); + if (result != HONEY_OK) + lua_pushstring(L, "Expected nil; allocation error occurred for more detailed message."); + else { + lua_pushstring(L, error_message); + free(error_message); + } + return false; + } + break; + + case HONEY_ANY: + break; + + default: + break; + } + } + + va_end(args); + return true; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + void honey_lua_create_table(lua_State* L, - honey_lua_element* elements, - unsigned int n_elements) + honey_lua_element* elements, + unsigned int n_elements) { lua_createtable(L, 0, n_elements); for (int i=0; i<n_elements; i++) { - honey_lua_push_element(L, elements[i]); - lua_setfield(L, -2, elements[i].name); + honey_lua_push_element(L, elements[i]); + lua_setfield(L, -2, elements[i].name); } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - + void honey_lua_push_element(lua_State* L, honey_lua_element element) { switch(element.type) { case HONEY_INT: - lua_pushinteger(L, element.data.integer); - break; + lua_pushinteger(L, element.data.integer); + break; case HONEY_NUM: - lua_pushnumber(L, element.data.number); - break; + lua_pushnumber(L, element.data.number); + break; case HONEY_STRING: - lua_pushstring(L, element.data.string); - break; + lua_pushstring(L, element.data.string); + break; case HONEY_FUNC: - lua_pushcfunction(L, element.data.function); - break; + lua_pushcfunction(L, element.data.function); + break; case HONEY_TABLE: - honey_lua_create_table(L, - element.data.table.elements, - element.data.table.n_elements); - break; + honey_lua_create_table(L, + element.data.table.elements, + element.data.table.n_elements); + break; default: - // this should never happen - break; + // this should never happen + break; } } diff --git a/src/input/input.c b/src/input/input.c index ffca84e..ec28695 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -3,10 +3,8 @@ void honey_setup_keyboard() { memset(honey_key_states, 0, sizeof(honey_key_states)); - memset(honey_key_callbacks, 0, sizeof(honey_key_callbacks)); - memset(honey_key_callbacks_data, 0, sizeof(honey_key_callbacks_data)); - - honey_keyboard_callback = &default_honey_keyboard_callback; + memset(honey_key_callbacks, LUA_NOREF, sizeof(honey_key_callbacks)); + memset(honey_key_callbacks_data, LUA_NOREF, sizeof(honey_key_callbacks_data)); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -16,135 +14,138 @@ void honey_setup_input(lua_State* L) honey_setup_keyboard(); honey_lua_element keyElements[] = { - { "unknown", HONEY_INT, { HONEY_KEY_UNKNOWN } }, - { "space", HONEY_INT, { HONEY_KEY_SPACE } }, - { "apostrophe", HONEY_INT, { HONEY_KEY_APOSTROPHE } }, - { "comma", HONEY_INT, { HONEY_KEY_COMMA } }, - { "minus", HONEY_INT, { HONEY_KEY_MINUS } }, - { "period", HONEY_INT, { HONEY_KEY_PERIOD } }, - { "slash", HONEY_INT, { HONEY_KEY_SLASH } }, - { "0", HONEY_INT, { HONEY_KEY_0 } }, - { "1", HONEY_INT, { HONEY_KEY_1 } }, - { "2", HONEY_INT, { HONEY_KEY_2 } }, - { "3", HONEY_INT, { HONEY_KEY_3 } }, - { "4", HONEY_INT, { HONEY_KEY_4 } }, - { "5", HONEY_INT, { HONEY_KEY_5 } }, - { "6", HONEY_INT, { HONEY_KEY_6 } }, - { "7", HONEY_INT, { HONEY_KEY_7 } }, - { "8", HONEY_INT, { HONEY_KEY_8 } }, - { "9", HONEY_INT, { HONEY_KEY_9 } }, - { "semicolon", HONEY_INT, { HONEY_KEY_SEMICOLON } }, - { "equal", HONEY_INT, { HONEY_KEY_EQUAL } }, - { "a", HONEY_INT, { HONEY_KEY_A } }, - { "b", HONEY_INT, { HONEY_KEY_B } }, - { "c", HONEY_INT, { HONEY_KEY_C } }, - { "d", HONEY_INT, { HONEY_KEY_D } }, - { "e", HONEY_INT, { HONEY_KEY_E } }, - { "f", HONEY_INT, { HONEY_KEY_F } }, - { "g", HONEY_INT, { HONEY_KEY_G } }, - { "h", HONEY_INT, { HONEY_KEY_H } }, - { "i", HONEY_INT, { HONEY_KEY_I } }, - { "j", HONEY_INT, { HONEY_KEY_J } }, - { "k", HONEY_INT, { HONEY_KEY_K } }, - { "l", HONEY_INT, { HONEY_KEY_L } }, - { "m", HONEY_INT, { HONEY_KEY_M } }, - { "n", HONEY_INT, { HONEY_KEY_N } }, - { "o", HONEY_INT, { HONEY_KEY_O } }, - { "p", HONEY_INT, { HONEY_KEY_P } }, - { "q", HONEY_INT, { HONEY_KEY_Q } }, - { "r", HONEY_INT, { HONEY_KEY_R } }, - { "s", HONEY_INT, { HONEY_KEY_S } }, - { "t", HONEY_INT, { HONEY_KEY_T } }, - { "u", HONEY_INT, { HONEY_KEY_U } }, - { "v", HONEY_INT, { HONEY_KEY_V } }, - { "w", HONEY_INT, { HONEY_KEY_W } }, - { "x", HONEY_INT, { HONEY_KEY_X } }, - { "y", HONEY_INT, { HONEY_KEY_Y } }, - { "z", HONEY_INT, { HONEY_KEY_Z } }, - { "left_bracket", HONEY_INT, { HONEY_KEY_LEFT_BRACKET } }, - { "backslash", HONEY_INT, { HONEY_KEY_BACKSLASH } }, - { "right_bracket", HONEY_INT, { HONEY_KEY_RIGHT_BRACKET } }, - { "grave_accent", HONEY_INT, { HONEY_KEY_GRAVE_ACCENT } }, - { "world_1", HONEY_INT, { HONEY_KEY_WORLD_1 } }, - { "world_2", HONEY_INT, { HONEY_KEY_WORLD_2 } }, - { "escape", HONEY_INT, { HONEY_KEY_ESCAPE } }, - { "enter", HONEY_INT, { HONEY_KEY_ENTER } }, - { "tab", HONEY_INT, { HONEY_KEY_TAB } }, - { "backspace", HONEY_INT, { HONEY_KEY_BACKSPACE } }, - { "insert", HONEY_INT, { HONEY_KEY_INSERT } }, - { "delete", HONEY_INT, { HONEY_KEY_DELETE } }, - { "right", HONEY_INT, { HONEY_KEY_RIGHT } }, - { "left", HONEY_INT, { HONEY_KEY_LEFT } }, - { "down", HONEY_INT, { HONEY_KEY_DOWN } }, - { "up", HONEY_INT, { HONEY_KEY_UP } }, - { "page_up", HONEY_INT, { HONEY_KEY_PAGE_UP } }, - { "page_down", HONEY_INT, { HONEY_KEY_PAGE_DOWN } }, - { "home", HONEY_INT, { HONEY_KEY_HOME } }, - { "end", HONEY_INT, { HONEY_KEY_END } }, - { "caps_lock", HONEY_INT, { HONEY_KEY_CAPS_LOCK } }, - { "scroll_lock", HONEY_INT, { HONEY_KEY_SCROLL_LOCK } }, - { "num_lock", HONEY_INT, { HONEY_KEY_NUM_LOCK } }, - { "print_screen", HONEY_INT, { HONEY_KEY_PRINT_SCREEN } }, - { "pause", HONEY_INT, { HONEY_KEY_PAUSE } }, - { "f1", HONEY_INT, { HONEY_KEY_F1 } }, - { "f2", HONEY_INT, { HONEY_KEY_F2 } }, - { "f3", HONEY_INT, { HONEY_KEY_F3 } }, - { "f4", HONEY_INT, { HONEY_KEY_F4 } }, - { "f5", HONEY_INT, { HONEY_KEY_F5 } }, - { "f6", HONEY_INT, { HONEY_KEY_F6 } }, - { "f7", HONEY_INT, { HONEY_KEY_F7 } }, - { "f8", HONEY_INT, { HONEY_KEY_F8 } }, - { "f9", HONEY_INT, { HONEY_KEY_F9 } }, - { "f10", HONEY_INT, { HONEY_KEY_F10 } }, - { "f11", HONEY_INT, { HONEY_KEY_F11 } }, - { "f12", HONEY_INT, { HONEY_KEY_F12 } }, - { "f13", HONEY_INT, { HONEY_KEY_F13 } }, - { "f14", HONEY_INT, { HONEY_KEY_F14 } }, - { "f15", HONEY_INT, { HONEY_KEY_F15 } }, - { "f16", HONEY_INT, { HONEY_KEY_F16 } }, - { "f17", HONEY_INT, { HONEY_KEY_F17 } }, - { "f18", HONEY_INT, { HONEY_KEY_F18 } }, - { "f19", HONEY_INT, { HONEY_KEY_F19 } }, - { "f20", HONEY_INT, { HONEY_KEY_F20 } }, - { "f21", HONEY_INT, { HONEY_KEY_F21 } }, - { "f22", HONEY_INT, { HONEY_KEY_F22 } }, - { "f23", HONEY_INT, { HONEY_KEY_F23 } }, - { "f24", HONEY_INT, { HONEY_KEY_F24 } }, - { "f25", HONEY_INT, { HONEY_KEY_F25 } }, - { "kp_0", HONEY_INT, { HONEY_KEY_KP_0 } }, - { "kp_1", HONEY_INT, { HONEY_KEY_KP_1 } }, - { "kp_2", HONEY_INT, { HONEY_KEY_KP_2 } }, - { "kp_3", HONEY_INT, { HONEY_KEY_KP_3 } }, - { "kp_4", HONEY_INT, { HONEY_KEY_KP_4 } }, - { "kp_5", HONEY_INT, { HONEY_KEY_KP_5 } }, - { "kp_6", HONEY_INT, { HONEY_KEY_KP_6 } }, - { "kp_7", HONEY_INT, { HONEY_KEY_KP_7 } }, - { "kp_8", HONEY_INT, { HONEY_KEY_KP_8 } }, - { "kp_9", HONEY_INT, { HONEY_KEY_KP_9 } }, - { "kp_decimal", HONEY_INT, { HONEY_KEY_KP_DECIMAL } }, - { "kp_divide", HONEY_INT, { HONEY_KEY_KP_DIVIDE } }, - { "kp_multiply", HONEY_INT, { HONEY_KEY_KP_MULTIPLY } }, - { "kp_subtract", HONEY_INT, { HONEY_KEY_KP_SUBTRACT } }, - { "kp_add", HONEY_INT, { HONEY_KEY_KP_ADD } }, - { "kp_enter", HONEY_INT, { HONEY_KEY_KP_ENTER } }, - { "kp_equal", HONEY_INT, { HONEY_KEY_KP_EQUAL } }, - { "left_shift", HONEY_INT, { HONEY_KEY_LEFT_SHIFT } }, - { "left_control", HONEY_INT, { HONEY_KEY_LEFT_CONTROL } }, - { "left_alt", HONEY_INT, { HONEY_KEY_LEFT_ALT } }, - { "left_super", HONEY_INT, { HONEY_KEY_LEFT_SUPER } }, - { "right_shift", HONEY_INT, { HONEY_KEY_RIGHT_SHIFT } }, - { "right_control", HONEY_INT, { HONEY_KEY_RIGHT_CONTROL } }, - { "right_alt", HONEY_INT, { HONEY_KEY_RIGHT_ALT } }, - { "right_super", HONEY_INT, { HONEY_KEY_RIGHT_SUPER } }, - { "menu", HONEY_INT, { HONEY_KEY_MENU } }, + { "unknown", HONEY_INT, { HONEY_KEY_UNKNOWN } }, + { "space", HONEY_INT, { HONEY_KEY_SPACE } }, + { "apostrophe", HONEY_INT, { HONEY_KEY_APOSTROPHE } }, + { "comma", HONEY_INT, { HONEY_KEY_COMMA } }, + { "minus", HONEY_INT, { HONEY_KEY_MINUS } }, + { "period", HONEY_INT, { HONEY_KEY_PERIOD } }, + { "slash", HONEY_INT, { HONEY_KEY_SLASH } }, + { "0", HONEY_INT, { HONEY_KEY_0 } }, + { "1", HONEY_INT, { HONEY_KEY_1 } }, + { "2", HONEY_INT, { HONEY_KEY_2 } }, + { "3", HONEY_INT, { HONEY_KEY_3 } }, + { "4", HONEY_INT, { HONEY_KEY_4 } }, + { "5", HONEY_INT, { HONEY_KEY_5 } }, + { "6", HONEY_INT, { HONEY_KEY_6 } }, + { "7", HONEY_INT, { HONEY_KEY_7 } }, + { "8", HONEY_INT, { HONEY_KEY_8 } }, + { "9", HONEY_INT, { HONEY_KEY_9 } }, + { "semicolon", HONEY_INT, { HONEY_KEY_SEMICOLON } }, + { "equal", HONEY_INT, { HONEY_KEY_EQUAL } }, + { "a", HONEY_INT, { HONEY_KEY_A } }, + { "b", HONEY_INT, { HONEY_KEY_B } }, + { "c", HONEY_INT, { HONEY_KEY_C } }, + { "d", HONEY_INT, { HONEY_KEY_D } }, + { "e", HONEY_INT, { HONEY_KEY_E } }, + { "f", HONEY_INT, { HONEY_KEY_F } }, + { "g", HONEY_INT, { HONEY_KEY_G } }, + { "h", HONEY_INT, { HONEY_KEY_H } }, + { "i", HONEY_INT, { HONEY_KEY_I } }, + { "j", HONEY_INT, { HONEY_KEY_J } }, + { "k", HONEY_INT, { HONEY_KEY_K } }, + { "l", HONEY_INT, { HONEY_KEY_L } }, + { "m", HONEY_INT, { HONEY_KEY_M } }, + { "n", HONEY_INT, { HONEY_KEY_N } }, + { "o", HONEY_INT, { HONEY_KEY_O } }, + { "p", HONEY_INT, { HONEY_KEY_P } }, + { "q", HONEY_INT, { HONEY_KEY_Q } }, + { "r", HONEY_INT, { HONEY_KEY_R } }, + { "s", HONEY_INT, { HONEY_KEY_S } }, + { "t", HONEY_INT, { HONEY_KEY_T } }, + { "u", HONEY_INT, { HONEY_KEY_U } }, + { "v", HONEY_INT, { HONEY_KEY_V } }, + { "w", HONEY_INT, { HONEY_KEY_W } }, + { "x", HONEY_INT, { HONEY_KEY_X } }, + { "y", HONEY_INT, { HONEY_KEY_Y } }, + { "z", HONEY_INT, { HONEY_KEY_Z } }, + { "left_bracket", HONEY_INT, { HONEY_KEY_LEFT_BRACKET } }, + { "backslash", HONEY_INT, { HONEY_KEY_BACKSLASH } }, + { "right_bracket", HONEY_INT, { HONEY_KEY_RIGHT_BRACKET } }, + { "grave_accent", HONEY_INT, { HONEY_KEY_GRAVE_ACCENT } }, + { "world_1", HONEY_INT, { HONEY_KEY_WORLD_1 } }, + { "world_2", HONEY_INT, { HONEY_KEY_WORLD_2 } }, + { "escape", HONEY_INT, { HONEY_KEY_ESCAPE } }, + { "enter", HONEY_INT, { HONEY_KEY_ENTER } }, + { "tab", HONEY_INT, { HONEY_KEY_TAB } }, + { "backspace", HONEY_INT, { HONEY_KEY_BACKSPACE } }, + { "insert", HONEY_INT, { HONEY_KEY_INSERT } }, + { "delete", HONEY_INT, { HONEY_KEY_DELETE } }, + { "right", HONEY_INT, { HONEY_KEY_RIGHT } }, + { "left", HONEY_INT, { HONEY_KEY_LEFT } }, + { "down", HONEY_INT, { HONEY_KEY_DOWN } }, + { "up", HONEY_INT, { HONEY_KEY_UP } }, + { "page_up", HONEY_INT, { HONEY_KEY_PAGE_UP } }, + { "page_down", HONEY_INT, { HONEY_KEY_PAGE_DOWN } }, + { "home", HONEY_INT, { HONEY_KEY_HOME } }, + { "end", HONEY_INT, { HONEY_KEY_END } }, + { "caps_lock", HONEY_INT, { HONEY_KEY_CAPS_LOCK } }, + { "scroll_lock", HONEY_INT, { HONEY_KEY_SCROLL_LOCK } }, + { "num_lock", HONEY_INT, { HONEY_KEY_NUM_LOCK } }, + { "print_screen", HONEY_INT, { HONEY_KEY_PRINT_SCREEN } }, + { "pause", HONEY_INT, { HONEY_KEY_PAUSE } }, + { "f1", HONEY_INT, { HONEY_KEY_F1 } }, + { "f2", HONEY_INT, { HONEY_KEY_F2 } }, + { "f3", HONEY_INT, { HONEY_KEY_F3 } }, + { "f4", HONEY_INT, { HONEY_KEY_F4 } }, + { "f5", HONEY_INT, { HONEY_KEY_F5 } }, + { "f6", HONEY_INT, { HONEY_KEY_F6 } }, + { "f7", HONEY_INT, { HONEY_KEY_F7 } }, + { "f8", HONEY_INT, { HONEY_KEY_F8 } }, + { "f9", HONEY_INT, { HONEY_KEY_F9 } }, + { "f10", HONEY_INT, { HONEY_KEY_F10 } }, + { "f11", HONEY_INT, { HONEY_KEY_F11 } }, + { "f12", HONEY_INT, { HONEY_KEY_F12 } }, + { "f13", HONEY_INT, { HONEY_KEY_F13 } }, + { "f14", HONEY_INT, { HONEY_KEY_F14 } }, + { "f15", HONEY_INT, { HONEY_KEY_F15 } }, + { "f16", HONEY_INT, { HONEY_KEY_F16 } }, + { "f17", HONEY_INT, { HONEY_KEY_F17 } }, + { "f18", HONEY_INT, { HONEY_KEY_F18 } }, + { "f19", HONEY_INT, { HONEY_KEY_F19 } }, + { "f20", HONEY_INT, { HONEY_KEY_F20 } }, + { "f21", HONEY_INT, { HONEY_KEY_F21 } }, + { "f22", HONEY_INT, { HONEY_KEY_F22 } }, + { "f23", HONEY_INT, { HONEY_KEY_F23 } }, + { "f24", HONEY_INT, { HONEY_KEY_F24 } }, + { "f25", HONEY_INT, { HONEY_KEY_F25 } }, + { "kp_0", HONEY_INT, { HONEY_KEY_KP_0 } }, + { "kp_1", HONEY_INT, { HONEY_KEY_KP_1 } }, + { "kp_2", HONEY_INT, { HONEY_KEY_KP_2 } }, + { "kp_3", HONEY_INT, { HONEY_KEY_KP_3 } }, + { "kp_4", HONEY_INT, { HONEY_KEY_KP_4 } }, + { "kp_5", HONEY_INT, { HONEY_KEY_KP_5 } }, + { "kp_6", HONEY_INT, { HONEY_KEY_KP_6 } }, + { "kp_7", HONEY_INT, { HONEY_KEY_KP_7 } }, + { "kp_8", HONEY_INT, { HONEY_KEY_KP_8 } }, + { "kp_9", HONEY_INT, { HONEY_KEY_KP_9 } }, + { "kp_decimal", HONEY_INT, { HONEY_KEY_KP_DECIMAL } }, + { "kp_divide", HONEY_INT, { HONEY_KEY_KP_DIVIDE } }, + { "kp_multiply", HONEY_INT, { HONEY_KEY_KP_MULTIPLY } }, + { "kp_subtract", HONEY_INT, { HONEY_KEY_KP_SUBTRACT } }, + { "kp_add", HONEY_INT, { HONEY_KEY_KP_ADD } }, + { "kp_enter", HONEY_INT, { HONEY_KEY_KP_ENTER } }, + { "kp_equal", HONEY_INT, { HONEY_KEY_KP_EQUAL } }, + { "left_shift", HONEY_INT, { HONEY_KEY_LEFT_SHIFT } }, + { "left_control", HONEY_INT, { HONEY_KEY_LEFT_CONTROL } }, + { "left_alt", HONEY_INT, { HONEY_KEY_LEFT_ALT } }, + { "left_super", HONEY_INT, { HONEY_KEY_LEFT_SUPER } }, + { "right_shift", HONEY_INT, { HONEY_KEY_RIGHT_SHIFT } }, + { "right_control", HONEY_INT, { HONEY_KEY_RIGHT_CONTROL } }, + { "right_alt", HONEY_INT, { HONEY_KEY_RIGHT_ALT } }, + { "right_super", HONEY_INT, { HONEY_KEY_RIGHT_SUPER } }, + { "menu", HONEY_INT, { HONEY_KEY_MENU } }, }; honey_lua_element inputElements[] = { - { "key", HONEY_TABLE, { .table={ HONEY_N_KEYS, keyElements } } }, - { "is_down", HONEY_FUNC, { .function = honey_key_down } } + { "key", HONEY_TABLE, { .table={ HONEY_N_KEYS, keyElements } } }, + { "is_down", HONEY_FUNC, { .function = honey_key_down } }, + { "bind_key", HONEY_FUNC, { .function = honey_key_bind } }, + { "unbind_key", HONEY_FUNC, { .function = honey_key_unbind } }, + { "unbind_all_keys", HONEY_FUNC, { .function = honey_key_unbind_all } }, }; - honey_lua_create_table(L, inputElements, 2); + honey_lua_create_table(L, inputElements, 5); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -152,48 +153,100 @@ void honey_setup_input(lua_State* L) int honey_key_down(lua_State* L) { if (!lua_isnumber(L, 1)) - return 0; + return 0; int key = lua_tointeger(L, 1); if (key < 0 || key >= HONEY_N_KEYS) - lua_pushboolean(L, false); + lua_pushboolean(L, false); else - lua_pushboolean(L, honey_key_states[key]); + lua_pushboolean(L, honey_key_states[key]); - printf("check key %d: %d\n", key, honey_key_states[key]); - return 1; } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void honey_key_bind(int key, - void (*callback)(void*, int), - void* data) +int honey_key_bind(lua_State* L) { + /* lua params: (int) key, (func) callback, (arb) data */ + int n_args = lua_gettop(L); + if (n_args == 3) { + if (!honey_lua_validate_types(L, 3, HONEY_INT, HONEY_FUNC, HONEY_ANY)) { + lua_error(L); + } + } + else if (n_args == 2) { + if (!honey_lua_validate_types(L, 2, HONEY_INT, HONEY_FUNC)) { + lua_error(L); + } + } + else { + char* error_message; + honey_format_string(error_message, "expected 2 or 3 arguments; received %d instead", n_args); + free(error_message); + lua_error(L); + } + + int key = lua_tointeger(L, 1); + lua_pushvalue(L, 2); + int callback = luaL_ref(L, LUA_REGISTRYINDEX); + lua_pushvalue(L, 3); + int data = luaL_ref(L, LUA_REGISTRYINDEX); + if (key >= 0 && key < HONEY_N_KEYS) { - honey_key_callbacks[key] = callback; - honey_key_callbacks_data[key] = data; + honey_key_callbacks[key] = callback; + honey_key_callbacks_data[key] = data; } + + return 0; } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void honey_key_unbind(int key) +int honey_key_unbind(lua_State* L) { + /* lua params: (int) key */ + if (!honey_lua_validate_types(L, 1, HONEY_INT)) + lua_error(L); + + int key = lua_tointeger(L, 1); + if (key >=0 && key < HONEY_N_KEYS) { - honey_key_callbacks[key] = NULL; - honey_key_callbacks_data[key] = NULL; + honey_key_callbacks[key] = LUA_NOREF; + honey_key_callbacks_data[key] = LUA_NOREF; + } + else { + char* error_message; + honey_format_string(&error_message, "'%d' is not a valid keycode", key); + lua_pushstring(L, error_message); + free(error_message); + lua_error(L); } + return 0; } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void honey_key_unbind_all() +int honey_key_unbind_all(lua_State* L) { for (int i=0; i<HONEY_N_KEYS; i++) { - honey_key_callbacks[i] = NULL; - honey_key_callbacks_data[i] = NULL; + honey_key_callbacks[i] = LUA_NOREF; + honey_key_callbacks_data[i] = LUA_NOREF; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +static void execute_lua_key_callback(lua_State* L, int callback, int action, int data) +{ + if (callback != LUA_NOREF) { + lua_rawgeti(L, LUA_REGISTRYINDEX, callback); + lua_pushinteger(L, action); + if (data != LUA_REFNIL) + lua_rawgeti(L, LUA_REGISTRYINDEX, data); + else + lua_pushnil(L); + lua_pcall(L, 2, 0, 0); } } @@ -201,978 +254,980 @@ void honey_key_unbind_all() void default_honey_keyboard_callback(honey_window window, int key, int scancode, int action, int mods) { + int callback, data; + lua_State* L = (lua_State*) glfwGetWindowUserPointer(window); switch (key) { case GLFW_KEY_UNKNOWN: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_UNKNOWN] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_UNKNOWN] = 0; } - if (honey_key_callbacks[HONEY_KEY_UNKNOWN] != NULL) { - honey_key_callbacks[HONEY_KEY_UNKNOWN](honey_key_callbacks_data[HONEY_KEY_UNKNOWN], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_UNKNOWN] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_UNKNOWN] = 0; } + callback = honey_key_callbacks[HONEY_KEY_UNKNOWN]; + data = honey_key_callbacks_data[HONEY_KEY_UNKNOWN]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_SPACE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SPACE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SPACE] = 0; } - if (honey_key_callbacks[HONEY_KEY_SPACE] != NULL) { - honey_key_callbacks[HONEY_KEY_SPACE] (honey_key_callbacks_data[HONEY_KEY_SPACE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SPACE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SPACE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_SPACE]; + data = honey_key_callbacks_data[HONEY_KEY_SPACE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_APOSTROPHE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_APOSTROPHE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_APOSTROPHE] = 0; } - if (honey_key_callbacks[HONEY_KEY_APOSTROPHE] != NULL) { - honey_key_callbacks[HONEY_KEY_APOSTROPHE] (honey_key_callbacks_data[HONEY_KEY_APOSTROPHE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_APOSTROPHE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_APOSTROPHE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_APOSTROPHE]; + data = honey_key_callbacks_data[HONEY_KEY_APOSTROPHE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_COMMA: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_COMMA] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_COMMA] = 0; } - if (honey_key_callbacks[HONEY_KEY_COMMA] != NULL) { - honey_key_callbacks[HONEY_KEY_COMMA] (honey_key_callbacks_data[HONEY_KEY_COMMA], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_COMMA] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_COMMA] = 0; } + callback = honey_key_callbacks[HONEY_KEY_COMMA]; + data = honey_key_callbacks_data[HONEY_KEY_COMMA]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_MINUS: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_MINUS] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_MINUS] = 0; } - if (honey_key_callbacks[HONEY_KEY_MINUS] != NULL) { - honey_key_callbacks[HONEY_KEY_MINUS] (honey_key_callbacks_data[HONEY_KEY_MINUS], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_MINUS] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_MINUS] = 0; } + callback = honey_key_callbacks[HONEY_KEY_MINUS]; + data = honey_key_callbacks_data[HONEY_KEY_MINUS]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_PERIOD: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PERIOD] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PERIOD] = 0; } - if (honey_key_callbacks[HONEY_KEY_PERIOD] != NULL) { - honey_key_callbacks[HONEY_KEY_PERIOD] (honey_key_callbacks_data[HONEY_KEY_PERIOD], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PERIOD] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PERIOD] = 0; } + callback = honey_key_callbacks[HONEY_KEY_PERIOD]; + data = honey_key_callbacks_data[HONEY_KEY_PERIOD]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_SLASH: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SLASH] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SLASH] = 0; } - if (honey_key_callbacks[HONEY_KEY_SLASH] != NULL) { - honey_key_callbacks[HONEY_KEY_SLASH] (honey_key_callbacks_data[HONEY_KEY_SLASH], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SLASH] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SLASH] = 0; } + callback = honey_key_callbacks[HONEY_KEY_SLASH]; + data = honey_key_callbacks_data[HONEY_KEY_SLASH]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_0: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_0] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_0] = 0; } - if (honey_key_callbacks[HONEY_KEY_0] != NULL) { - honey_key_callbacks[HONEY_KEY_0] (honey_key_callbacks_data[HONEY_KEY_0], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_0] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_0] = 0; } + callback = honey_key_callbacks[HONEY_KEY_0]; + data = honey_key_callbacks_data[HONEY_KEY_0]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_1: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_1] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_1] = 0; } - if (honey_key_callbacks[HONEY_KEY_1] != NULL) { - honey_key_callbacks[HONEY_KEY_1] (honey_key_callbacks_data[HONEY_KEY_1], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_1] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_1] = 0; } + callback = honey_key_callbacks[HONEY_KEY_1]; + data = honey_key_callbacks_data[HONEY_KEY_1]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_2: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_2] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_2] = 0; } - if (honey_key_callbacks[HONEY_KEY_2] != NULL) { - honey_key_callbacks[HONEY_KEY_2] (honey_key_callbacks_data[HONEY_KEY_2], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_2] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_2] = 0; } + callback = honey_key_callbacks[HONEY_KEY_2]; + data = honey_key_callbacks_data[HONEY_KEY_2]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_3: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_3] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_3] = 0; } - if (honey_key_callbacks[HONEY_KEY_3] != NULL) { - honey_key_callbacks[HONEY_KEY_3] (honey_key_callbacks_data[HONEY_KEY_3], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_3] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_3] = 0; } + callback = honey_key_callbacks[HONEY_KEY_3]; + data = honey_key_callbacks_data[HONEY_KEY_3]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_4: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_4] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_4] = 0; } - if (honey_key_callbacks[HONEY_KEY_4] != NULL) { - honey_key_callbacks[HONEY_KEY_4] (honey_key_callbacks_data[HONEY_KEY_4], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_4] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_4] = 0; } + callback = honey_key_callbacks[HONEY_KEY_4]; + data = honey_key_callbacks_data[HONEY_KEY_4]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_5: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_5] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_5] = 0; } - if (honey_key_callbacks[HONEY_KEY_5] != NULL) { - honey_key_callbacks[HONEY_KEY_5] (honey_key_callbacks_data[HONEY_KEY_5], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_5] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_5] = 0; } + callback = honey_key_callbacks[HONEY_KEY_5]; + data = honey_key_callbacks_data[HONEY_KEY_5]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_6: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_6] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_6] = 0; } - if (honey_key_callbacks[HONEY_KEY_6] != NULL) { - honey_key_callbacks[HONEY_KEY_6] (honey_key_callbacks_data[HONEY_KEY_6], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_6] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_6] = 0; } + callback = honey_key_callbacks[HONEY_KEY_6]; + data = honey_key_callbacks_data[HONEY_KEY_6]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_7: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_7] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_7] = 0; } - if (honey_key_callbacks[HONEY_KEY_7] != NULL) { - honey_key_callbacks[HONEY_KEY_7] (honey_key_callbacks_data[HONEY_KEY_7], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_7] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_7] = 0; } + callback = honey_key_callbacks[HONEY_KEY_7]; + data = honey_key_callbacks_data[HONEY_KEY_7]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_8: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_8] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_8] = 0; } - if (honey_key_callbacks[HONEY_KEY_8] != NULL) { - honey_key_callbacks[HONEY_KEY_8] (honey_key_callbacks_data[HONEY_KEY_8], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_8] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_8] = 0; } + callback = honey_key_callbacks[HONEY_KEY_8]; + data = honey_key_callbacks_data[HONEY_KEY_8]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_9: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_9] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_9] = 0; } - if (honey_key_callbacks[HONEY_KEY_9] != NULL) { - honey_key_callbacks[HONEY_KEY_9] (honey_key_callbacks_data[HONEY_KEY_9], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_9] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_9] = 0; } + callback = honey_key_callbacks[HONEY_KEY_9]; + data = honey_key_callbacks_data[HONEY_KEY_9]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_SEMICOLON: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SEMICOLON] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SEMICOLON] = 0; } - if (honey_key_callbacks[HONEY_KEY_SEMICOLON] != NULL) { - honey_key_callbacks[HONEY_KEY_SEMICOLON] (honey_key_callbacks_data[HONEY_KEY_SEMICOLON], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SEMICOLON] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SEMICOLON] = 0; } + callback = honey_key_callbacks[HONEY_KEY_SEMICOLON]; + data = honey_key_callbacks_data[HONEY_KEY_SEMICOLON]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_EQUAL: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_EQUAL] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_EQUAL] = 0; } - if (honey_key_callbacks[HONEY_KEY_EQUAL] != NULL) { - honey_key_callbacks[HONEY_KEY_EQUAL] (honey_key_callbacks_data[HONEY_KEY_EQUAL], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_EQUAL] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_EQUAL] = 0; } + callback = honey_key_callbacks[HONEY_KEY_EQUAL]; + data = honey_key_callbacks_data[HONEY_KEY_EQUAL]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_A: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_A] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_A] = 0; } - if (honey_key_callbacks[HONEY_KEY_A] != NULL) { - honey_key_callbacks[HONEY_KEY_A] (honey_key_callbacks_data[HONEY_KEY_A], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_A] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_A] = 0; } + callback = honey_key_callbacks[HONEY_KEY_A]; + data = honey_key_callbacks_data[HONEY_KEY_A]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_B: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_B] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_B] = 0; } - if (honey_key_callbacks[HONEY_KEY_B] != NULL) { - honey_key_callbacks[HONEY_KEY_B] (honey_key_callbacks_data[HONEY_KEY_B], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_B] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_B] = 0; } + callback = honey_key_callbacks[HONEY_KEY_B]; + data = honey_key_callbacks_data[HONEY_KEY_B]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_C: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_C] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_C] = 0; } - if (honey_key_callbacks[HONEY_KEY_C] != NULL) { - honey_key_callbacks[HONEY_KEY_C] (honey_key_callbacks_data[HONEY_KEY_C], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_C] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_C] = 0; } + callback = honey_key_callbacks[HONEY_KEY_C]; + data = honey_key_callbacks_data[HONEY_KEY_C]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_D: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_D] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_D] = 0; } - if (honey_key_callbacks[HONEY_KEY_D] != NULL) { - honey_key_callbacks[HONEY_KEY_D] (honey_key_callbacks_data[HONEY_KEY_D], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_D] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_D] = 0; } + callback = honey_key_callbacks[HONEY_KEY_D]; + data = honey_key_callbacks_data[HONEY_KEY_D]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_E: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_E] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_E] = 0; } - if (honey_key_callbacks[HONEY_KEY_E] != NULL) { - honey_key_callbacks[HONEY_KEY_E] (honey_key_callbacks_data[HONEY_KEY_E], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_E] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_E] = 0; } + callback = honey_key_callbacks[HONEY_KEY_E]; + data = honey_key_callbacks_data[HONEY_KEY_E]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F] = 0; } - if (honey_key_callbacks[HONEY_KEY_F] != NULL) { - honey_key_callbacks[HONEY_KEY_F] (honey_key_callbacks_data[HONEY_KEY_F], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F]; + data = honey_key_callbacks_data[HONEY_KEY_F]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_G: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_G] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_G] = 0; } - if (honey_key_callbacks[HONEY_KEY_G] != NULL) { - honey_key_callbacks[HONEY_KEY_G] (honey_key_callbacks_data[HONEY_KEY_G], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_G] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_G] = 0; } + callback = honey_key_callbacks[HONEY_KEY_G]; + data = honey_key_callbacks_data[HONEY_KEY_G]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_H: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_H] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_H] = 0; } - if (honey_key_callbacks[HONEY_KEY_H] != NULL) { - honey_key_callbacks[HONEY_KEY_H] (honey_key_callbacks_data[HONEY_KEY_H], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_H] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_H] = 0; } + callback = honey_key_callbacks[HONEY_KEY_H]; + data = honey_key_callbacks_data[HONEY_KEY_H]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_I: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_I] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_I] = 0; } - if (honey_key_callbacks[HONEY_KEY_I] != NULL) { - honey_key_callbacks[HONEY_KEY_I] (honey_key_callbacks_data[HONEY_KEY_I], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_I] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_I] = 0; } + callback = honey_key_callbacks[HONEY_KEY_I]; + data = honey_key_callbacks_data[HONEY_KEY_I]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_J: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_J] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_J] = 0; } - if (honey_key_callbacks[HONEY_KEY_J] != NULL) { - honey_key_callbacks[HONEY_KEY_J] (honey_key_callbacks_data[HONEY_KEY_J], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_J] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_J] = 0; } + callback = honey_key_callbacks[HONEY_KEY_J]; + data = honey_key_callbacks_data[HONEY_KEY_J]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_K: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_K] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_K] = 0; } - if (honey_key_callbacks[HONEY_KEY_K] != NULL) { - honey_key_callbacks[HONEY_KEY_K] (honey_key_callbacks_data[HONEY_KEY_K], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_K] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_K] = 0; } + callback = honey_key_callbacks[HONEY_KEY_K]; + data = honey_key_callbacks_data[HONEY_KEY_K]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_L: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_L] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_L] = 0; } - if (honey_key_callbacks[HONEY_KEY_L] != NULL) { - honey_key_callbacks[HONEY_KEY_L] (honey_key_callbacks_data[HONEY_KEY_L], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_L] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_L] = 0; } + callback = honey_key_callbacks[HONEY_KEY_L]; + data = honey_key_callbacks_data[HONEY_KEY_L]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_M: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_M] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_M] = 0; } - if (honey_key_callbacks[HONEY_KEY_M] != NULL) { - honey_key_callbacks[HONEY_KEY_M] (honey_key_callbacks_data[HONEY_KEY_M], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_M] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_M] = 0; } + callback = honey_key_callbacks[HONEY_KEY_M]; + data = honey_key_callbacks_data[HONEY_KEY_M]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_N: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_N] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_N] = 0; } - if (honey_key_callbacks[HONEY_KEY_N] != NULL) { - honey_key_callbacks[HONEY_KEY_N] (honey_key_callbacks_data[HONEY_KEY_N], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_N] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_N] = 0; } + callback = honey_key_callbacks[HONEY_KEY_N]; + data = honey_key_callbacks_data[HONEY_KEY_N]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_O: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_O] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_O] = 0; } - if (honey_key_callbacks[HONEY_KEY_O] != NULL) { - honey_key_callbacks[HONEY_KEY_O] (honey_key_callbacks_data[HONEY_KEY_O], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_O] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_O] = 0; } + callback = honey_key_callbacks[HONEY_KEY_O]; + data = honey_key_callbacks_data[HONEY_KEY_O]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_P: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_P] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_P] = 0; } - if (honey_key_callbacks[HONEY_KEY_P] != NULL) { - honey_key_callbacks[HONEY_KEY_P] (honey_key_callbacks_data[HONEY_KEY_P], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_P] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_P] = 0; } + callback = honey_key_callbacks[HONEY_KEY_P]; + data = honey_key_callbacks_data[HONEY_KEY_P]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_Q: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_Q] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_Q] = 0; } - if (honey_key_callbacks[HONEY_KEY_Q] != NULL) { - honey_key_callbacks[HONEY_KEY_Q] (honey_key_callbacks_data[HONEY_KEY_Q], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_Q] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_Q] = 0; } + callback = honey_key_callbacks[HONEY_KEY_Q]; + data = honey_key_callbacks_data[HONEY_KEY_Q]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_R: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_R] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_R] = 0; } - if (honey_key_callbacks[HONEY_KEY_R] != NULL) { - honey_key_callbacks[HONEY_KEY_R] (honey_key_callbacks_data[HONEY_KEY_R], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_R] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_R] = 0; } + callback = honey_key_callbacks[HONEY_KEY_R]; + data = honey_key_callbacks_data[HONEY_KEY_R]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_S: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_S] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_S] = 0; } - if (honey_key_callbacks[HONEY_KEY_S] != NULL) { - honey_key_callbacks[HONEY_KEY_S] (honey_key_callbacks_data[HONEY_KEY_S], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_S] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_S] = 0; } + callback = honey_key_callbacks[HONEY_KEY_S]; + data = honey_key_callbacks_data[HONEY_KEY_S]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_T: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_T] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_T] = 0; } - if (honey_key_callbacks[HONEY_KEY_T] != NULL) { - honey_key_callbacks[HONEY_KEY_T] (honey_key_callbacks_data[HONEY_KEY_T], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_T] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_T] = 0; } + callback = honey_key_callbacks[HONEY_KEY_T]; + data = honey_key_callbacks_data[HONEY_KEY_T]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_U: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_U] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_U] = 0; } - if (honey_key_callbacks[HONEY_KEY_U] != NULL) { - honey_key_callbacks[HONEY_KEY_U] (honey_key_callbacks_data[HONEY_KEY_U], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_U] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_U] = 0; } + callback = honey_key_callbacks[HONEY_KEY_U]; + data = honey_key_callbacks_data[HONEY_KEY_U]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_V: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_V] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_V] = 0; } - if (honey_key_callbacks[HONEY_KEY_V] != NULL) { - honey_key_callbacks[HONEY_KEY_V] (honey_key_callbacks_data[HONEY_KEY_V], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_V] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_V] = 0; } + callback = honey_key_callbacks[HONEY_KEY_V]; + data = honey_key_callbacks_data[HONEY_KEY_V]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_W: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_W] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_W] = 0; } - if (honey_key_callbacks[HONEY_KEY_W] != NULL) { - honey_key_callbacks[HONEY_KEY_W] (honey_key_callbacks_data[HONEY_KEY_W], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_W] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_W] = 0; } + callback = honey_key_callbacks[HONEY_KEY_W]; + data = honey_key_callbacks_data[HONEY_KEY_W]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_X: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_X] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_X] = 0; } - if (honey_key_callbacks[HONEY_KEY_X] != NULL) { - honey_key_callbacks[HONEY_KEY_X] (honey_key_callbacks_data[HONEY_KEY_X], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_X] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_X] = 0; } + callback = honey_key_callbacks[HONEY_KEY_X]; + data = honey_key_callbacks_data[HONEY_KEY_X]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_Y: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_Y] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_Y] = 0; } - if (honey_key_callbacks[HONEY_KEY_Y] != NULL) { - honey_key_callbacks[HONEY_KEY_Y] (honey_key_callbacks_data[HONEY_KEY_Y], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_Y] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_Y] = 0; } + callback = honey_key_callbacks[HONEY_KEY_Y]; + data = honey_key_callbacks_data[HONEY_KEY_Y]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_Z: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_Z] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_Z] = 0; } - if (honey_key_callbacks[HONEY_KEY_Z] != NULL) { - honey_key_callbacks[HONEY_KEY_Z] (honey_key_callbacks_data[HONEY_KEY_Z], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_Z] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_Z] = 0; } + callback = honey_key_callbacks[HONEY_KEY_Z]; + data = honey_key_callbacks_data[HONEY_KEY_Z]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_LEFT_BRACKET: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_BRACKET] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_BRACKET] = 0; } - if (honey_key_callbacks[HONEY_KEY_LEFT_BRACKET] != NULL) { - honey_key_callbacks[HONEY_KEY_LEFT_BRACKET] (honey_key_callbacks_data[HONEY_KEY_LEFT_BRACKET], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_BRACKET] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_BRACKET] = 0; } + callback = honey_key_callbacks[HONEY_KEY_LEFT_BRACKET]; + data = honey_key_callbacks_data[HONEY_KEY_LEFT_BRACKET]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_BACKSLASH: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_BACKSLASH] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_BACKSLASH] = 0; } - if (honey_key_callbacks[HONEY_KEY_BACKSLASH] != NULL) { - honey_key_callbacks[HONEY_KEY_BACKSLASH] (honey_key_callbacks_data[HONEY_KEY_BACKSLASH], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_BACKSLASH] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_BACKSLASH] = 0; } + callback = honey_key_callbacks[HONEY_KEY_BACKSLASH]; + data = honey_key_callbacks_data[HONEY_KEY_BACKSLASH]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_RIGHT_BRACKET: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_BRACKET] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_BRACKET] = 0; } - if (honey_key_callbacks[HONEY_KEY_RIGHT_BRACKET] != NULL) { - honey_key_callbacks[HONEY_KEY_RIGHT_BRACKET] (honey_key_callbacks_data[HONEY_KEY_RIGHT_BRACKET], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_BRACKET] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_BRACKET] = 0; } + callback = honey_key_callbacks[HONEY_KEY_RIGHT_BRACKET]; + data = honey_key_callbacks_data[HONEY_KEY_RIGHT_BRACKET]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_GRAVE_ACCENT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_GRAVE_ACCENT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_GRAVE_ACCENT] = 0; } - if (honey_key_callbacks[HONEY_KEY_GRAVE_ACCENT] != NULL) { - honey_key_callbacks[HONEY_KEY_GRAVE_ACCENT] (honey_key_callbacks_data[HONEY_KEY_GRAVE_ACCENT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_GRAVE_ACCENT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_GRAVE_ACCENT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_GRAVE_ACCENT]; + data = honey_key_callbacks_data[HONEY_KEY_GRAVE_ACCENT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_WORLD_1: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_WORLD_1] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_WORLD_1] = 0; } - if (honey_key_callbacks[HONEY_KEY_WORLD_1] != NULL) { - honey_key_callbacks[HONEY_KEY_WORLD_1] (honey_key_callbacks_data[HONEY_KEY_WORLD_1], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_WORLD_1] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_WORLD_1] = 0; } + callback = honey_key_callbacks[HONEY_KEY_WORLD_1]; + data = honey_key_callbacks_data[HONEY_KEY_WORLD_1]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_WORLD_2: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_WORLD_2] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_WORLD_2] = 0; } - if (honey_key_callbacks[HONEY_KEY_WORLD_2] != NULL) { - honey_key_callbacks[HONEY_KEY_WORLD_2] (honey_key_callbacks_data[HONEY_KEY_WORLD_2], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_WORLD_2] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_WORLD_2] = 0; } + callback = honey_key_callbacks[HONEY_KEY_WORLD_2]; + data = honey_key_callbacks_data[HONEY_KEY_WORLD_2]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_ESCAPE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_ESCAPE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_ESCAPE] = 0; } - if (honey_key_callbacks[HONEY_KEY_ESCAPE] != NULL) { - honey_key_callbacks[HONEY_KEY_ESCAPE] (honey_key_callbacks_data[HONEY_KEY_ESCAPE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_ESCAPE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_ESCAPE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_ESCAPE]; + data = honey_key_callbacks_data[HONEY_KEY_ESCAPE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_ENTER: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_ENTER] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_ENTER] = 0; } - if (honey_key_callbacks[HONEY_KEY_ENTER] != NULL) { - honey_key_callbacks[HONEY_KEY_ENTER] (honey_key_callbacks_data[HONEY_KEY_ENTER], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_ENTER] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_ENTER] = 0; } + callback = honey_key_callbacks[HONEY_KEY_ENTER]; + data = honey_key_callbacks_data[HONEY_KEY_ENTER]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_TAB: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_TAB] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_TAB] = 0; } - if (honey_key_callbacks[HONEY_KEY_TAB] != NULL) { - honey_key_callbacks[HONEY_KEY_TAB] (honey_key_callbacks_data[HONEY_KEY_TAB], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_TAB] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_TAB] = 0; } + callback = honey_key_callbacks[HONEY_KEY_TAB]; + data = honey_key_callbacks_data[HONEY_KEY_TAB]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_BACKSPACE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_BACKSPACE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_BACKSPACE] = 0; } - if (honey_key_callbacks[HONEY_KEY_BACKSPACE] != NULL) { - honey_key_callbacks[HONEY_KEY_BACKSPACE] (honey_key_callbacks_data[HONEY_KEY_BACKSPACE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_BACKSPACE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_BACKSPACE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_BACKSPACE]; + data = honey_key_callbacks_data[HONEY_KEY_BACKSPACE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_INSERT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_INSERT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_INSERT] = 0; } - if (honey_key_callbacks[HONEY_KEY_INSERT] != NULL) { - honey_key_callbacks[HONEY_KEY_INSERT] (honey_key_callbacks_data[HONEY_KEY_INSERT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_INSERT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_INSERT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_INSERT]; + data = honey_key_callbacks_data[HONEY_KEY_INSERT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_DELETE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_DELETE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_DELETE] = 0; } - if (honey_key_callbacks[HONEY_KEY_DELETE] != NULL) { - honey_key_callbacks[HONEY_KEY_DELETE] (honey_key_callbacks_data[HONEY_KEY_DELETE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_DELETE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_DELETE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_DELETE]; + data = honey_key_callbacks_data[HONEY_KEY_DELETE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_RIGHT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT] = 0; } - if (honey_key_callbacks[HONEY_KEY_RIGHT] != NULL) { - honey_key_callbacks[HONEY_KEY_RIGHT] (honey_key_callbacks_data[HONEY_KEY_RIGHT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_RIGHT]; + data = honey_key_callbacks_data[HONEY_KEY_RIGHT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_LEFT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT] = 0; } - if (honey_key_callbacks[HONEY_KEY_LEFT] != NULL) { - honey_key_callbacks[HONEY_KEY_LEFT] (honey_key_callbacks_data[HONEY_KEY_LEFT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_LEFT]; + data = honey_key_callbacks_data[HONEY_KEY_LEFT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_DOWN: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_DOWN] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_DOWN] = 0; } - if (honey_key_callbacks[HONEY_KEY_DOWN] != NULL) { - honey_key_callbacks[HONEY_KEY_DOWN] (honey_key_callbacks_data[HONEY_KEY_DOWN], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_DOWN] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_DOWN] = 0; } + callback = honey_key_callbacks[HONEY_KEY_DOWN]; + data = honey_key_callbacks_data[HONEY_KEY_DOWN]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_UP: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_UP] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_UP] = 0; } - if (honey_key_callbacks[HONEY_KEY_UP] != NULL) { - honey_key_callbacks[HONEY_KEY_UP] (honey_key_callbacks_data[HONEY_KEY_UP], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_UP] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_UP] = 0; } + callback = honey_key_callbacks[HONEY_KEY_UP]; + data = honey_key_callbacks_data[HONEY_KEY_UP]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_PAGE_UP: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PAGE_UP] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PAGE_UP] = 0; } - if (honey_key_callbacks[HONEY_KEY_PAGE_UP] != NULL) { - honey_key_callbacks[HONEY_KEY_PAGE_UP] (honey_key_callbacks_data[HONEY_KEY_PAGE_UP], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PAGE_UP] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PAGE_UP] = 0; } + callback = honey_key_callbacks[HONEY_KEY_PAGE_UP]; + data = honey_key_callbacks_data[HONEY_KEY_PAGE_UP]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_PAGE_DOWN: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PAGE_DOWN] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PAGE_DOWN] = 0; } - if (honey_key_callbacks[HONEY_KEY_PAGE_DOWN] != NULL) { - honey_key_callbacks[HONEY_KEY_PAGE_DOWN] (honey_key_callbacks_data[HONEY_KEY_PAGE_DOWN], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PAGE_DOWN] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PAGE_DOWN] = 0; } + callback = honey_key_callbacks[HONEY_KEY_PAGE_DOWN]; + data = honey_key_callbacks_data[HONEY_KEY_PAGE_DOWN]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_HOME: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_HOME] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_HOME] = 0; } - if (honey_key_callbacks[HONEY_KEY_HOME] != NULL) { - honey_key_callbacks[HONEY_KEY_HOME] (honey_key_callbacks_data[HONEY_KEY_HOME], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_HOME] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_HOME] = 0; } + callback = honey_key_callbacks[HONEY_KEY_HOME]; + data = honey_key_callbacks_data[HONEY_KEY_HOME]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_END: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_END] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_END] = 0; } - if (honey_key_callbacks[HONEY_KEY_END] != NULL) { - honey_key_callbacks[HONEY_KEY_END] (honey_key_callbacks_data[HONEY_KEY_END], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_END] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_END] = 0; } + callback = honey_key_callbacks[HONEY_KEY_END]; + data = honey_key_callbacks_data[HONEY_KEY_END]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_CAPS_LOCK: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_CAPS_LOCK] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_CAPS_LOCK] = 0; } - if (honey_key_callbacks[HONEY_KEY_CAPS_LOCK] != NULL) { - honey_key_callbacks[HONEY_KEY_CAPS_LOCK] (honey_key_callbacks_data[HONEY_KEY_CAPS_LOCK], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_CAPS_LOCK] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_CAPS_LOCK] = 0; } + callback = honey_key_callbacks[HONEY_KEY_CAPS_LOCK]; + data = honey_key_callbacks_data[HONEY_KEY_CAPS_LOCK]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_SCROLL_LOCK: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SCROLL_LOCK] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SCROLL_LOCK] = 0; } - if (honey_key_callbacks[HONEY_KEY_SCROLL_LOCK] != NULL) { - honey_key_callbacks[HONEY_KEY_SCROLL_LOCK] (honey_key_callbacks_data[HONEY_KEY_SCROLL_LOCK], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_SCROLL_LOCK] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_SCROLL_LOCK] = 0; } + callback = honey_key_callbacks[HONEY_KEY_SCROLL_LOCK]; + data = honey_key_callbacks_data[HONEY_KEY_SCROLL_LOCK]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_NUM_LOCK: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_NUM_LOCK] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_NUM_LOCK] = 0; } - if (honey_key_callbacks[HONEY_KEY_NUM_LOCK] != NULL) { - honey_key_callbacks[HONEY_KEY_NUM_LOCK] (honey_key_callbacks_data[HONEY_KEY_NUM_LOCK], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_NUM_LOCK] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_NUM_LOCK] = 0; } + callback = honey_key_callbacks[HONEY_KEY_NUM_LOCK]; + data = honey_key_callbacks_data[HONEY_KEY_NUM_LOCK]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_PRINT_SCREEN: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PRINT_SCREEN] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PRINT_SCREEN] = 0; } - if (honey_key_callbacks[HONEY_KEY_PRINT_SCREEN] != NULL) { - honey_key_callbacks[HONEY_KEY_PRINT_SCREEN] (honey_key_callbacks_data[HONEY_KEY_PRINT_SCREEN], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PRINT_SCREEN] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PRINT_SCREEN] = 0; } + callback = honey_key_callbacks[HONEY_KEY_PRINT_SCREEN]; + data = honey_key_callbacks_data[HONEY_KEY_PRINT_SCREEN]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_PAUSE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PAUSE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PAUSE] = 0; } - if (honey_key_callbacks[HONEY_KEY_PAUSE] != NULL) { - honey_key_callbacks[HONEY_KEY_PAUSE] (honey_key_callbacks_data[HONEY_KEY_PAUSE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_PAUSE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_PAUSE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_PAUSE]; + data = honey_key_callbacks_data[HONEY_KEY_PAUSE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F1: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F1] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F1] = 0; } - if (honey_key_callbacks[HONEY_KEY_F1] != NULL) { - honey_key_callbacks[HONEY_KEY_F1] (honey_key_callbacks_data[HONEY_KEY_F1], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F1] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F1] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F1]; + data = honey_key_callbacks_data[HONEY_KEY_F1]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F2: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F2] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F2] = 0; } - if (honey_key_callbacks[HONEY_KEY_F2] != NULL) { - honey_key_callbacks[HONEY_KEY_F2] (honey_key_callbacks_data[HONEY_KEY_F2], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F2] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F2] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F2]; + data = honey_key_callbacks_data[HONEY_KEY_F2]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F3: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F3] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F3] = 0; } - if (honey_key_callbacks[HONEY_KEY_F3] != NULL) { - honey_key_callbacks[HONEY_KEY_F3] (honey_key_callbacks_data[HONEY_KEY_F3], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F3] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F3] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F3]; + data = honey_key_callbacks_data[HONEY_KEY_F3]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F4: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F4] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F4] = 0; } - if (honey_key_callbacks[HONEY_KEY_F4] != NULL) { - honey_key_callbacks[HONEY_KEY_F4] (honey_key_callbacks_data[HONEY_KEY_F4], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F4] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F4] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F4]; + data = honey_key_callbacks_data[HONEY_KEY_F4]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F5: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F5] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F5] = 0; } - if (honey_key_callbacks[HONEY_KEY_F5] != NULL) { - honey_key_callbacks[HONEY_KEY_F5] (honey_key_callbacks_data[HONEY_KEY_F5], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F5] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F5] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F5]; + data = honey_key_callbacks_data[HONEY_KEY_F5]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F6: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F6] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F6] = 0; } - if (honey_key_callbacks[HONEY_KEY_F6] != NULL) { - honey_key_callbacks[HONEY_KEY_F6] (honey_key_callbacks_data[HONEY_KEY_F6], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F6] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F6] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F6]; + data = honey_key_callbacks_data[HONEY_KEY_F6]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F7: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F7] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F7] = 0; } - if (honey_key_callbacks[HONEY_KEY_F7] != NULL) { - honey_key_callbacks[HONEY_KEY_F7] (honey_key_callbacks_data[HONEY_KEY_F7], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F7] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F7] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F7]; + data = honey_key_callbacks_data[HONEY_KEY_F7]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F8: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F8] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F8] = 0; } - if (honey_key_callbacks[HONEY_KEY_F8] != NULL) { - honey_key_callbacks[HONEY_KEY_F8] (honey_key_callbacks_data[HONEY_KEY_F8], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F8] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F8] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F8]; + data = honey_key_callbacks_data[HONEY_KEY_F8]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F9: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F9] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F9] = 0; } - if (honey_key_callbacks[HONEY_KEY_F9] != NULL) { - honey_key_callbacks[HONEY_KEY_F9] (honey_key_callbacks_data[HONEY_KEY_F9], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F9] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F9] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F9]; + data = honey_key_callbacks_data[HONEY_KEY_F9]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F10: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F10] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F10] = 0; } - if (honey_key_callbacks[HONEY_KEY_F10] != NULL) { - honey_key_callbacks[HONEY_KEY_F10] (honey_key_callbacks_data[HONEY_KEY_F10], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F10] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F10] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F10]; + data = honey_key_callbacks_data[HONEY_KEY_F10]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F11: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F11] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F11] = 0; } - if (honey_key_callbacks[HONEY_KEY_F11] != NULL) { - honey_key_callbacks[HONEY_KEY_F11] (honey_key_callbacks_data[HONEY_KEY_F11], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F11] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F11] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F11]; + data = honey_key_callbacks_data[HONEY_KEY_F11]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F12: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F12] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F12] = 0; } - if (honey_key_callbacks[HONEY_KEY_F12] != NULL) { - honey_key_callbacks[HONEY_KEY_F12] (honey_key_callbacks_data[HONEY_KEY_F12], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F12] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F12] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F12]; + data = honey_key_callbacks_data[HONEY_KEY_F12]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F13: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F13] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F13] = 0; } - if (honey_key_callbacks[HONEY_KEY_F13] != NULL) { - honey_key_callbacks[HONEY_KEY_F13] (honey_key_callbacks_data[HONEY_KEY_F13], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F13] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F13] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F13]; + data = honey_key_callbacks_data[HONEY_KEY_F13]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F14: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F14] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F14] = 0; } - if (honey_key_callbacks[HONEY_KEY_F14] != NULL) { - honey_key_callbacks[HONEY_KEY_F14] (honey_key_callbacks_data[HONEY_KEY_F14], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F14] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F14] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F14]; + data = honey_key_callbacks_data[HONEY_KEY_F14]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F15: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F15] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F15] = 0; } - if (honey_key_callbacks[HONEY_KEY_F15] != NULL) { - honey_key_callbacks[HONEY_KEY_F15] (honey_key_callbacks_data[HONEY_KEY_F15], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F15] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F15] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F15]; + data = honey_key_callbacks_data[HONEY_KEY_F15]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F16: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F16] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F16] = 0; } - if (honey_key_callbacks[HONEY_KEY_F16] != NULL) { - honey_key_callbacks[HONEY_KEY_F16] (honey_key_callbacks_data[HONEY_KEY_F16], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F16] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F16] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F16]; + data = honey_key_callbacks_data[HONEY_KEY_F16]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F17: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F17] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F17] = 0; } - if (honey_key_callbacks[HONEY_KEY_F17] != NULL) { - honey_key_callbacks[HONEY_KEY_F17] (honey_key_callbacks_data[HONEY_KEY_F17], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F17] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F17] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F17]; + data = honey_key_callbacks_data[HONEY_KEY_F17]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F18: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F18] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F18] = 0; } - if (honey_key_callbacks[HONEY_KEY_F18] != NULL) { - honey_key_callbacks[HONEY_KEY_F18] (honey_key_callbacks_data[HONEY_KEY_F18], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F18] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F18] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F18]; + data = honey_key_callbacks_data[HONEY_KEY_F18]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F19: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F19] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F19] = 0; } - if (honey_key_callbacks[HONEY_KEY_F19] != NULL) { - honey_key_callbacks[HONEY_KEY_F19] (honey_key_callbacks_data[HONEY_KEY_F19], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F19] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F19] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F19]; + data = honey_key_callbacks_data[HONEY_KEY_F19]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F20: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F20] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F20] = 0; } - if (honey_key_callbacks[HONEY_KEY_F20] != NULL) { - honey_key_callbacks[HONEY_KEY_F20] (honey_key_callbacks_data[HONEY_KEY_F20], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F20] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F20] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F20]; + data = honey_key_callbacks_data[HONEY_KEY_F20]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F21: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F21] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F21] = 0; } - if (honey_key_callbacks[HONEY_KEY_F21] != NULL) { - honey_key_callbacks[HONEY_KEY_F21] (honey_key_callbacks_data[HONEY_KEY_F21], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F21] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F21] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F21]; + data = honey_key_callbacks_data[HONEY_KEY_F21]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F22: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F22] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F22] = 0; } - if (honey_key_callbacks[HONEY_KEY_F22] != NULL) { - honey_key_callbacks[HONEY_KEY_F22] (honey_key_callbacks_data[HONEY_KEY_F22], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F22] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F22] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F22]; + data = honey_key_callbacks_data[HONEY_KEY_F22]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F23: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F23] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F23] = 0; } - if (honey_key_callbacks[HONEY_KEY_F23] != NULL) { - honey_key_callbacks[HONEY_KEY_F23] (honey_key_callbacks_data[HONEY_KEY_F23], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F23] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F23] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F23]; + data = honey_key_callbacks_data[HONEY_KEY_F23]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F24: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F24] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F24] = 0; } - if (honey_key_callbacks[HONEY_KEY_F24] != NULL) { - honey_key_callbacks[HONEY_KEY_F24] (honey_key_callbacks_data[HONEY_KEY_F24], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F24] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F24] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F24]; + data = honey_key_callbacks_data[HONEY_KEY_F24]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_F25: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F25] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F25] = 0; } - if (honey_key_callbacks[HONEY_KEY_F25] != NULL) { - honey_key_callbacks[HONEY_KEY_F25] (honey_key_callbacks_data[HONEY_KEY_F25], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_F25] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_F25] = 0; } + callback = honey_key_callbacks[HONEY_KEY_F25]; + data = honey_key_callbacks_data[HONEY_KEY_F25]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_0: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_0] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_0] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_0] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_0] (honey_key_callbacks_data[HONEY_KEY_KP_0], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_0] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_0] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_0]; + data = honey_key_callbacks_data[HONEY_KEY_KP_0]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_1: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_1] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_1] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_1] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_1] (honey_key_callbacks_data[HONEY_KEY_KP_1], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_1] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_1] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_1]; + data = honey_key_callbacks_data[HONEY_KEY_KP_1]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_2: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_2] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_2] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_2] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_2] (honey_key_callbacks_data[HONEY_KEY_KP_2], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_2] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_2] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_2]; + data = honey_key_callbacks_data[HONEY_KEY_KP_2]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_3: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_3] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_3] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_3] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_3] (honey_key_callbacks_data[HONEY_KEY_KP_3], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_3] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_3] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_3]; + data = honey_key_callbacks_data[HONEY_KEY_KP_3]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_4: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_4] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_4] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_4] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_4] (honey_key_callbacks_data[HONEY_KEY_KP_4], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_4] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_4] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_4]; + data = honey_key_callbacks_data[HONEY_KEY_KP_4]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_5: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_5] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_5] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_5] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_5] (honey_key_callbacks_data[HONEY_KEY_KP_5], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_5] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_5] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_5]; + data = honey_key_callbacks_data[HONEY_KEY_KP_5]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_6: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_6] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_6] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_6] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_6] (honey_key_callbacks_data[HONEY_KEY_KP_6], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_6] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_6] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_6]; + data = honey_key_callbacks_data[HONEY_KEY_KP_6]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_7: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_7] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_7] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_7] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_7] (honey_key_callbacks_data[HONEY_KEY_KP_7], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_7] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_7] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_7]; + data = honey_key_callbacks_data[HONEY_KEY_KP_7]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_8: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_8] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_8] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_8] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_8] (honey_key_callbacks_data[HONEY_KEY_KP_8], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_8] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_8] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_8]; + data = honey_key_callbacks_data[HONEY_KEY_KP_8]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_9: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_9] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_9] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_9] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_9] (honey_key_callbacks_data[HONEY_KEY_KP_9], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_9] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_9] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_9]; + data = honey_key_callbacks_data[HONEY_KEY_KP_9]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_DECIMAL: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_DECIMAL] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_DECIMAL] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_DECIMAL] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_DECIMAL] (honey_key_callbacks_data[HONEY_KEY_KP_DECIMAL], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_DECIMAL] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_DECIMAL] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_DECIMAL]; + data = honey_key_callbacks_data[HONEY_KEY_KP_DECIMAL]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_DIVIDE: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_DIVIDE] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_DIVIDE] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_DIVIDE] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_DIVIDE] (honey_key_callbacks_data[HONEY_KEY_KP_DIVIDE], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_DIVIDE] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_DIVIDE] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_DIVIDE]; + data = honey_key_callbacks_data[HONEY_KEY_KP_DIVIDE]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_MULTIPLY: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_MULTIPLY] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_MULTIPLY] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_MULTIPLY] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_MULTIPLY] (honey_key_callbacks_data[HONEY_KEY_KP_MULTIPLY], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_MULTIPLY] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_MULTIPLY] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_MULTIPLY]; + data = honey_key_callbacks_data[HONEY_KEY_KP_MULTIPLY]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_SUBTRACT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_SUBTRACT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_SUBTRACT] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_SUBTRACT] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_SUBTRACT] (honey_key_callbacks_data[HONEY_KEY_KP_SUBTRACT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_SUBTRACT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_SUBTRACT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_SUBTRACT]; + data = honey_key_callbacks_data[HONEY_KEY_KP_SUBTRACT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_ADD: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_ADD] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_ADD] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_ADD] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_ADD] (honey_key_callbacks_data[HONEY_KEY_KP_ADD], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_ADD] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_ADD] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_ADD]; + data = honey_key_callbacks_data[HONEY_KEY_KP_ADD]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_ENTER: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_ENTER] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_ENTER] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_ENTER] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_ENTER] (honey_key_callbacks_data[HONEY_KEY_KP_ENTER], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_ENTER] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_ENTER] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_ENTER]; + data = honey_key_callbacks_data[HONEY_KEY_KP_ENTER]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_KP_EQUAL: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_EQUAL] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_EQUAL] = 0; } - if (honey_key_callbacks[HONEY_KEY_KP_EQUAL] != NULL) { - honey_key_callbacks[HONEY_KEY_KP_EQUAL] (honey_key_callbacks_data[HONEY_KEY_KP_EQUAL], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_KP_EQUAL] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_KP_EQUAL] = 0; } + callback = honey_key_callbacks[HONEY_KEY_KP_EQUAL]; + data = honey_key_callbacks_data[HONEY_KEY_KP_EQUAL]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_LEFT_SHIFT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_SHIFT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_SHIFT] = 0; } - if (honey_key_callbacks[HONEY_KEY_LEFT_SHIFT] != NULL) { - honey_key_callbacks[HONEY_KEY_LEFT_SHIFT] (honey_key_callbacks_data[HONEY_KEY_LEFT_SHIFT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_SHIFT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_SHIFT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_LEFT_SHIFT]; + data = honey_key_callbacks_data[HONEY_KEY_LEFT_SHIFT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_LEFT_CONTROL: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_CONTROL] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_CONTROL] = 0; } - if (honey_key_callbacks[HONEY_KEY_LEFT_CONTROL] != NULL) { - honey_key_callbacks[HONEY_KEY_LEFT_CONTROL] (honey_key_callbacks_data[HONEY_KEY_LEFT_CONTROL], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_CONTROL] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_CONTROL] = 0; } + callback = honey_key_callbacks[HONEY_KEY_LEFT_CONTROL]; + data = honey_key_callbacks_data[HONEY_KEY_LEFT_CONTROL]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_LEFT_ALT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_ALT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_ALT] = 0; } - if (honey_key_callbacks[HONEY_KEY_LEFT_ALT] != NULL) { - honey_key_callbacks[HONEY_KEY_LEFT_ALT] (honey_key_callbacks_data[HONEY_KEY_LEFT_ALT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_ALT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_ALT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_LEFT_ALT]; + data = honey_key_callbacks_data[HONEY_KEY_LEFT_ALT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_LEFT_SUPER: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_SUPER] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_SUPER] = 0; } - if (honey_key_callbacks[HONEY_KEY_LEFT_SUPER] != NULL) { - honey_key_callbacks[HONEY_KEY_LEFT_SUPER] (honey_key_callbacks_data[HONEY_KEY_LEFT_SUPER], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_LEFT_SUPER] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_LEFT_SUPER] = 0; } + callback = honey_key_callbacks[HONEY_KEY_LEFT_SUPER]; + data = honey_key_callbacks_data[HONEY_KEY_LEFT_SUPER]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_RIGHT_SHIFT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_SHIFT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_SHIFT] = 0; } - if (honey_key_callbacks[HONEY_KEY_RIGHT_SHIFT] != NULL) { - honey_key_callbacks[HONEY_KEY_RIGHT_SHIFT] (honey_key_callbacks_data[HONEY_KEY_RIGHT_SHIFT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_SHIFT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_SHIFT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_RIGHT_SHIFT]; + data = honey_key_callbacks_data[HONEY_KEY_RIGHT_SHIFT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_RIGHT_CONTROL: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_CONTROL] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_CONTROL] = 0; } - if (honey_key_callbacks[HONEY_KEY_RIGHT_CONTROL] != NULL) { - honey_key_callbacks[HONEY_KEY_RIGHT_CONTROL] (honey_key_callbacks_data[HONEY_KEY_RIGHT_CONTROL], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_CONTROL] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_CONTROL] = 0; } + callback = honey_key_callbacks[HONEY_KEY_RIGHT_CONTROL]; + data = honey_key_callbacks_data[HONEY_KEY_RIGHT_CONTROL]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_RIGHT_ALT: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_ALT] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_ALT] = 0; } - if (honey_key_callbacks[HONEY_KEY_RIGHT_ALT] != NULL) { - honey_key_callbacks[HONEY_KEY_RIGHT_ALT] (honey_key_callbacks_data[HONEY_KEY_RIGHT_ALT], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_ALT] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_ALT] = 0; } + callback = honey_key_callbacks[HONEY_KEY_RIGHT_ALT]; + data = honey_key_callbacks_data[HONEY_KEY_RIGHT_ALT]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_RIGHT_SUPER: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_SUPER] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_SUPER] = 0; } - if (honey_key_callbacks[HONEY_KEY_RIGHT_SUPER] != NULL) { - honey_key_callbacks[HONEY_KEY_RIGHT_SUPER] (honey_key_callbacks_data[HONEY_KEY_RIGHT_SUPER], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_RIGHT_SUPER] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_RIGHT_SUPER] = 0; } + callback = honey_key_callbacks[HONEY_KEY_RIGHT_SUPER]; + data = honey_key_callbacks_data[HONEY_KEY_RIGHT_SUPER]; + execute_lua_key_callback(L, callback, action, data); + break; + case GLFW_KEY_MENU: - if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_MENU] = 1; } - if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_MENU] = 0; } - if (honey_key_callbacks[HONEY_KEY_MENU] != NULL) { - honey_key_callbacks[HONEY_KEY_MENU] (honey_key_callbacks_data[HONEY_KEY_MENU], - action); - } - break; + if (action == HONEY_KEY_PRESS) { honey_key_states[HONEY_KEY_MENU] = 1; } + if (action == HONEY_KEY_RELEASE) { honey_key_states[HONEY_KEY_MENU] = 0; } + callback = honey_key_callbacks[HONEY_KEY_MENU]; + data = honey_key_callbacks_data[HONEY_KEY_MENU]; + execute_lua_key_callback(L, callback, action, data); + break; + default: - /* do nothing */ - break; + /* do nothing */ + break; } } diff --git a/src/input/input.h b/src/input/input.h index 31be34a..2127417 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -136,9 +136,8 @@ #define HONEY_KEY_RELEASE GLFW_RELEASE unsigned int honey_key_states[HONEY_N_KEYS]; -static void (*honey_key_callbacks[HONEY_N_KEYS])(void*, int); -static void* honey_key_callbacks_data[HONEY_N_KEYS]; -static void (*honey_keyboard_callback)(honey_window window, int key, int scancode, int action, int mods); +static int honey_key_callbacks[HONEY_N_KEYS]; +static int honey_key_callbacks_data[HONEY_N_KEYS]; /** @brief Initializes Honey's internal keyboard states. * @@ -176,7 +175,7 @@ int honey_key_down(lua_State* L); * @param[in] callback The callback function to bind. * @param[in] data Data to pass to the callback function upon triggering. */ -void honey_key_bind(int key, void (*callback)(void*, int), void* data); +int honey_key_bind(lua_State* L); /** @brief Unbind a key callback. * @@ -184,13 +183,13 @@ void honey_key_bind(int key, void (*callback)(void*, int), void* data); * * @param[in] key The key to unbind a callback from. */ -void honey_key_unbind(int key); +int honey_key_unbind(lua_State* L); /** @brief Unbind all key callbacks. * * THIS FUNCTION DOES NOT FREE MEMORY! If you allocated any, be sure to free it yourself! */ -void honey_key_unbind_all(); +int honey_key_unbind_all(lua_State* L); void default_honey_keyboard_callback(honey_window window, int key, int scancode, int action, int mods); @@ -13,7 +13,7 @@ bool has_function(lua_State* L, char* field) lua_getglobal(L, "honey"); lua_getfield(L, -1, field); if (lua_isfunction(L, -1)) - return true; + return true; return false; } @@ -26,32 +26,32 @@ bool parse_options(struct options* opt, int argc, char** argv) int c; while ((c = getopt(argc, argv, "vh")) != -1) { - switch (c) { - case 'v': - opt->verbose = true; - break; - - case 'h': - // print help - break; - - case '?': - if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - else - fprintf (stderr, - "Unknown option character `\\x%x'.\n", - optopt); - return false; - - default: - return false; - } + switch (c) { + case 'v': + opt->verbose = true; + break; + + case 'h': + // print help + break; + + case '?': + if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, + "Unknown option character `\\x%x'.\n", + optopt); + return false; + + default: + return false; + } } if (optind < argc) { - opt->run = true; - opt->scriptdir = argv[optind]; + opt->run = true; + opt->scriptdir = argv[optind]; } return true; @@ -66,18 +66,18 @@ GLFWwindow* setup_window(int width, int height, char* title) GLFWwindow* window = glfwCreateWindow(width, height, title, NULL, NULL); if (window == NULL) { - fprintf(stderr, "ERROR: failed to create window!\n"); - glfwTerminate(); - return NULL; + fprintf(stderr, "ERROR: failed to create window!\n"); + glfwTerminate(); + return NULL; } glfwMakeContextCurrent(window); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) { - fprintf(stderr, "ERROR: failed to initialize GLAD!\n"); - glfwTerminate(); - return NULL; + fprintf(stderr, "ERROR: failed to initialize GLAD!\n"); + glfwTerminate(); + return NULL; } honey_setup_keyboard(); @@ -95,16 +95,19 @@ int main(int argc, char** argv) { struct options opt; if (!parse_options(&opt, argc, argv)) { - fprintf(stderr, "ERROR: failed to parse command line options!\n"); - return 1; + fprintf(stderr, "ERROR: failed to parse command line options!\n"); + return 1; } if (!opt.run) - return 0; + return 0; + printf("%d\n", LUA_NOREF); + GLFWwindow* window = setup_window(480, 320, "honey-engine"); lua_State* L = luaL_newstate(); + glfwSetWindowUserPointer(window, L); luaL_openlibs(L); lua_createtable(L, 0, 1); @@ -117,20 +120,20 @@ int main(int argc, char** argv) size_t dirlen = strlen(opt.scriptdir) + 10; char* scriptfile = malloc(sizeof(char) * dirlen); if (scriptfile == NULL) { - fprintf(stderr, "ERROR: failed to allocate memory for script file string!\n"); - return 1; + fprintf(stderr, "ERROR: failed to allocate memory for script file string!\n"); + return 1; } snprintf(scriptfile, dirlen, "%s/main.lua", opt.scriptdir); if (luaL_loadfile(L, scriptfile) == 0) { - if (lua_pcall(L, 0, 1, 0) == 0) { - lua_pop(L, lua_gettop(L)); - } + if (lua_pcall(L, 0, 1, 0) == 0) { + lua_pop(L, lua_gettop(L)); + } } else { - fprintf(stderr, "ERROR: failed to open %s!\n", scriptfile); - return 1; + fprintf(stderr, "ERROR: failed to open %s!\n", scriptfile); + return 1; } opt.has_update = has_function(L, "update"); @@ -141,41 +144,41 @@ int main(int argc, char** argv) float dt; while (!glfwWindowShouldClose(window)) { - currentTime = (float) glfwGetTime(); - dt = currentTime - prevTime; - prevTime = currentTime; - glfwPollEvents(); - - lua_getglobal(L, "honey"); - - if (opt.has_update) { - lua_getfield(L, -1, "update"); - if (lua_isfunction(L, -1)) { - lua_pushnumber(L, dt); - int result = lua_pcall(L, 1, 0, 0); - if (result != 0) { - glfwSetWindowShouldClose(window, true); - } - } - else { - lua_pop(L, 1); - } - } - - if (opt.has_draw) { - lua_getfield(L, -1, "draw"); - if (lua_isfunction(L, -1)) { - int result = lua_pcall(L, 0, 0, 0); - if (result != 0) { - glfwSetWindowShouldClose(window, true); - } - } - else { - lua_pop(L, 1); - } - } - - lua_pop(L, 1); + currentTime = (float) glfwGetTime(); + dt = currentTime - prevTime; + prevTime = currentTime; + glfwPollEvents(); + + lua_getglobal(L, "honey"); + + if (opt.has_update) { + lua_getfield(L, -1, "update"); + if (lua_isfunction(L, -1)) { + lua_pushnumber(L, dt); + int result = lua_pcall(L, 1, 0, 0); + if (result != 0) { + glfwSetWindowShouldClose(window, true); + } + } + else { + lua_pop(L, 1); + } + } + + if (opt.has_draw) { + lua_getfield(L, -1, "draw"); + if (lua_isfunction(L, -1)) { + int result = lua_pcall(L, 0, 0, 0); + if (result != 0) { + glfwSetWindowShouldClose(window, true); + } + } + else { + lua_pop(L, 1); + } + } + + lua_pop(L, 1); } lua_close(L); |