feat(loader)!: implement glob pattern matching for module discovery
Replace simple prefix matching with full glob pattern support for discovering root folders. Changes: - Add EscapePattern() to escape Lua magic characters - Add GlobToPattern() to convert glob patterns (e.g., "bladw_*") to Lua regex patterns - Refactor FindRootFolders() to support: • Exact matches without wildcards (e.g., "bladw_announcement") • Glob patterns with * in prefix/suffix/middle positions - Update default config root from "bladw_*" to "bladw_announcement" - Improve documentation with usage examples - Add new announcement module with client, server, and shared files - Update rndx.lua library (formatting/whitespace changes) BREAKING CHANGE: The root config now expects exact folder names or glob patterns instead of simple prefixes. Existing configs using "bladw_*" will still work but the matching behavior changes from prefix-only to glob-based pattern matching.
This commit is contained in:
5 files changed
+752
-707
No files matched your search
@@ -6,8 +6,11 @@
|
||||
local MURA = {}
|
||||
|
||||
MURA.config = {
|
||||
-- Préfixe des dossiers-modules à charger (le * final est un wildcard).
|
||||
root = "bladw_*",
|
||||
-- Dossier(s)-module(s) à charger.
|
||||
-- • sans wildcard -> nom exact d'UN dossier : "bladw_announcement"
|
||||
-- • avec wildcard -> glob, charge TOUS ceux qui matchent :
|
||||
-- "bladw_*" (préfixe) / "*_menu" (suffixe) / "bladw_*_v2" (milieu)
|
||||
root = "bladw_announcement",
|
||||
-- Dossiers de bibliothèques : seulement envoyés au client (AddCSLuaFile),
|
||||
-- jamais auto-inclus. Ils sont chargés à la demande via include("lib/...").
|
||||
libs = { "lib" },
|
||||
@@ -220,20 +223,40 @@ local function SendFolder(dir)
|
||||
end
|
||||
|
||||
-- ============================================================
|
||||
-- Découverte des dossiers-modules correspondant au préfixe
|
||||
-- Découverte des dossiers-modules
|
||||
-- (file.Find ne supporte le wildcard que sur le dernier segment,
|
||||
-- donc on liste la racine lua/ puis on filtre par préfixe.)
|
||||
-- donc on liste la racine lua/ puis on filtre nous-mêmes.)
|
||||
-- • pattern sans "*" -> match exact (un seul dossier)
|
||||
-- • pattern avec "*" -> glob converti en motif Lua (préfixe/suffixe/milieu)
|
||||
-- ============================================================
|
||||
|
||||
--- Échappe les caractères magiques d'un motif Lua.
|
||||
local function EscapePattern(s)
|
||||
return (s:gsub("([%(%)%.%%%+%-%*%?%[%]%^%$])", "%%%1"))
|
||||
end
|
||||
|
||||
--- Transforme un glob simple ("bladw_*") en motif Lua ancré ("^bladw_.*$").
|
||||
local function GlobToPattern(glob)
|
||||
return "^" .. EscapePattern(glob):gsub("%%%*", ".*") .. "$"
|
||||
end
|
||||
|
||||
local function FindRootFolders(pattern)
|
||||
local prefix = pattern:gsub("%*+$", "") -- "bladw_*" -> "bladw_"
|
||||
local roots = {}
|
||||
local roots = {}
|
||||
|
||||
-- Construit la fonction de test selon la présence ou non d'un wildcard.
|
||||
local matches
|
||||
if pattern:find("*", 1, true) then
|
||||
local lua_pat = GlobToPattern(pattern)
|
||||
matches = function(d) return d:match(lua_pat) ~= nil end
|
||||
else
|
||||
matches = function(d) return d == pattern end
|
||||
end
|
||||
|
||||
local _, dirs1 = file.Find("*", "LUA")
|
||||
local _, dirs2 = file.Find("lua/*", "GAME")
|
||||
|
||||
for _, d in ipairs(Merge(dirs1, dirs2)) do
|
||||
if StartsWith(d, prefix) and not IsExcluded(d) then
|
||||
if matches(d) and not IsExcluded(d) then
|
||||
table.insert(roots, d)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user