1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- local lfs
- -- checks if lua file system is installed
- local using_lfs = pcall(function() lfs = require "lfs" end)
- -- switches to legacy module loading if lfs is not available
- if using_lfs then
- -- loads file names to ignore into a table
- function fetch_ignores(module_path)
- local ignore_list = {}
- -- checks if ignore.txt exists
- local f_test = io.open(module_path .. "/ignore.txt", "r")
- if not f_test then return {} end
-
- -- puts each line of ignore.txt into the table
- local f = io.lines(module_path .. "/ignore.txt")
- for line in f do
- table.insert(ignore_list, line)
- end
- return ignore_list
- end
- -- checks if a string is in a list
- function check_list(ignore_list, name)
- for i, v in ipairs(ignore_list) do
- if v == name then
- return true
- end
- end
- return false
- end
- modpol.load_modules = function(module_path)
- local loaded = 0
- local ignored = 0
- local ignores = fetch_ignores(module_path)
- for file in lfs.dir(module_path) do
- if file == "." or file == ".." then
- -- ignoring current and parent directory
- else
- -- only looks for .lua files
- if string.sub(file, -4, -1) == ".lua" then
-
- -- doesn't load files in the ignore.txt
- if check_list(ignores, file) then
- ignored = ignored + 1
- else
- dofile(module_path .. "/" .. file)
- loaded = loaded + 1
- end
- end
- end
- end
- print(loaded .. " modules loaded (" .. ignored .. " ignored)")
- end
- else
- dofile (modpol.topdir .. "/storage/store-modules-legacy.lua")
- end
|