diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-11-20 13:15:01 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-11-21 10:52:33 +0100 |
| commit | c00ef937ac0e6bc6391f973783e900ff5691f4c3 (patch) | |
| tree | a5862fb13f978c39b9c84def51d7da34671c1f1c | |
| parent | 2d4aebd7d2d13024b56edf35188f3a68c186ea41 (diff) | |
| download | vis-c00ef937ac0e6bc6391f973783e900ff5691f4c3.tar.gz vis-c00ef937ac0e6bc6391f973783e900ff5691f4c3.tar.xz | |
vis-lua: implement window:close
| -rw-r--r-- | vis-lua.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -1741,6 +1741,33 @@ static int window_draw(lua_State *L) { return 0; } +/*** + * Close window. + * + * After a successful call the Window reference becomes invalid and + * must no longer be used. Attempting to close the last window will + * always fail. + * + * @function close + * @see exit + * @tparam bool force whether unsaved changes should be discarded + * @treturn bool whether the window was closed + */ +static int window_close(lua_State *L) { + Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW); + int count = 0; + for (Win *w = win->vis->windows; w; w = w->next) { + if (!w->file->internal) + count++; + } + bool force = lua_isboolean(L, 2) && lua_toboolean(L, 2); + bool close = count > 1 && (force || vis_window_closable(win)); + if (close) + vis_window_close(win); + lua_pushboolean(L, close); + return 1; +} + static const struct luaL_Reg window_funcs[] = { { "__index", window_index }, { "__newindex", newindex_common }, @@ -1751,6 +1778,7 @@ static const struct luaL_Reg window_funcs[] = { { "style", window_style }, { "status", window_status }, { "draw", window_draw }, + { "close", window_close }, { NULL, NULL }, }; |
