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)
1.3 KiB
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, thenexecvp(argv[0], argv) - In parent: read both pipes into buffers,
waitpid()for exit status - Build a Lua table with
code,stdout,stderrfields and push onto stack - Depends on #04 (argv parsing) to tokenize the command string into argv[]
Error handling
- Command not found → set
codeto an error value,stderrto 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
__tostringmetamethod on result table?