Files
lush/issues/05-env-var-access.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.1 KiB

05 — Implement environment variable access (read/write)

Status: open Blocked by: #01

Add syntax for reading and writing environment variables directly from Lua.

Option 1 — export keyword

local var = "my data"
export var                    -- exports existing local to env
export other_var = "my data"  -- creates + exports
  • New reserved word export in lexer
  • export var looks up the local's value by name and calls setenv()
  • export x = val combines declaration with setenv()

Option 2 — $ sigil

local dir = $PWD              -- getenv("PWD")
$PWD = "/"                    -- setenv("PWD", "/")
$MY_ENV_VAR = "data"          -- setenv("MY_ENV_VAR", "data")
  • $NAME as expression → getenv("NAME"), returns string or nil
  • $NAME = expr as statement → setenv("NAME", tostring(expr))
  • New token type in lexer for $ + identifier

Implementation touches

  • llex.c / llex.h — new token(s) or reserved word
  • lparser.c — new expression/statement rules
  • Runtime calls getenv() / setenv() — standard C, no shell needed
  • Non-existent env var → return nil