Skip to main content

Module loadlib

Module loadlib 

Source
Expand description

Dynamic library loader for the Lua package library.

Ported from reference/lua-5.4.7/src/loadlib.c (758 lines, ~25 functions).

Provides require, package.loadlib, package.searchpath, and the four built-in module searchers (preload, Lua-file, C-library, C-root).

§Platform-specific dynamic loading

The three platform calls (lsys_load, lsys_sym, lsys_unloadlib) are dispatched through embedder hooks on lua_vm::state::GlobalState: dynlib_load_hook, dynlib_symbol_hook, dynlib_unload_hook. lua-cli installs a libloading-backed implementation; embeddings that omit the hooks behave like C-Lua’s fallback platform stub (LIB_FAIL = "absent").

Keeping the platform calls behind hooks lets lua-stdlib stay free of unsafe per PORTING.md §1; libloading lives entirely in lua-cli.

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.