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:
16
lcmd.c
16
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 */
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user