Skip to content

Commit abf3262

Browse files
author
Robert McLay
committed
Issue #797: Adding support for new MRC commands hideRegex and forbidRegex
1 parent 9489913 commit abf3262

File tree

7 files changed

+83
-21
lines changed

7 files changed

+83
-21
lines changed

rt/modulerc/lmodrc_797.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
forbidRegex{name="[Gg]pu%-app.*"}

rt/modulerc/mfH/Core/AA/1.0.lua

Whitespace-only changes.

rt/modulerc/mfH/Core/BB/2.0.lua

Whitespace-only changes.

rt/modulerc/mfH/Core/BB/3.0.lua

Whitespace-only changes.

rt/modulerc/mfH/Core/Gpu-app/2.0.lua

Whitespace-only changes.

rt/modulerc/mfH/Core/gpu-app/4.0.lua

Whitespace-only changes.

src/MRC.lua

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,13 @@ function M.parseModA(self, modA, weight)
269269
elseif (entry.action == "hide") then
270270
self.__hiddenT[entry.name] = entry
271271
elseif (entry.action == "hideRegex") then
272+
entry.action = "hide"
272273
self.__hiddenRxT[entry.name] = entry
273274
elseif (entry.action == "forbid") then
274275
self.__forbiddenT[entry.name] = entry
275276
elseif (entry.action == "forbidRegex") then
277+
dbg.print{"action: ", entry.action,", name: ",entry.name,"\n"}
278+
entry.action = "forbid"
276279
self.__forbiddenRxT[entry.name] = entry
277280
end
278281
until true
@@ -527,47 +530,103 @@ function M.export(self)
527530
end
528531

529532
local function l_find_resultT(self, tbl_kind, tbl_kindRx, replaceT, mpath, wantedA)
530-
dbg.start{"MRC:l_find_resultT( tbl_kind, replaceT, mpath, wantedA)"}
533+
dbg.start{"MRC:l_find_resultT( tbl_kind: ",tbl_kind,", tbl_kindRx, replaceT, mpath, wantedA)"}
531534
local resultT = false
532-
local Tkind = "__" .. tbl_kind
533-
local tt = {}
534-
local ttt = self[Tkind] or {}
535-
536-
-- Add code here to search both hash table key lookup and Regex matching to keys
535+
local mpathA = {mpath}
537536

537+
----------------------------------------------------------------------
538+
-- Check non-regex names first
539+
----------------------------------------------------------------------
538540

541+
local modTreeMRCT = {}
542+
local lmodMRCT = self["__" .. tbl_kind] or {}
539543

540544
if (self.__mpathT[mpath] and self.__mpathT[mpath][tbl_kind]) then
541-
tt = self.__mpathT[mpath][tbl_kind]
545+
modTreeMRCT = self.__mpathT[mpath][tbl_kind]
542546
end
543-
dbg.print{"mpath: ",mpath,"\n"}
544-
dbg.printT("wantedA",wantedA)
545-
dbg.printT("ttt", ttt)
546-
dbg.printT("tt", tt)
547-
dbg.printT("mpathT", self.__mpathT)
548547

