Expand description
The Lua package library: require, package.loadlib,
package.searchpath, and the four built-in module searchers (preload,
Lua-file, C-library, C-root).
§Graduation (Idiomatization Sprint 2 / Phase 2 — cold, platform-FFI module)
Split cleanly into two regimes, and treated as such:
- Deterministic pure-Lua package logic — now guarded by
tests/loadlib_strengthen.rs(16 reference-pinned cross-version assertions). Strengthening that net FIRST caught seven divergences our weaker net hid: the 5.1package.configtrailing newline,require’s 5.4+ 2nd return value, the 5.1 preload-loader arg count, a C-root searcher message truncation, thenil-vs-falseluaL_pushfailvalue, the 5.1 absence ofpackage.searchpath, and the 5.2/5.3 searchpath-error leading separator. All were fixed via single-source version helpers; the version gates are explicit and load-bearing. SeeGRADUATED.md“loadlib”. - Platform / dynamic-loading FFI — left LOAD-BEARING and untouched. The
three platform calls (
lsys_load,lsys_sym,lsys_unloadlib) dispatch through embedder hooks onlua_vm::state::GlobalState(dynlib_load_hook,dynlib_symbol_hook,dynlib_unload_hook);lua-cliinstalls alibloading-backed (genuinelyunsafe) implementation, while embeddings that omit the hooks behave like C-Lua’s fallback stub (LIB_FAIL = "absent"). This indirection keepslua-stdlibitselfunsafe-free (unsafe_code = "forbid"); the real FFI bridge lives inlua-cli. Its behavior — the dlopen/dlsym path, the platform error strings, the"open"/"absent"/"init"tags — needs a real shared object and host loader, so it is NOT reference-pinnable and is a documented honest-negative (the analogue of math’s platformrand()).
Functions§
- ll_
loadlib package.loadlib(filename, funcname)— open a C library and return a Lua-callable wrapper forfuncname.- ll_
require require(modname)— load a module by name, usingpackage.loadedas a cache andpackage.searchersto find and load it if not already cached.- ll_
searchpath package.searchpath(name, path [, sep [, rep]]).- luaopen_
package - Open the
packagelibrary and return thepackagetable.