lua: search modules next to the main script
It eliminates a need to call `package.setsearchroot()` in the main script to find modules in the application's directory. Such layout is typical for cartridge based applications. It it also used, when different versions of modules are in use in different applications and installing the modules into the system is not an option. Regarding the implementation. There are two possible ways to add more searching logic: add more entries into `package.path` and `package.cpath` or add/wrap a loader. I'm going the second way, because we already have a logic around .rocks and override modules implemented as loaders. It is easier to follow. However, I would reimplement all those loaders as paths generators for `package.path` and `package.cpath` in a future. See also #3136. Follows up #7774 Fixes #8182 @TarantoolBot document Title: Default module search paths now include the main script directory Let's assume that there is an application in the directory /path/to/myapp with modules inside: ``` + /path/to/myapp/ +- .rocks/share/tarantool/ +- foo.lua +- init.lua +- myapp/ +- bar.lua ``` Now the following command automatically adds the path to the main script directory to search paths for modules: ```sh $ tarantool /path/to/app/init.lua ``` So `require('foo')` and `require('myapp.bar')` works without any additional work.
Showing
- changelogs/unreleased/gh-8182-module-search-next-to-script.md 3 additions, 0 deletions...gelogs/unreleased/gh-8182-module-search-next-to-script.md
- src/lua/loaders.lua 56 additions, 0 deletionssrc/lua/loaders.lua
- test/app-luatest/module_search_test.lua 94 additions, 0 deletionstest/app-luatest/module_search_test.lua
test/app-luatest/module_search_test.lua
0 → 100644
Please register or sign in to comment