lua: don't set built-in modules to package.loaded
It is necessary to implement overloading of a built-in module by an external one. `require('foo')` will work this way: check for `override.foo` module on the file system and then load built-in `foo`. If `foo` is already assigned to `package.loaded`, the loaders will not be called at all, so we can't check the file system. This commit changes a built-in module registration process: the modules are assigned into another table called `loaders.builtin`. A special loader is added to `package.loaders` to look into this table. Comments on the luajit-test-init.lua changes: * The LuaJIT tests use its own tap module, so the script unloads the built-in tap module. However, now it is not enough to remove it from `package.loaded` (it'll be loaded again at next require()). It should also be removed from `loaders.builtin`. Maybe it would be better to move this external tap module to <...>/override/tap.lua in a future. * `package.loaded` may miss `internal.print` and `internal.pairs` if they were not required. The right way to obtain the modules is to require() them. Part of #7774 NO_TEST=no user visible changes NO_CHANGELOG=see NO_TEST NO_DOC=see NO_TEST
Showing
- src/lua/init.c 7 additions, 0 deletionssrc/lua/init.c
- src/lua/loaders.lua 70 additions, 0 deletionssrc/lua/loaders.lua
- src/lua/minifio.c 7 additions, 1 deletionsrc/lua/minifio.c
- src/lua/utils.c 9 additions, 9 deletionssrc/lua/utils.c
- src/lua/utils.h 5 additions, 5 deletionssrc/lua/utils.h
- test/luajit-test-init.lua 11 additions, 12 deletionstest/luajit-test-init.lua
- test/unit/luaT_tuple_new.c 2 additions, 2 deletionstest/unit/luaT_tuple_new.c
- test/unit/lua_msgpack.c 3 additions, 2 deletionstest/unit/lua_msgpack.c
- test/unit/lua_test_utils.h 36 additions, 0 deletionstest/unit/lua_test_utils.h
- test/unit/lua_tweaks.c 24 additions, 2 deletionstest/unit/lua_tweaks.c
Loading
Please register or sign in to comment