vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit d062b9503dda792b3710ab478d2e037ab51da24a parent c17f12ef912a3972467f1abcc4dc8cd1d99988c0 Author: Florian Fischer <florian.fischer@muhq.space> Date: Tue, 10 Sep 2024 09:52:49 +0200 lua: improve argument parsing in vis.pipe Support the old behavior of using vis:pipe(cmd, fullscreen) without input. Properly distinguish between vis:pipe(text, cmd, fullscreen) and vis:pipe(file, range, cmd). Diffstat:
| M | vis-lua.c | | | 16 | ++++++++++------ |
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/vis-lua.c b/vis-lua.c @@ -1254,15 +1254,19 @@ static int pipe_func(lua_State *L) { const char *text = NULL; File *file = vis->win ? vis->win->file : NULL; Filerange range = text_range_new(0, 0); - if (lua_gettop(L) == 2) { + if (lua_gettop(L) == 2) { // vis:pipe(cmd) cmd_idx = 2; } else if (lua_gettop(L) == 3) { - text = luaL_checkstring(L, 2); - if (text != NULL) - cmd_idx = 3; - else + if (lua_isboolean(L, 3)) { // vis:pipe(cmd, fullscreen) cmd_idx = 2; - } else if (!(lua_isnil(L, 2) && lua_isnil(L, 3))) { + } else { // vis:pipe(text, cmd) + text = luaL_checkstring(L, 2); + cmd_idx = 3; + } + } else if (lua_isboolean(L, 4)) { // vis:pipe(text, cmd, fullscreen) + text = luaL_checkstring(L, 2); + cmd_idx = 3; + } else if (!(lua_isnil(L, 2) && lua_isnil(L, 3))) { // vis:pipe(file, range, cmd, [fullscreen]) file = obj_ref_check(L, 2, VIS_LUA_TYPE_FILE); range = getrange(L, 3); }