fix: support adding top-level lua directories

This commit is contained in:
Folke Lemaitre 2022-11-22 22:27:29 +01:00
parent fca984b18c
commit 72889623af
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 9 additions and 2 deletions

View file

@ -58,11 +58,11 @@ local function _add_module(dir, modname)
for _, entry in ipairs(entries) do
local path = dir .. "/" .. entry.name
if entry.type == "directory" then
_add_module(path, modname .. "." .. entry.name)
_add_module(path, modname and (modname .. "." .. entry.name) or entry.name)
else
local childname = entry.name:match("^(.*)%.lua$")
if childname then
local child = entry.name == "init.lua" and modname or (modname .. "." .. childname)
local child = entry.name == "init.lua" and modname or modname and (modname .. "." .. childname) or childname
if child then
M.add(child, path)
end
@ -76,6 +76,9 @@ local function _add_module(dir, modname)
end
function M.add_module(path)
if path:find("/lua/?$") then
return _add_module(path)
end
---@type string
local modname = path:match("/lua/(.*)/?")
assert(modname)