Skip to content
Snippets Groups Projects
user avatar
Alexander Turenko authored
There are built-in Lua modules written in Lua in src/lua and src/box/lua
directories. Surprisingly, they are loaded in a slightly different ways.

The src/lua/*.lua modules return a module table, which is written into
`package.loaded` by the loading mechanism. This approach is usual for
external modules as well. The src/box/lua/*.lua modules write themselves
into `package.loaded` on its own.

This commit modifies the box modules loading function to store the
return values from box's built-in modules in `package.loaded` if the
module name is provided in the `lua_sources` registry.

The next commit will replace `package.loaded` assignments with
returning module tables.

The motivation behind this change is not only to make the modules
structure more natural for a Lua developer, but also concentrate
`package.loaded` assignments in a few common places. Those places will
be changes to implement modules overriding in future commits. Direct
`package.loaded` assignments would prevent ability to override a
built-in module by an external one.

The change also makes the ways to load src/lua and src/box/lua modules
closer. Now it is easier to coalesce corresponding code. It is not done
in this patchset, but can be done later to simplify the code.

This commit is pure refactoring change and it doesn't change how the
`getsources()` debugging function works. It is to be fixed separately.
See the comment in the code.

Part of #7774

NO_TEST=no user visible changes
NO_CHANGELOG=see NO_TEST
NO_DOC=see NO_TEST
5e71958e
History
Name Last commit Last update