549-
local mpathA = {mpath}
548+
dbg.print{"mpath: ", mpath,"\n"}
549+
dbg.printT("wantedA", wantedA)
550+
dbg.printT("lmodMRCT[".."__" .. tbl_kind .. "]", lmodMRCT)
551+
dbg.printT("modTreeMRCT", modTreeMRCT)
552+
dbg.printT("mpathT", self.__mpathT)
553+
550554
for i = 1,#wantedA do
551555
local wanted = wantedA[i]
552556
local key = self:resolve(mpathA, wanted)
553-
local ans = ttt[key] or tt[key]
557+
local ans = lmodMRCT[key] or modTreeMRCT[key]
554558
if (ans) then
555559
if (type(ans) == "table") then
556560
resultT = ans
557561
else
558562
resultT = replaceT
559563
end
560564
dbg.printT("resultT",resultT)
561-
dbg.fini("MRC:l_find_resultT")
565+
dbg.fini("MRC:l_find_resultT via non-regex match")
562566
return resultT
563-
else
564-
567+
end
568+
end
569+
570+
----------------------------------------------------------------------
571+
-- Check regex names
572+
----------------------------------------------------------------------
573+
574+
575+
lmodMRCT = self["__" .. tbl_kindRx] or {}
576+
dbg.printT("lmodMRCT[".."__" .. tbl_kindRx .. "]",lmodMRCT)
577+
if (next(lmodMRCT) == nil) then
578+
dbg.print{"lmodMRCT has zero keys\n"}
579+
end
580+
for k, ans in pairs(lmodMRCT) do
581+
dbg.print{"lmodMRCT: k: ",k,"\n"}
582+
for i = 1,#wantedA do
583+
local wanted = wantedA[i]
584+
local key = self:resolve(mpathA, wanted)
585+
dbg.print{"lmodMRCT: key: ",key,", wanted: ",wanted,"\n"}
586+
if (key:find(k)) then
587+
if (type(ans) == "table") then
588+
resultT = ans
589+
else
590+
resultT = replaceT
591+
end
592+
dbg.printT("resultT",resultT)
593+
dbg.fini("MRC:l_find_resultT via regex match from RTMlmodMRCT")
594+
595+
return resultT
596+
end
597+
end
598+
end
599+
600+
modTreeMRCT = {}
601+
if (self.__mpathT[mpath] and self.__mpathT[mpath][tbl_kindRx]) then
602+
modTreeMRCT = self.__mpathT[mpath][tbl_kindRx]
603+
end
604+
dbg.printT("modTreeMRCT",modTreeMRCT)
605+
for k, ans in pairs(modTreeMRCT) do
606+
dbg.print{"modTreeMRCT: k: ",k,"\n"}
607+
for i = 1,#wantedA do
608+
local wanted = wantedA[i]
609+
local key = self:resolve(mpathA, wanted)
610+
dbg.print{"modTreeMRCT: key: ",key,", wanted: ",wanted,"\n"}
611+
612+
if (key:find(k)) then
613+
if (type(ans) == "table") then
614+
resultT = ans
615+
else
616+
resultT = replaceT
617+
end
618+
dbg.printT("resultT",resultT)
619+
dbg.fini("MRC:l_find_resultT via regex match from modTreeMRCT")
620+
return resultT
621+
end
565622
end
566623
end
567624
dbg.fini("MRC:l_find_resultT (false)")
568625
return resultT
569626
end
570627

628+
629+
571630
local function l_findHiddenState(self, modT)
572631
--dbg.start{"l_findHiddenState(self, modT)"}
573632
local fn = modT.fn
@@ -798,7 +857,7 @@ function M.isVisible(self, modT)
798857
end
799858

800859
function M.isForbidden(self, modT)
801-
--dbg.start{"MRC:isForbidden(modT}"}
860+
dbg.start{"MRC:isForbidden(modT}"}
802861
local frameStk = require("FrameStk"):singleton()
803862
local mname = frameStk:mname()
804863
local mt = frameStk:mt()
@@ -812,10 +871,11 @@ function M.isForbidden(self, modT)
812871
local resultT = l_findForbiddenState(self, mpath, sn, fullName, fn)
813872

814873
--dbg.print{"fullName: ",fullName,"\n"}
815-
--dbg.printT("resultT",resultT)
874+
dbg.printT("resultT",resultT)
816875

876+
--if (resultT.action ~= "forbid" and resultT.action ~= "forbidRegex") then
817877
if (resultT.action ~= "forbid") then
818-
--dbg.fini("MRC:isForbidden")
878+
dbg.fini("MRC:isForbidden")
819879
return nil
820880
end
821881

@@ -831,7 +891,8 @@ function M.isForbidden(self, modT)
831891
local my_resultT = {forbiddenState = modT.forbiddenState, message = modT.message,
832892
nearlymessage = modT.nearlymessage, after = resultT.after}
833893

834-
--dbg.fini("MRC:isForbidden")
894+
dbg.printT("my_resultT",my_resultT)
895+
dbg.fini("MRC:isForbidden")
835896
return my_resultT
836897
end
837898

0 commit comments

Comments
 (0)