54 Commits

Author SHA1 Message Date
Cormac Shannon
fbb7b441c3 Refactor(builtins): Move luaopen_builtins from linit to lcmd 2026-03-20 23:16:00 +00:00
Cormac Shannon
768de9fe8b Expose lush global as a standard library (issue #26)
Register luaopen_lush() in stdlibs so the lush table is available as a
global. Users can now extend the shell by adding functions to
lush.builtins. The OP_LUSH VM access via integer keys is preserved.
2026-03-18 09:52:56 +00:00
Cormac Shannon
1766e40a68 Implement $(cmd) subcommand syntax in commands (issue #27)
Add $() for inline subcommand substitution that runs a command and
inserts its stdout (trailing newlines stripped) into the outer command
string. Supports nesting, and mixing with ${expr} and $NAME.
2026-03-18 09:29:51 +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
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
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
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
Roberto Ierusalimschy
a08d82eb13 llimits.h being used by all Lua code
The definitions in llimits.h are useful not only for the core. That
header only defines types and '#define's, so libs and core still do
not share any real code/data.
2024-06-20 14:46:06 -03:00
Roberto Ierusalimschy
165389b27b New interface to function 'luaL_openselectedlibs'
Instead of preloading all non-loaded libraries, there is another
mask to select which libraries to preload.
2024-02-15 11:17:39 -03:00
Roberto Ierusalimschy
d738c8d18b New function 'luaL_openselectedlibs'
Makes it easier to start Lua with only some standard libraries.
2022-12-07 15:12:52 -03:00
Roberto Ierusalimschy
f99509581e Removed extra information from RCS keyword strings
Version numbers and dates (mostly wrong) from RCS keyword strings
removed from all source files; only the file name are kept.
2018-08-23 14:26:12 -03:00
Roberto Ierusalimschy
34b00c16e2 removed compatibility code with older versions 2018-02-27 15:47:32 -03:00
Roberto Ierusalimschy
5a1c8d8ef3 new constant 'LUA_GNAME' for the name of the global table "_G" 2017-06-27 15:32:49 -03:00
Roberto Ierusalimschy
b2aa2ba046 using constants for "_LOADED" and "PRELOAD" 2016-12-04 18:17:24 -02:00
Roberto Ierusalimschy
3317f5c6d9 includes 'stddef.h' (as it uses NULL) 2015-01-05 11:48:33 -02:00
Roberto Ierusalimschy
36efa6a6b9 no more 'preloadedlibs' when opening libraries (as it is dead code now) 2014-12-09 13:00:17 -02:00
Roberto Ierusalimschy
460968353f in test mode, debug library is not predefined (to allow testing
'preloadedlibs')
2014-12-06 18:42:58 -02:00
Roberto Ierusalimschy
28fdbcf393 added include for 'lprefix.h', for stuff that must be added before
any other header file
2014-11-02 17:19:04 -02:00
Roberto Ierusalimschy
a73da6112d deprecated library throws an error if called (instead of silently
not loading itself)
2014-05-15 16:28:34 -03:00
Roberto Ierusalimschy
6ccf150039 new library: utf8 2014-02-06 15:32:33 -02:00
Roberto Ierusalimschy
19fbdf6cae 'luaL_findtable' -> 'luaL_getsubtable' 2011-04-08 16:17:36 -03:00
Roberto Ierusalimschy
c4ea0c3b29 detail (cleaning trailing spaces) 2011-01-26 14:30:02 -02:00
Roberto Ierusalimschy
8c21f463ed 'debug' library is loaded by default 2010-11-12 13:48:30 -02:00
Roberto Ierusalimschy
9e8e60dd5f bitlib renamed to 'bit32' + new function for arithmetic shift 2010-10-25 12:32:36 -02:00
Roberto Ierusalimschy
7192afafee new module policy: C modules do not create globals and do not register
themselves with 'require' (let 'require' do its work); new auxiliary
functions luaL_newlib/luaL_newlibtable/luaL_setfuncs/luaL_requiref.
Old luaL_register will be deprecated.
2010-07-02 08:38:13 -03:00
Roberto Ierusalimschy
a139e2e003 old (and complex) luaL_findtable now used only in compatibility code
inside lauxlib.c
2010-06-30 14:40:27 -03:00
Roberto Ierusalimschy
bd262d591f 'coroutine' library separated from 'baselib' 2010-06-10 18:30:26 -03:00
Roberto Ierusalimschy
e34d3c06b0 it is better to call open functions with lua_call to not mess
the caller stack
2010-05-20 09:57:59 -03:00
Roberto Ierusalimschy
064e406f67 no more fenvs! 2010-03-26 17:58:11 -03:00
Roberto Ierusalimschy
f84b575cfa no more pseudoindex LUA_GLOBALSINDEX; global table now accessible
through registry
2009-12-22 13:32:50 -02:00
Roberto Ierusalimschy
de6fc75d63 several configuration options that do not change often moved out of
luaconf.h and into more internal files
2009-12-17 10:26:09 -02:00
Roberto Ierusalimschy
2e51792596 avoid using deprecated macros lua_[gs]etglobal 2009-12-11 11:40:44 -02:00
Roberto Ierusalimschy
90e2a716c8 details + comments 2009-09-05 09:39:29 -03:00
Roberto Ierusalimschy
3abe3da9fb new module 'lbitlib.c' for bitwise operations 2009-07-01 13:16:40 -03:00
Roberto Ierusalimschy
0cc3add9f8 variable renaming: 'lualibs' -> 'loadedlibs'; 'luareqlibs' ->
'preloadedlibs'
2009-05-01 10:46:35 -03:00
Roberto Ierusalimschy
71c2eeff98 comments 2009-05-01 10:37:11 -03:00
Roberto Ierusalimschy
47b4858357 detail ('name' of baselib is "_G") 2008-01-02 14:16:28 -02:00
Roberto Ierusalimschy
3904a66ab0 'debug' library must be required before being used 2007-06-22 13:59:11 -03:00
Roberto Ierusalimschy
bfdcbbcd76 small optimizations (lua_newtable -> lua_createtable) 2005-12-29 14:23:32 -02:00
Roberto Ierusalimschy
3390f9a35a detail 2005-08-26 14:36:32 -03:00
Roberto Ierusalimschy
c7b4f44772 correct name to open package library 2005-08-10 15:06:58 -03:00
Roberto Ierusalimschy
04f657c7f8 new protocol to open standard libraries 2005-04-13 14:24:20 -03:00
Roberto Ierusalimschy
2d5b923759 details 2005-03-08 10:37:55 -03:00
Roberto Ierusalimschy
7d45a5f48f C functions and userdata also have environments 2005-02-18 10:40:02 -02:00
Roberto Ierusalimschy
ce455481ab separation between io lib and os lib 2004-07-09 12:47:48 -03:00
Roberto Ierusalimschy
31f6540fba back with an "open all libs" function 2004-07-09 11:29:29 -03:00
Roberto Ierusalimschy
fb55c96706 obsolete module; not part of the oficial distribution 2000-08-09 11:50:13 -03:00
Roberto Ierusalimschy
89a3ec08f3 function lua_userinit is used only in single-state mode (by lua.c) 2000-06-16 14:22:43 -03:00