Skip to content
Snippets Groups Projects
user avatar
Alexander Turenko authored
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
7e9051c4
History
Name Last commit Last update