summaryrefslogtreecommitdiff
path: root/server-beta/src/core/field.lua
blob: 997b38e3e45f48f3e7a62b7961b3438f5f971fef (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
local guide = require 'parser.guide'

local m = {}

function m:def(source, callback)
    local parent = source.parent
    if parent.type == 'setfield' or parent.type == 'getfield' then
        local node = parent.node
        local key = guide.getKeyName(source)
        self:eachField(node, key, function (src, mode)
            if mode == 'set' then
                callback(src, mode)
            end
        end)
    elseif parent.type == 'tablefield' then
        self:eachDef(parent.value, callback)
    end
end

function m:ref(source, callback)
    local parent = source.parent
    if parent.type == 'setfield' or parent.type == 'getfield' then
        local node = parent.node
        local key = guide.getKeyName(source)
        self:eachField(node, key, function (src, mode)
            if mode == 'set' or mode == 'get' then
                callback(src, mode)
            end
        end)
    elseif parent.type == 'tablefield' then
        self:eachDef(parent.value, callback)
    end
end

function m:value(source, callback)
    local parent = source.parent
    if parent.type == 'setfield'
    or parent.type == 'tablefield' then
        if parent.value then
            self:eachValue(parent.value, callback)
        end
    end
end

return m