aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-09-10 09:52:49 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-09-13 06:04:17 -0600
commit06453ed994acbaa48a590fa71d4dfb18e1ff3a64 (patch)
tree193678b534d75f3c6459f32aefef2cf26464aed6
parentc569e85f6a1521b30437335b247732f6af635a61 (diff)
downloadvis-06453ed994acbaa48a590fa71d4dfb18e1ff3a64.tar.gz
vis-06453ed994acbaa48a590fa71d4dfb18e1ff3a64.tar.xz
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).
-rw-r--r--vis-lua.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 0a435b4..f347886 100644
--- 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);
}