From 1a55ea2d22436359f8e11061e203cf9e8849a114 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Sun, 25 Oct 2020 10:51:13 -0500 Subject: add honey_exit --- src/common.h | 6 ++++++ src/honey.c | 3 +++ src/honey_lua.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) (limited to 'src') 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; +} -- cgit v1.2.1