Skip to main content

Module loadlib

Module loadlib 

Source
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.1 package.config trailing newline, require’s 5.4+ 2nd return value, the 5.1 preload-loader arg count, a C-root searcher message truncation, the nil-vs-false luaL_pushfail value, the 5.1 absence of package.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. See GRADUATED.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 on lua_vm::state::GlobalState (dynlib_load_hook, dynlib_symbol_hook, dynlib_unload_hook); lua-cli installs a libloading-backed (genuinely unsafe) implementation, while embeddings that omit the hooks behave like C-Lua’s fallback stub (LIB_FAIL = "absent"). This indirection keeps lua-stdlib itself unsafe-free (unsafe_code = "forbid"); the real FFI bridge lives in lua-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 platform rand()).

Functions§

ll_loadlib
package.loadlib(filename, funcname) — open a C library and return a Lua-callable wrapper for funcname.
ll_require
require(modname) — load a module by name, using package.loaded as a cache and package.searchers to find and load it if not already cached.
ll_searchpath
package.searchpath(name, path [, sep [, rep]]).
luaopen_package
Open the package library and return the package table.