require module with non-existant modulepath results in infinite loop
PatrickDahlin opened this issue · 1 comments
PatrickDahlin commented
When using a structure as following:
src/
main.lua
Then running luvit on src/main.lua where we create a module for "Test" using the generator, any following require just causes an infinite loop to occur.
Example main.lua:
local generator = require('require')
local myRequire, myModule = generator("Test")
myRequire("file1")
Looking into it, it seems that require.lua:190 tries to step up one level in the directory-hierarchy, while base path is an empty string, which results in the same empty path string.
-- Otherwise, keep going higher
base = pathJoin(base, "..")
I guess this case should be accounted for explicitly
squeek502 commented
Luvit's require is fairly coupled to how Luvi works I believe. Here's how require
gets autoloaded from within Luvi:
-- Auto-register the require system if present
local mainRequire
local stat = bundle.stat("deps/require.lua")
if stat and stat.type == "file" then
bundle.register('require', "deps/require.lua")
mainRequire = require('require')("bundle:main.lua")
end