diff options
Diffstat (limited to 'src/nvim/lua/executor.c')
| -rw-r--r-- | src/nvim/lua/executor.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 199813bf4a..c2b1887d60 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -601,6 +601,17 @@ static int nlua_check_interrupt(lua_State *lstate) return 1; } +static int nlua_os_exit(lua_State *lstate) +{ + int status = 0; + if (lua_gettop(lstate) >= 1 && !lua_isnil(lstate, 1)) { + status = lua_isboolean(lstate, 1) ? (lua_toboolean(lstate, 1) ? 0 : 1) + : (int)luaL_checkinteger(lstate, 1); + } + getout(status); + return 0; // Unreachable, but MSVC does not infer getout() is noreturn. +} + static nlua_ref_state_t *nlua_new_ref_state(lua_State *lstate, bool is_thread) FUNC_ATTR_NONNULL_ALL { @@ -841,6 +852,12 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pop(lstate, 1); #endif + // os.exit() + lua_getglobal(lstate, "os"); + lua_pushcfunction(lstate, &nlua_os_exit); + lua_setfield(lstate, -2, "exit"); + lua_pop(lstate, 1); + // vim lua_newtable(lstate); |