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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
local function getDefaultSource()
return {
start = 0,
finish = 0,
uri = '',
}
end
local mt = {}
mt.__index = mt
mt.type = 'local'
mt._close = math.maxinteger
function mt:setValue(value)
if self.value then
self.value:mergeValue(value)
else
self.value = value
end
end
function mt:getValue()
return self.value
end
function mt:setInitValue(value)
self.initValue = value
end
function mt:getInitValue()
return self.initValue
end
function mt:addInfo(tp, source)
self[#self+1] = {
type = tp,
source = source,
}
end
function mt:eachInfo(callback)
for _, info in ipairs(self) do
local res = callback(info)
if res ~= nil then
return res
end
end
end
function mt:set(name, v)
if not self._flag then
self._flag = {}
end
self._flag[name] = v
end
function mt:get(name)
if not self._flag then
return nil
end
return self._flag[name]
end
function mt:getName()
return self.name
end
function mt:shadow(old)
if not old then
return self._shadow
end
local group = old._shadow
if not group then
group = {}
group[#group+1] = old
end
group[#group+1] = self
self._shadow = group
old:close(self.source.start - 1)
end
function mt:close(pos)
if pos then
self._close = pos
else
return self._close
end
end
return function (name, source, value)
if not value then
error('Local must has a value')
end
local self = setmetatable({
name = name,
source = source or getDefaultSource(),
value = value,
initValue = value,
}, mt)
return self
end
|