blob: b82e98e89a9a6b0e53b772dc2b5d964abff553f5 (
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
|
local function getDefaultSource()
return {
start = 0,
finish = 0,
uri = '',
}
end
local mt = {}
mt.__index = mt
mt.type = 'label'
function mt:getName()
return self.name
end
function mt:addInfo(tp, source)
if source and not source.start then
error('Miss start: ' .. table.dump(source))
end
self[#self+1] = {
type = tp,
source = source or getDefaultSource(),
}
end
function mt:eachInfo(callback)
for _, info in ipairs(self) do
local res = callback(info)
if res ~= nil then
return res
end
end
return nil
end
return function (name, source)
local self = setmetatable({
name = name,
source = source,
}, mt)
return self
end
|