Design flaws + future rewrite
[searchers/loaders](https://www.lua.org/manual/5.1/manual.html#pdf-package.loaders) cannot return a loader that `require` itself (require loop), which makes it impossible to run the lz.n loader and `after` hooks properly.
A `require` wrapper like this might work:
```lua
function require(modname)
local mod, err = old_require(modname)
if err == nil then return mod end
if err ~= 'module not found ...' then return err end
pack_name, dir = search_in_opt(modname)
if pack_name == nil then return err end
hook_before()
-- assuming lz.n is using the default loader (packadd)
require('lz.n').trigger_load(pack_name)
hook_after()
end
```
worth investigating is lz.n Handlers, haven't had time to dig into those but might help?
关闭于 2024-11-07 0 条评论