summaryrefslogtreecommitdiff
path: root/server-beta/src/core/getindex.lua
blob: 28706589aad9d8c2e32103881ddc2a1bb7056d9b (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
38
39
40
41
42
43
44
45
46
local guide    = require 'parser.guide'
local checkSMT = require 'core.setmetatable'

local m = {}

function m:field(source, key, callback)
    local used = {}
    local found = false
    used[source] = true

    local node = source.node
    used[node] = true

    local myKey = guide.getKeyName(source)
    if key == myKey then
        callback(source.index, 'set')
    end

    self:eachField(node, key, function (src, mode)
        if used[src] then
            return
        end
        used[src] = true
        if mode == 'set' then
            callback(src, mode)
            found = true
        end
    end)

    self:eachValue(node, function (src)
        self:eachField(src, key, function (src, mode)
            if used[src] then
                return
            end
            used[src] = true
            if mode == 'set' then
                callback(src, mode)
                found = true
            end
        end)
    end)

    checkSMT(self, key, used, found, callback)
end

return m