summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/eachGlobal.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/searcher/eachGlobal.lua')
-rw-r--r--server-beta/src/searcher/eachGlobal.lua38
1 files changed, 30 insertions, 8 deletions
diff --git a/server-beta/src/searcher/eachGlobal.lua b/server-beta/src/searcher/eachGlobal.lua
index 49396b00..8f556976 100644
--- a/server-beta/src/searcher/eachGlobal.lua
+++ b/server-beta/src/searcher/eachGlobal.lua
@@ -4,14 +4,38 @@ local searcher = require 'searcher.searcher'
local function eachGlobal(source, callback)
local root = guide.getRoot(source)
local env = root.locals[1]
- searcher.eachField(env, callback)
+ local result = {}
+ local mark = {}
+ searcher.eachField(env, function (info)
+ local src = info.source
+ if mark[src] then
+ return
+ end
+ mark[src] = true
+ local name = info.key
+ if not result[name] then
+ result[name] = {
+ key = name,
+ mode = {},
+ }
+ end
+ result[name][#result[name]+1] = info
+ result[name].mode[info.mode] = true
+ end)
+ for _, info in pairs(result) do
+ callback(info)
+ end
end
function searcher.eachGlobal(source, callback)
+ source = guide.getRoot(source)
local cache = searcher.cache.eachGlobal[source]
if cache then
for i = 1, #cache do
- callback(cache[i])
+ local res = callback(cache[i])
+ if res ~= nil then
+ return res
+ end
end
return
end
@@ -23,15 +47,13 @@ function searcher.eachGlobal(source, callback)
searcher.cache.eachGlobal[source] = cache
local mark = {}
eachGlobal(source, function (info)
- local src = info.source
- if mark[src] then
- return
- end
- mark[src] = true
cache[#cache+1] = info
end)
unlock()
for i = 1, #cache do
- callback(cache[i])
+ local res = callback(cache[i])
+ if res ~= nil then
+ return res
+ end
end
end