diff options
author | sanine-a <sanine.not@pm.me> | 2020-10-25 10:51:13 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-10-25 10:51:13 -0500 |
commit | 1a55ea2d22436359f8e11061e203cf9e8849a114 (patch) | |
tree | 4984cc1ded2473d313098cca31fa7401a745b2a9 /src | |
parent | 6162a18f445b89400be521fdeeb0d6a812a03c35 (diff) |
add honey_exit
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 6 | ||||
-rw-r--r-- | src/honey.c | 3 | ||||
-rw-r--r-- | src/honey_lua.c | 17 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h index 9027712..c87992a 100644 --- a/src/common.h +++ b/src/common.h @@ -179,4 +179,10 @@ int honey_lua_traceback(lua_State* L); */ int honey_lua_pcall(lua_State* L, int nargs, int nret); +/** @brief Trigger honey to exit. + * + * @returns Nothing. + */ +int honey_exit(lua_State* L); + #endif diff --git a/src/honey.c b/src/honey.c index 9e8bc45..c3b4856 100644 --- a/src/honey.c +++ b/src/honey.c @@ -70,6 +70,9 @@ bool honey_setup(lua_State** L) honey_setup_input(*L); lua_setfield(*L, -2, "input"); + lua_pushcfunction(*L, honey_exit); + lua_setfield(*L, -2, "exit"); + lua_setglobal(*L, "honey"); return true; diff --git a/src/honey_lua.c b/src/honey_lua.c index 4dd0667..1d1375f 100644 --- a/src/honey_lua.c +++ b/src/honey_lua.c @@ -273,3 +273,20 @@ int honey_lua_pcall(lua_State* L, int nargs, int nret) return result; } +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int honey_exit(lua_State* L) +{ + if (honey_window_info_ref == LUA_NOREF || + honey_window_info_ref == LUA_REFNIL) { + lua_pushstring(L, "Window information is not set!"); + lua_error(L); + } + + lua_rawgeti(L, LUA_REGISTRYINDEX, honey_window_info_ref); + honey_window_information* info = lua_touserdata(L, -1); + lua_pop(L, 1); + + glfwSetWindowShouldClose(info->window, true); + return 0; +} |