Files
lush/issues/01-syntax-design.md
Cormac Shannon bad40fb65b Standardize issue status labels to done/open/in progress
Rename resolved→done (#1-4, #11), closed→done (#13, #18),
open (post-core)→open (#7), mark #9 as superseded by #21.
2026-03-15 19:33:49 +00:00

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 string
  • output.stderr — captured stderr as a string
  • output.code — integer exit code
  • No __tostring metamethod — access .stdout explicitly

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")
  • $NAME as an expression → getenv("NAME"), returns string or nil
  • $NAME = expr as 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.