blob: 49396b005f346811d7949b91665fa9a254beab50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
local guide = require 'parser.guide'
local searcher = require 'searcher.searcher'
local function eachGlobal(source, callback)
local root = guide.getRoot(source)
local env = root.locals[1]
searcher.eachField(env, callback)
end
function searcher.eachGlobal(source, callback)
local cache = searcher.cache.eachGlobal[source]
if cache then
for i = 1, #cache do
callback(cache[i])
end
return
end
local unlock = searcher.lock('eachGlobal', source)
if not unlock then
return
end
cache = {}
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])
end
end
|