Files
lush/issues/03-command-execution-runtime.md
Cormac Shannon 4b49907ce7 Update project issues: resolve #02-#04, add #08-#10
Mark issues #02 (backtick lexing/parsing), #03 (command execution
runtime), and #04 (argv parsing) as resolved. Add new issues for
configuration (#08), programmable prompt (#09), and interactive
command execution (#10).
2026-02-28 18:27:55 +00:00

1.3 KiB

03 — Implement direct command execution runtime (no shell)

Status: resolved 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?