diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-03-03 11:11:03 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-03-03 11:11:03 +0100 |
| commit | 750cc3187fa66c207d8dc9f10389f4f7ef958ad7 (patch) | |
| tree | a2e55ee97b784781c47c8b9926127240317bdcdb | |
| parent | a08fff28fb2f0bdcf998d1cc2094a2c2654de5fd (diff) | |
| download | vis-750cc3187fa66c207d8dc9f10389f4f7ef958ad7.tar.gz vis-750cc3187fa66c207d8dc9f10389f4f7ef958ad7.tar.xz | |
vis-lua: add vis:exit function
| -rw-r--r-- | vis-lua.c | 21 | ||||
| -rw-r--r-- | vis.c | 3 |
2 files changed, 24 insertions, 0 deletions
@@ -1101,6 +1101,26 @@ static int replace(lua_State *L) { } /*** + * Terminate editor process. + * + * Termination happens upon the next iteration of the main event loop. + * This means the calling Lua code will be executed further until it + * eventually hands over control to the editor core. The exit status + * of the most recent call is used. + * + * All unsaved chanes will be lost! + * + * @function exit + * @tparam int code the exit status returned to the operating system + */ +static int exit_func(lua_State *L) { + Vis *vis = obj_ref_check(L, 1, "vis"); + int code = luaL_checkint(L, 2); + vis_exit(vis, code); + return 0; +} + +/*** * Currently active window. * @tfield Window win * @see windows @@ -1204,6 +1224,7 @@ static const struct luaL_Reg vis_lua[] = { { "insert", insert }, { "replace", replace }, { "action_register", action_register }, + { "exit", exit_func }, { "__index", vis_index }, { "__newindex", vis_newindex }, { NULL, NULL }, @@ -529,6 +529,7 @@ Vis *vis_new(Ui *ui, VisEvent *event) { Vis *vis = calloc(1, sizeof(Vis)); if (!vis) return NULL; + vis->exit_status = -1; vis->ui = ui; vis->tabwidth = 8; vis->expandtab = false; @@ -1149,6 +1150,8 @@ bool vis_signal_handler(Vis *vis, int signum, const siginfo_t *siginfo, const vo int vis_run(Vis *vis, int argc, char *argv[]) { if (!vis->windows) return EXIT_SUCCESS; + if (vis->exit_status != -1) + return vis->exit_status; vis->running = true; vis_event_emit(vis, VIS_EVENT_START); |
