summaryrefslogtreecommitdiff
path: root/server-beta/src/core/setfield.lua
blob: bf18842ddf8f281534779d3b735c7d4272e11350 (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
47
48
49
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

    callback(source.field, 'set')
    local myKey = guide.getKeyName(source)
    self:eachField(node, myKey, function (src, mode)
        if used[src] then
            return
        end
        used[src] = true
        self:eachField(src, key, function (src, mode)
            used[src] = true
            if mode == 'set' then
                callback(src, mode)
                found = true
            end
        end)
    end)

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

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

return m