Implement $(cmd) subcommand syntax in commands (issue #27)

Add $() for inline subcommand substitution that runs a command and
inserts its stdout (trailing newlines stripped) into the outer command
string. Supports nesting, and mixing with ${expr} and $NAME.
This commit is contained in:
Cormac Shannon
2026-03-18 09:29:51 +00:00
parent 42baabde34
commit 1766e40a68
8 changed files with 143 additions and 7 deletions

View File

@@ -45,7 +45,7 @@ static const luaL_Reg stdlibs[] = {
/*
** Store shell functions in a registry table at LUA_RIDX_LUSH.
** Integer keys 1..4 hold the C functions (accessed by OP_LUSH).
** Integer keys 1..5 hold the C functions (accessed by OP_LUSH).
** String key "builtins" holds the builtins table (set by luaopen_builtins).
*/
static void opencommand (lua_State *L) {
@@ -58,6 +58,8 @@ static void opencommand (lua_State *L) {
lua_rawseti(L, -2, LUSH_OP_GETENV + 1);
lua_pushcfunction(L, lushCmd_setenv);
lua_rawseti(L, -2, LUSH_OP_SETENV + 1);
lua_pushcfunction(L, lushCmd_subcmd);
lua_rawseti(L, -2, LUSH_OP_SUBCMD + 1);
lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_LUSH);
}