diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 23:26:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 23:26:32 +0800 |
commit | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (patch) | |
tree | bb34518d70b85de7656dbdbe958dfa221a3ff3b3 /script/src/vm/label.lua | |
parent | 0a2c2ad15e1ec359171fb0dd4c72e57c5b66e9ba (diff) | |
download | lua-language-server-d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a.zip |
整理一下目录结构
Diffstat (limited to 'script/src/vm/label.lua')
-rw-r--r-- | script/src/vm/label.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/script/src/vm/label.lua b/script/src/vm/label.lua new file mode 100644 index 00000000..c0e0dfb8 --- /dev/null +++ b/script/src/vm/label.lua @@ -0,0 +1,75 @@ +local listMgr = require 'vm.list' + +local Sort = 0 + +local mt = {} +mt.__index = mt +mt.type = 'label' + +function mt:getName() + return self.name +end + +function mt:addInfo(tp, source) + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') + end + if self._info[id] then + return + end + Sort = Sort + 1 + local info = { + type = tp, + source = id, + _sort = Sort, + } + + self._info[id] = info +end + +function mt:eachInfo(callback) + local list = {} + for srcId, info in pairs(self._info) do + local src = listMgr.get(srcId) + if src then + list[#list+1] = info + else + self._info[srcId] = nil + end + end + table.sort(list, function (a, b) + return a._sort < b._sort + end) + for i = 1, #list do + local info = list[i] + local res = callback(info, listMgr.get(info.source)) + if res ~= nil then + return res + end + end + return nil +end + +function mt:getSource() + return listMgr.get(self.source) +end + +return function (name, source) + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') + end + local self = setmetatable({ + name = name, + source = id, + _info = {}, + }, mt) + return self +end |