diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/collector.lua | 101 | ||||
-rw-r--r-- | script/core/searcher.lua | 2 |
2 files changed, 87 insertions, 16 deletions
diff --git a/script/core/collector.lua b/script/core/collector.lua index 45dae65f..43e584d5 100644 --- a/script/core/collector.lua +++ b/script/core/collector.lua @@ -60,35 +60,106 @@ end local DUMMY_FUNCTION = function () end ---- 迭代某个名字的订阅 ----@param uri uri ----@param name string -function m.each(uri, name) - local nameCollect = collect[name] - if not nameCollect then - return DUMMY_FUNCTION +---@param scp scope +local function eachOfFolder(nameCollect, scp) + local curi, value + + local function getNext() + curi, value = next(nameCollect, curi) + if not curi then + return nil, nil + end + if scp:isChildUri(curi) + or scp:isLinkedUri(curi) then + return value, curi + end + return getNext() end - ---@type scope - local scp = scope.getFolder(uri) - or scope.getLinkedScope(uri) - or scope.fallback + return getNext +end + +---@param scp scope +local function eachOfLinked(nameCollect, scp) local curi, value + local function getNext() curi, value = next(nameCollect, curi) if not curi then return nil, nil end - if not scp:isChildUri(curi) - and not scp:isLinkedUri(curi) then - return getNext() + if scp:isChildUri(curi) + and scp:isLinkedUri(curi) then + return value, curi end - return value, curi + local cscp = scope.getFolder(curi) + or scope.getLinkedScope(curi) + or scope.fallback + + if cscp == scp + or cscp:isChildUri(scp.uri) + or cscp:isLinkedUri(scp.uri) then + return value, curi + end + + return getNext() end + return getNext end +---@param scp scope +local function eachOfFallback(nameCollect, scp) + local curi, value + + local function getNext() + curi, value = next(nameCollect, curi) + if not curi then + return nil, nil + end + if scp:isLinkedUri(curi) then + return value, curi + end + + local cscp = scope.getFolder(curi) + or scope.getLinkedScope(curi) + or scope.fallback + + if cscp == scp then + return value, curi + end + + return getNext() + end + + return getNext +end + +--- 迭代某个名字的订阅 +---@param uri uri +---@param name string +function m.each(uri, name) + local nameCollect = collect[name] + if not nameCollect then + return DUMMY_FUNCTION + end + + local scp = scope.getFolder(uri) + + if scp then + return eachOfFolder(nameCollect, scp) + end + + scp = scope.getLinkedScope(uri) + + if scp then + return eachOfLinked(nameCollect, scp) + end + + return eachOfFallback(nameCollect, scope.fallback) +end + --- 迭代某个名字的引用订阅 ---@param uri uri ---@param name string diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 558dc96b..10f1d3db 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -27,7 +27,7 @@ local getUri = guide.getUri local getRoot = guide.getRoot local ceach = collector.each -local ceachref = collector.eachRef +local ceachref = collector.each local getState = files.getState |