Files
lush/issues/03-command-execution-runtime.md
Cormac Shannon db6f39a2a4 Add project issues for lush (Lua + shell) features
Defines syntax decisions and implementation plan across 7 issues:
- backtick command execution returning {code, stdout, stderr}
- ${expr} interpolation in backticks
- $SIGIL env var read/write
- argv parsing, piping, and redirection (future)
2026-02-18 19:08:59 +00:00

1.3 KiB

03 — Implement direct command execution runtime (no shell)

Status: open Blocked by: #02 Blocks: #06, #07

Implement the C runtime that executes commands when a backtick expression is evaluated.

Critical constraint: do NOT spawn a shell (no bash, dash, sh, system(), popen()).

Return value

Backtick expressions return a table:

local r = `ls -lha`
r.code    -- exit code (integer)
r.stdout  -- captured stdout (string)
r.stderr  -- captured stderr (string)

Implementation approach

  • fork() + execvp() on Unix/macOS
  • Set up two pipes: one for stdout, one for stderr
  • In child: dup2() pipes onto fd 1 and fd 2, then execvp(argv[0], argv)
  • In parent: read both pipes into buffers, waitpid() for exit status
  • Build a Lua table with code, stdout, stderr fields and push onto stack
  • Depends on #04 (argv parsing) to tokenize the command string into argv[]

Error handling

  • Command not found → set code to an error value, stderr to error message
  • Permission denied → same
  • fork() failure → raise a Lua error

Open questions

  • New file (lcmd.c / lcmd.h) or add to an existing lib?
  • Signal handling during child execution
  • Binary output — return raw string bytes as-is?
  • Set __tostring metamethod on result table?