Make lush.interactive() return the result table in addition to setting _

Previously it only set the global _ and returned nothing, which was
surprising when calling it as a function. Now it returns the same
{code, stdout, stderr} table it sets _ to.
This commit is contained in:
Cormac Shannon
2026-03-22 18:49:29 +00:00
parent 917509aa8a
commit daccad3c45

16
lcmd.c
View File

@@ -1205,8 +1205,7 @@ int lushCmd_interactive (lua_State *L) {
if (nstages > 1) { if (nstages > 1) {
exec_pipeline(L, stages, nstages, 1); exec_pipeline(L, stages, nstages, 1);
free(stages[0]); free(stages[0]);
lua_setglobal(L, "_"); goto set_and_return;
return 0;
} }
/* single stage */ /* single stage */
@@ -1220,21 +1219,22 @@ int lushCmd_interactive (lua_State *L) {
dynbuf_init(&empty_out); dynbuf_init(&empty_out);
dynbuf_init(&empty_err); dynbuf_init(&empty_err);
push_result_table(L, 0, &empty_out, &empty_err); push_result_table(L, 0, &empty_out, &empty_err);
lua_setglobal(L, "_"); goto set_and_return;
return 0;
} }
/* check for shell builtin */ /* check for shell builtin */
if (try_builtin(L, &pa)) { if (try_builtin(L, &pa)) {
free_argv(&pa); free_argv(&pa);
lua_setglobal(L, "_"); goto set_and_return;
return 0;
} }
fork_exec_single(L, &pa, 0); fork_exec_single(L, &pa, 0);
free_argv(&pa); free_argv(&pa);
lua_setglobal(L, "_");
return 0; set_and_return:
lua_pushvalue(L, -1); /* duplicate result table */
lua_setglobal(L, "_"); /* pop one copy into _ */
return 1; /* return the other */
} }