From daccad3c45ccd2022fd7da479dd83024ca5009af Mon Sep 17 00:00:00 2001 From: Cormac Shannon <> Date: Sun, 22 Mar 2026 18:49:29 +0000 Subject: [PATCH] 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. --- lcmd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lcmd.c b/lcmd.c index f5fd6fdd..83cd0fc4 100644 --- a/lcmd.c +++ b/lcmd.c @@ -1205,8 +1205,7 @@ int lushCmd_interactive (lua_State *L) { if (nstages > 1) { exec_pipeline(L, stages, nstages, 1); free(stages[0]); - lua_setglobal(L, "_"); - return 0; + goto set_and_return; } /* single stage */ @@ -1220,21 +1219,22 @@ int lushCmd_interactive (lua_State *L) { dynbuf_init(&empty_out); dynbuf_init(&empty_err); push_result_table(L, 0, &empty_out, &empty_err); - lua_setglobal(L, "_"); - return 0; + goto set_and_return; } /* check for shell builtin */ if (try_builtin(L, &pa)) { free_argv(&pa); - lua_setglobal(L, "_"); - return 0; + goto set_and_return; } fork_exec_single(L, &pa, 0); 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 */ }