feat(ext): add extension discovery and loading

Extension discovery (plan todo 20): scans --ext-dir dirs,
STUPIDTOOLS_EXT, the XDG user dir and a builtin-ext dir for *.lua
modules, runs each in the sandboxed Lua runtime, and enumerates its
registrations; the builtin C/C++ modules load first via
st_ext_init_builtins. Fail-fast with an error naming file and line on
any malformed/sandbox-violating module.

The CLI gains a repeatable --ext-dir flag; with flag or env present
main.c runs discovery and prints 'loaded extension: ...' lines from
actual registrations (interim wiring until todo 23).

Note: src/Makefile.am gained the ext + vendored Lua sources because
the binary otherwise cannot link discovery -- required for the
root-verifiable CLI acceptance.
This commit is contained in:
2026-08-28 21:17:05 -04:00
parent 88d78990d5
commit 783019dff4
8 changed files with 1286 additions and 2 deletions
+8
View File
@@ -17,6 +17,9 @@
#define CLI_EXIT_RUNTIME 1
#define CLI_EXIT_USAGE 2
/* Sane cap on repeated --ext-dir flags (todo 20). */
#define CLI_MAX_EXT_DIRS 32
/* What the caller should do after parsing argv. */
enum cli_action {
CLI_ACTION_RUN, /* proceed with the parsed buildfile (todo 16+) */
@@ -28,6 +31,11 @@ enum cli_action {
struct cli_opts {
const char *program; /* argv[0] as given (or a default) */
const char *buildfile; /* single positional buildfile, NULL if none */
/* --ext-dir values, in the order given; the pointers are borrowed
* from argv. STUPIDTOOLS_EXT is NOT merged here -- discovery reads
* the environment itself and appends those dirs after these. */
const char *ext_dirs[CLI_MAX_EXT_DIRS];
size_t ext_dir_count;
};
enum cli_action cli_parse(int argc, char **argv, struct cli_opts *opts);