blob: deaea8ba4202951015c5c89887042b829afd2ded (
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
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
|
---@class file
local mt = {}
mt.__index = mt
mt.type = 'file'
mt._uri = ''
mt._text = ''
mt._version = -1
---@param buf string
function mt:setText(buf)
self._text = buf
end
---@return string
function mt:getText()
return self._text
end
---@param version integer
function mt:setVersion(version)
self._version = version
end
---@return integer
function mt:getVersion()
return self._version
end
function mt:remove()
if self._removed then
return
end
self._removed = true
self._text = nil
self._version = nil
if self._vm then
self._vm:remove()
end
end
---@param vm VM
function mt:saveVM(vm)
self._vm = vm
end
---@return VM
function mt:getVM()
return self._vm
end
function mt:removeVM()
if not self._vm then
return
end
self._vm:remove()
self._vm = nil
end
---@return file
function mt:getParent()
return self._parent
end
---@param uri uri
function mt:removeChild(uri)
self._child[uri] = nil
end
---@param uri uri
function mt:removeParent(uri)
self._parent[uri] = nil
end
function mt:eachChild()
return pairs(self._child)
end
function mt:eachParent()
return pairs(self._parent)
end
---@param uri string
return function (uri)
local self = setmetatable({
_uri = uri,
_parent = {},
_child = {},
}, mt)
return self
end
|