Commit Graph

5815 Commits

Author SHA1 Message Date
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
Roberto I
9ea06e61f2 Details
- LUAMOD_API defined as 'extern "C"' in C++.
- "ANSI C" is in fact "ISO C" (comments)
- Removed option -std from makefile in testes/libs. (Easier to change
  to C++ for tests).
2025-09-05 15:36:47 -03:00
Roberto I
ffbcadfb41 In C++, 'throw' must go to the correct handler.
In C, we may have several "setjmp" nested, and the "longjmp" will go
to the one given by the corresponding "jmp_buf". In C++, a "throw"
will always go to the inner "catch". So, the "catch" must check
whether it is the recipient of the "throw" and, if not, rethrow
the exception to the outer level.
2025-09-05 15:29:15 -03:00
Roberto Ierusalimschy
0b73ed8f08 Allows LUA_32BITS to be defined externally
An external definition for LUA_32BITS can change the API, but libraries
check number-format compatibility when loading. So, any incompatible
modules will report a clear error.
2025-08-30 16:16:02 -03:00
Roberto I
f87416f1a3 Added limit to number of elements in a constructor
The reasoning in commit 519c57d5 is wrong: A sequence of nils generates
several fields with just one OP_LOADNIL.
2025-08-27 10:30:54 -03:00
Roberto I
03a3473687 'ltests.h' should not use LUAI_FUNC
LUAI_FUNC is now defined in llimits.h.
2025-08-27 10:28:31 -03:00
Roberto Ierusalimschy
9a3940380a New compile option LUA_USE_OFF_T
Allows non-Posix systems to use off_t and related functions for
file offsets.
2025-08-26 12:30:34 -03:00
Roberto Ierusalimschy
711890624f update in 'onelua.c' 2025-08-26 12:30:05 -03:00
Roberto Ierusalimschy
13d2326a23 Some definitions moved from luaconf.h to llimits.h
These definitions were in luaconf.h only because the standard libraries
need them. Now that llimits.h is included by the libraries, it offers a
more private place for these definitions.
2025-08-21 10:51:17 -03:00
Roberto I
06c5d3825f Removed code for compatibility with version 5.3 2025-08-20 16:10:54 -03:00
Roberto I
c345877e4c Better documentation for LUA_ERRERR
Not all errors in a message handler generate a LUA_ERRERR.
2025-08-20 15:29:46 -03:00
Roberto I
907d172c11 Added lock/unlock to API function 'lua_rawlen'
The call to 'luaH_getn' can change the "field" 'lenhint' of a table.
2025-08-20 15:00:53 -03:00
Roberto I
88aa4049ad Keep the order left-right in shifts
Opcodes OP_SHLI-OP_SHRI and the cases for opcodes OP_SHL-OP_SHR were
out of order.
2025-08-20 14:31:07 -03:00
Roberto I
c688b00f73 Detail in 'obj2gco'
Its check should use the type of the object, not its tag. (Change only
relevant in test mode.)
2025-08-20 14:18:12 -03:00
Roberto I
dd095677e3 Small cleaning services 2025-08-20 13:59:08 -03:00
Roberto I
53dc5a3bba Functions 'frexp'-'ldexp' back to the math library
They are basic for anything that handles the representation of
floating numbers.
2025-08-09 15:15:20 -03:00
Roberto I
5b179eaf6a Details 2025-08-09 15:08:53 -03:00
Roberto Ierusalimschy
8fddca81e7 'onelua' can use the test library
Just add -DLUA_USER_H='"ltests.h"' when compiling it.
2025-07-29 14:35:04 -03:00
Roberto Ierusalimschy
c33bb08ffe Added some casts for 32-bit machines
When both 'int' and 'l_obj' have 32 bits, an unsigned int needs a
cast to be assigned to 'l_obj'. (As long as 'l_obj' can count the
total memory used by the system, these casts should be safe.)
2025-07-29 11:50:20 -03:00
Roberto Ierusalimschy
e3716ee161 Fix in string.rep
The cast of n (number of repetitions) to size_t may truncate its value,
causing a buffer overflow later. Better to check the buffer size
using lua_Integer, as all string lengths must fit in a lua_Integer and
n already is a lua_Integer. If everything fits in MAX_SIZE, then we can
safely convert n to size_t and compute the buffer size as a size_t.

As a corner case, n can be larger than size_t if the strings being
repeated have length zero, but in this case it will be multiplied by
zero, so an overflow in the cast is irrelevant.
2025-07-23 18:12:53 -03:00
Roberto Ierusalimschy
303f415559 Randomness added to table length computation
A bad actor could fill only a few entries in a table (power of twos in
decreasing order, see tests) and produce a small table with a huge
length. If your program builds a table with external data and iterates
over its length, this behavior could be an issue.
2025-07-18 16:18:30 -03:00
Roberto Ierusalimschy
ccb8b307f1 Correction in utf8.offset
Wrong utf-8 character may have no continuation bytes.
2025-07-18 16:10:28 -03:00