Rename resolved→done (#1-4, #11), closed→done (#13, #18), open (post-core)→open (#7), mark #9 as superseded by #21.
1.7 KiB
1.7 KiB
01 — Design and finalize syntax for all new features
Status: done Blocks: #02, #04, #05
Backtick command execution
Backtick expressions return a plain table with three fields:
local output = `ls -lha`
print(
output.code,
output.stdout,
output.stderr
)
output.stdout— captured stdout as a stringoutput.stderr— captured stderr as a stringoutput.code— integer exit code- No
__tostringmetamethod — access.stdoutexplicitly
String interpolation
Backticks support ${expr} interpolation:
local dir = "/tmp"
local result = `ls -lha ${dir}`
local pattern = "*.lua"
local result2 = `find ${dir} -name ${pattern}`
${expr} evaluates the Lua expression, converts to string, and splices it into the command string before argv parsing.
Environment variables — $ sigil
local dir = $PWD -- getenv("PWD") → string or nil
$PWD = "/" -- setenv("PWD", "/")
$MY_ENV_VAR = "data" -- setenv("MY_ENV_VAR", "data")
$NAMEas an expression →getenv("NAME"), returns string ornil$NAME = expras a statement →setenv("NAME", tostring(expr))$followed by an identifier is a new token type in the lexer- Note:
$NAME(env var) is distinct from${expr}inside backticks (interpolation)
Piping (future)
local result = `ls -l` | `grep ".lua"`
Challenge: | conflicts with Lua's bitwise OR. Pipes only valid between command expressions.
Redirection (future)
`ls -l` > "output.txt"
`ls -l` >> "output.txt"
`cmd` 2> "err.txt"
`cmd` 2>&1
`cmd` < "input.txt"
Challenge: > / >> conflict with Lua's comparison/shift operators. Only valid in command context.