summaryrefslogtreecommitdiff
path: root/script/vm/getGlobals.lua
blob: f32a84b160eddd032194f26bf1040ff8415db9ae (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
local collector = require 'core.collector'
---@type vm
local vm        = require 'vm.vm'
local noder     = require 'core.noder'

function vm.hasGlobalSets(name)
    local id = ('def:g:%q'):format(name)
    return collector.has(id)
end

function vm.getGlobalSets(name)
    local cache = vm.getCache 'getGlobalSets'
    if cache[name] then
        return cache[name]
    end
    local results = {}
    cache[name] = results
    local id
    if name == '*' then
        id = 'def:g:'
    else
        id = ('def:g:%q'):format(name)
    end
    for node in collector.each(id) do
        noder.eachSource(node, function (source)
            results[#results+1] = source
        end)
    end
    return results
end