diff options
| author | Jörg Bakker <captaingroove@openmultimedia.org> | 2023-06-16 11:25:08 +0200 |
|---|---|---|
| committer | Randy Palamar <palamar@ualberta.ca> | 2023-06-22 09:17:26 -0600 |
| commit | 424b2190b9207eea9807eef7132cd95e881cbbbf (patch) | |
| tree | 8e8ce1ade30ed1c30476adfe77b92f3f68593f40 /vis-lua.c | |
| parent | d897956f922220972c6fd4bdc218b31647d4a4ec (diff) | |
| download | vis-424b2190b9207eea9807eef7132cd95e881cbbbf.tar.gz vis-424b2190b9207eea9807eef7132cd95e881cbbbf.tar.xz | |
Lua API: allow nil in vis:pipe() File and Range parameters
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -1325,10 +1325,11 @@ static int exit_func(lua_State *L) { * Pipe file range to external process and collect output. * * The editor core will be blocked while the external process is running. + * File and Range can be omitted or nil to indicate empty input. * * @function pipe - * @tparam File file the file to which the range applies - * @tparam Range range the range to pipe + * @tparam[opt] File file the file to which the range applies + * @tparam[opt] Range range the range to pipe * @tparam string command the command to execute * @treturn int code the exit status of the executed command * @treturn string stdout the data written to stdout @@ -1336,10 +1337,17 @@ static int exit_func(lua_State *L) { */ static int pipe_func(lua_State *L) { Vis *vis = obj_ref_check(L, 1, "vis"); - File *file = obj_ref_check(L, 2, VIS_LUA_TYPE_FILE); - Filerange range = getrange(L, 3); - const char *cmd = luaL_checkstring(L, 4); + int cmd_idx = 4; char *out = NULL, *err = NULL; + File *file = vis->win->file; + Filerange range = text_range_new(0, 0); + if (lua_gettop(L) <= 3) { + cmd_idx = 2; + } else if (!(lua_isnil(L, 2) && lua_isnil(L, 3))) { + file = obj_ref_check(L, 2, VIS_LUA_TYPE_FILE); + range = getrange(L, 3); + } + const char *cmd = luaL_checkstring(L, cmd_idx); int status = vis_pipe_collect(vis, file, &range, (const char*[]){ cmd, NULL }, &out, &err); lua_pushinteger(L, status); if (out) |
