summaryrefslogtreecommitdiff
path: root/script-beta/vm/eachRef.lua
blob: c5d3c8455efff540b5c9e55c6c33dd1ea6dd8eb8 (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
local vm    = require 'vm.vm'
local guide = require 'parser.guide'

local function eachRef(source)
    local results = guide.requestReference(source)
    return results
end

function vm.eachRef(source, callback)
    local cache = vm.cache.eachRef[source]
    if cache ~= nil then
        for i = 1, #cache do
            callback(cache[i])
        end
        return
    end
    local unlock = vm.lock('eachRef', source)
    if not unlock then
        return
    end
    cache = eachRef(source) or false
    vm.cache.eachRef[source] = cache
    unlock()
    for i = 1, #cache do
        callback(cache[i])
    end
end