25 lines
1 KiB
Lua
25 lines
1 KiB
Lua
|
local context = debug and debug.getinfo(1, "S").source:match("mods[/\\][/\\]?([^/]*)") or error("They broke debug!")
|
||
|
local DIR_DELIM = debug.getinfo(1, "S").source:match("[\\/]")
|
||
|
|
||
|
_G[context] = _G[context] or {}
|
||
|
_G[context].init = function (path, patern)
|
||
|
path = path or "/src/"
|
||
|
patern = patern or "%.lua$"
|
||
|
local MOD_NAME =minetest.get_current_modname()
|
||
|
local MOD_PATH=minetest.get_modpath(MOD_NAME)
|
||
|
--Crate a array (of type table) of all files in the MOD_PATH
|
||
|
local files = minetest.get_dir_list(MOD_PATH .. DIR_DELIM .. path)
|
||
|
--Shuffle array to randomize load order and encurage stable coding practices, you know cause slow is good?
|
||
|
table.shuffle(files)
|
||
|
-- Process each filename using ipairs
|
||
|
for _, filename in ipairs(files) do
|
||
|
-- Check that the string ends with ".lua" and is not the init.lua file
|
||
|
if filename:match(patern) and filename ~= 'init.lua'then
|
||
|
--do the thing
|
||
|
dofile(MOD_PATH .. DIR_DELIM .. path .. DIR_DELIM .. filename)
|
||
|
--print logs for debuging ~~purposes~~
|
||
|
--minetest.log(filename)
|
||
|
end
|
||
|
end
|
||
|
end
|