Skip to content

Commit

Permalink
lua: improve argument parsing in vis.pipe
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
fischerling committed Sep 10, 2024
1 parent 4e8815e commit 346c5ef
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 346c5ef

Please sign in to comment.