Files
Astrobox/lua/astrobox/utils.lua
Niverton b4d05200d3 Now standalone plugin
First impl of standalone colorscheme
2023-12-09 23:20:15 +01:00

37 lines
1.1 KiB
Lua

local function get_module_root_path(modname)
local list = vim.loader.find(modname)
if list and #list then
return list[1].modpath:sub(0, -9) -- Cut init.lua
end
end
ASTROBOX_ROOT_PATH = get_module_root_path("astrobox")
local M = {}
function M.visit_astrobox_modules(module, visitor)
local modpath = ASTROBOX_ROOT_PATH .. module:gsub("%.", "/")
local hdl, err, msg = vim.loop.fs_scandir(modpath)
if hdl == nil then
print("Astrobox err: " .. err .. " " .. vim.inspect(msg))
return
end
while true do
local entry, type = vim.loop.fs_scandir_next(hdl)
if entry == nil then
break
end
if type == "file" and vim.endswith(entry, ".lua") then
local mod_name = entry:sub(0, -5) -- cut extension
local ok, mod = pcall(require, "astrobox." .. module .. "." .. mod_name)
if ok then
visitor(mod, mod_name)
else
print("AstroBox:Failed to load module " .. mod_name)
end
end
end
end
return M