Commit Graph

5836 Commits

Author SHA1 Message Date
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
Cormac Shannon
08df164692 Add issues #25, #26, #27; update #7 and #22 statuses
- #25: $VAR expansion in commands
- #26: Shell abbreviations and user-extensible builtins
- #27: $(cmd) subcommand syntax
- #22: Updated with implementation details (in progress)
- #7: Standardize status label
2026-03-15 19:33:19 +00:00
Cormac Shannon
5135b16375 Unify command tokens: remove TK_COMMAND_INTERP and TK_INTERACTIVE_INTERP
Use cmd_mode (already on LexState) to signal whether interpolation
follows, instead of separate *_INTERP token variants. This eliminates
duplicate simple/interpolated code paths in the parser — commandexp()
and interactivestat() now each use a single unified loop that checks
cmd_mode != 0. A shared parseinterp() helper handles each ${expr}
interpolation cycle.
2026-03-12 23:01:31 +00:00
Cormac Shannon
f09a033160 Replace upvalue-based shell dispatch with OP_LUSH opcode
Add a dedicated OP_LUSH A B instruction that loads shell C functions
directly from the registry, eliminating the need for upvalue allocation
in mainfunc(), upvalue population in lua_load(), and the fragile
LUSH_NUM_UPVALS heuristic. Every chunk no longer carries 4 extra
upvalues.
2026-03-12 22:47:25 +00:00
Cormac Shannon
f88b17959f Hide shell functions from _G using upvalues on the main chunk
Store __command, __interactive, __getenv, __setenv as upvalues
populated by lua_load() from the registry, keeping them invisible
to user code while accessible to the parser's codegen.
2026-03-12 22:46:56 +00:00
Cormac Shannon
34bfabccbd Expand issue #23 with detailed cleanup analysis; close issues #5 and #24
Issue #23 now covers function naming conventions, file organisation,
global namespace cleanup options, and a concrete implementation plan.
2026-03-12 19:26:05 +00:00
Cormac Shannon
c556928d0a Add compatibility test script for third-party Lua projects (issue #24)
Tests lua-TestMore, json.lua, and lume against the Lush binary to verify
parser/lexer/runtime changes don't break standard Lua code.
2026-03-12 19:04:21 +00:00
Cormac Shannon
0cfd327180 Update: issue 24 2026-03-10 23:53:08 +00:00
Cormac Shannon
ecab5ca6c7 Issue: lua test compatibility 2026-03-10 21:44:37 +00:00
Cormac Shannon
f49a73bc52 Close issues #13 and #18 2026-03-10 21:35:48 +00:00
Cormac Shannon
a43fd10e64 Implement shell globbing, tilde expansion, and brace expansion (issues #13, #18)
Unquoted tokens are now expanded through a tilde → brace → glob pipeline
in parse_argv. Quoted tokens (single, double, or backslash) suppress all
expansion. Uses glob(3) with GLOB_NOCHECK for wildcard matching and manual
implementations for tilde (~→$HOME) and brace ({a,b,c}) expansion.
2026-03-10 21:31:55 +00:00
Cormac Shannon
c96fae90c0 Fix nested commands in interactive mode triggering prompt2 (issue #19)
Save and restore cmd_mode across interpolation parsing so that
luaX_readcommandcont resumes in the correct mode after a nested
backtick command inside ${...}.
2026-03-05 00:13:34 +00:00
Cormac Shannon
b3aa1d9c63 Redesign prompt system: revert #09, use standard _PROMPT (issue #21)
Revert the bespoke __prompt()/__prompt2() function mechanism from issue
#09 and return to stock Lua's _PROMPT/_PROMPT2 globals (which already
support dynamic prompts via __tostring metatables). Set default
_PROMPT = "lush> " in doREPL if not already defined by config.
2026-03-04 23:53:04 +00:00
Cormac Shannon
9e75175c79 Add issues #16–#23
#16 multiline shell commands
#17 _ scope (global vs local)
#18 path expansion (~)
#19 nested commands trigger prompt2
#20 simplify backtick return value
#21 prompt redesign
#22 implicit interactive commands (drop ! prefix)
#23 general cleanup and refactor
2026-03-04 23:28:11 +00:00
Cormac Shannon
4cc352cbec Implement shell builtins: cd, exec, umask (issue #15)
Add builtin dispatch in lcmd.c that checks __builtins table before
fork(), so cd/exec/umask operate on the shell process itself.
2026-03-04 19:20:42 +00:00
Cormac Shannon
e8756d5d78 Implement programmable prompt (issue #09)
Replace static _PROMPT/_PROMPT2 with dynamic __prompt(exitcode)/__prompt2(exitcode)
functions. Fallback chain: __prompt() → _PROMPT → "> ". Install a default __prompt
that shows the current directory with ~ abbreviation. Track last exit code from the
REPL loop and pass it to the prompt function.
2026-03-03 23:19:09 +00:00
Cormac Shannon
bbc0f24009 Implement startup configuration file support (issue #08)
Load ~/.config/lush/config and config.d/*.lua at REPL startup,
respecting XDG_CONFIG_HOME. Suppressed by -E flag.
2026-03-03 22:59:51 +00:00
Cormac Shannon
db858b3f68 Implement prefix-based interactive commands via ! (issue #14)
Add !command syntax that runs commands with inherited terminal (no
capture). The lexer treats ! as a statement-starting token, reading
to end-of-line with the same interpolation/escape/pipe support as
backtick commands. The C function sets _ = {code=N, stdout="", stderr=""}.
2026-03-02 22:06:29 +00:00
Cormac Shannon
75098da240 Add issue #14: prefix-based interactive commands via ! 2026-03-02 21:16:06 +00:00
Cormac Shannon
0d23741891 Add issue #13: shell globbing (*, ?, **, {a,b}, [abc]) 2026-03-02 00:37:13 +00:00
Cormac Shannon
d0181e685d Implement piping between commands in backtick syntax (issue #06)
Add split_pipeline() to split command strings on unquoted | and
exec_pipeline() to fork N children connected by inter-stage pipes.
Only the last stage's stdout/stderr are captured; middle stages'
stderr is inherited. Exit code comes from the last stage.
2026-03-01 22:17:30 +00:00
Cormac Shannon
41b2095ed9 Rewrite issue #10 for scripts+REPL, add issue #12, add interactive command tests
Redesign issue #10: bare-word commands now work in both scripts and
the REPL via a parser-level heuristic (identifier + non-exception-list
token → shell command). Add runtime fallback for string-arg syntax
(echo "hello"), double-dash flag handling, and classification examples.

Add issue #12 for path-based command execution (./script, /bin/ls, ~/bin/deploy).

Add testes/lush/commands-interactive.lua as a design playground covering
result table structure, exit codes, commands inside Lua blocks, _ behaviour,
runtime fallback, Lua variable shadowing, and interleaved Lua/shell.
2026-03-01 19:35:09 +00:00
Cormac Shannon
af8300aa40 Make Ctrl-C clear line and re-prompt in REPL instead of exiting
Use sigsetjmp/siglongjmp to catch SIGINT during readline/fgets input
and jump back to the REPL loop with a fresh prompt. Running Lua code
still gets interrupted via the existing laction/lstop mechanism.

Fixes #11.
2026-02-28 23:35:30 +00:00
Cormac Shannon
47abb04921 Rewrite issue #10, add issue #11 (Ctrl-C REPL behaviour)
Rewrite #10 with refined interactive command design: bare-word REPL
fallback instead of ! prefix, result table assigned to _, same shape
as captured commands. Add #11 for Ctrl-C clearing the current line
instead of exiting the REPL.
2026-02-28 23:20:55 +00:00
Cormac Shannon
84b9aeb7e9 Auto-detect platform in makefiles and test runner
Use uname -s to select Linux vs macOS build flags instead of
hardcoding. Add -undefined dynamic_lookup for test shared libs
on macOS. Set _port=true automatically on non-Linux in ./all.
2026-02-28 19:27:14 +00:00
Cormac Shannon
27f16b126d Add lush feature tests and fix /dev/full test for macOS
Add test suite under testes/lush/ covering backtick commands, argv
parsing, ${} interpolation, and $NAME environment variables. Wire
them into testes/all.lua so they run with the full Lua 5.5 suite.

Skip /dev/full test in files.lua when the device doesn't exist
(macOS has no /dev/full).
2026-02-28 19:07:00 +00:00
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
Cormac Shannon
39d6cc95cb Add command execution runtime (lcmd.c, lcmd.h)
Implements luaB_command: fork/execvp with pipe-captured stdout/stderr,
argv parsing with quoting/escaping, and non-blocking pipe reading via
select(). Backs the __command() calls emitted by the backtick parser.

Resolves #03 and #04.
2026-02-28 18:27:42 +00:00
Cormac Shannon
882a90be48 Add environment variable access with $NAME syntax
Lexes $NAME as TK_ENVVAR, compiles reads as __getenv("NAME") calls
and writes ($NAME = expr) as __setenv("NAME", expr) calls. Runtime
functions wrap getenv/setenv/unsetenv with automatic tostring coercion.
2026-02-28 18:08:09 +00:00
Cormac Shannon
a773398cab Compile backtick commands as __command() calls with ${} interpolation
Backtick expressions now compile as calls to a global __command()
function instead of being treated as plain strings. Interpolation
via ${expr} is supported, with each interpolated value wrapped in
tostring() for type safety. Commands are parsed in primaryexp so
suffix operations like `.stdout` work directly.

Adds a stub __command that returns {code, stdout, stderr} for testing
until the real implementation (issue #03).
2026-02-19 20:00:15 +00:00
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
Roberto I
4cf498210e '__pairs' can also return a to-be-closed object 2025-11-11 15:11:06 -03:00
Roberto I
5b7d998764 External strings are as good as internal ones
A '__mode' metafield and an "n" key both can be external strings.
2025-11-11 14:40:30 -03:00
Roberto I
81f4def54f Correction in line info for semantic errors
Semantic errors should refer the last used token, not the next one.
2025-11-11 14:36:16 -03:00
Roberto I
e44f3a2ffc Global initialization checks name conflict
Initialization "global a = 10" raises an error if global 'a' is already
defined, that is, it has a non-nil value.
2025-11-08 11:43:42 -03:00
Roberto I
f791bb6906 Details
- New macro l_strcoll to ease changing 'strcoll' to something else.
- MAXINDEXRK==1 in 'ltests.h' is enough to run test 'code.lua'.
- Removed unused '#include' in 'lutf8lib.c'.
2025-10-31 14:48:55 -03:00
Roberto I
d342328e5b Vertical bar removed from syntax of vararg table
The syntax 'function foo (a, b, ...arg)' is already used by JavaScript
for this same semantics, so it seems natural to use the same notation in
Lua.
2025-10-30 11:07:01 -03:00
Roberto Ierusalimschy
0149b781d4 Case VVARGIND added to luaK_storevar
In a global initialization, the variable does not pass through
'check_readonly', and therefore a VVARGIND is not normalized to a
VINDEXED.
2025-10-30 10:39:55 -03:00
Roberto I
d4eff00234 Fixed initialization of global variables
When calling 'luaK_storevar', the 'expdesc' for the variable must be
created before the one for the expression, to satisfy the assumptions
for register allocation. So, in a statement like 'global a = exp', where
'a' is actually '_ENV.a', this variable must be handled before the
initializing expression 'exp'.
2025-10-29 13:14:48 -03:00
Roberto I
fca974486d Small change in 'trymt'
Operation name can be diferent from metamethod name.
2025-10-18 10:34:42 -03:00
Roberto I
26755cad99 Added "attribute internal" to __MACH__ platforms
Also, makefile does not add compiling options (LOCAL) to linker
flags (MYLDFLAGS).
2025-10-18 10:30:12 -03:00
Roberto I
b352217b84 Standard allocator function added to the API
That makes easier to redefine luaL_newstate.
2025-10-17 13:53:35 -03:00
Roberto I
9c66903cc5 Details
- Functions luaK_goiffalse, luaS_hash made private.
- Removed unused macro log2maxs.
2025-10-14 13:50:24 -03:00
Roberto I
30a7b93439 Two new memory tests
For external strings and for vararg tables.
2025-10-12 15:13:28 -03:00
Roberto I
7a92f3f99a Change in dumping of NULL strings
When dumping a string, adding 2 to its size may overflow a size_t for
external strings, which may not have a header. (Adding 1 is Ok, because
all strings end with a '\0' not included in their size.) The new method
for saving NULL strings code them as a repeated string, using the
reserved index 0.
2025-10-10 15:28:41 -03:00
Roberto I
3347c9d32d Initialization of too many locals break assertion
The check for limit of local variables is made after generating code to
initialize them. If there are too many local variables not initialized,
the coding of instruction OP_LOADNIL could overflow an argument.
2025-10-10 13:22:19 -03:00
Roberto I
25c54fe60e Optimization for vararg tables
A vararg table can be virtual. If the vararg table is used only as
a base in indexing expressions, the code does not need to create an
actual table for it. Instead, it compiles the indexing expressions
into direct accesses to the internal vararg data.
2025-09-24 18:33:08 -03:00
Roberto I
0cc3c9447c Small tweaks in makefile 2025-09-18 11:03:55 -03:00
Roberto I
8fb1af0e33 Varag parameter is a new kind of variable
To allow some optimizations on its use.
2025-09-17 16:07:48 -03:00
Roberto I
140b672e2e Vararg table
Not yet optimized nor documented.
2025-09-16 13:26:24 -03:00