diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-15 15:50:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-15 15:50:39 +0800 |
commit | 9aaf4607376e11a35fe04ef86baa3c18a9d90864 (patch) | |
tree | f0e9e025de033dc01e7f76b406d6ae0af7a9fbc7 /server/src/vm | |
parent | f65de4fabbe2b8b1a66a13661adc26f9b93f5d80 (diff) | |
download | lua-language-server-9aaf4607376e11a35fe04ef86baa3c18a9d90864.zip |
解除死掉的全局变量引用
Diffstat (limited to 'server/src/vm')
-rw-r--r-- | server/src/vm/global.lua | 1 | ||||
-rw-r--r-- | server/src/vm/value.lua | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua index dea30525..99f05e37 100644 --- a/server/src/vm/global.lua +++ b/server/src/vm/global.lua @@ -12,6 +12,7 @@ return function (lsp) end global = t._G + global:set('_G', true) for k, v in pairs(t) do global:setChild(k, v) end diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 60f0c663..67b4536c 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -38,6 +38,19 @@ local function create (tp, source, literal) return self end +local function isDeadGlobalChild(value) + if value._lib then + return false + end + for srcId in pairs(value._info) do + local src = sourceMgr.list[srcId] + if src then + return false + end + end + return true +end + function mt:setType(tp, rate) if type(tp) == 'table' then for _, ctp in ipairs(tp) do @@ -92,6 +105,12 @@ function mt:rawGet(index) if not child then return nil end + if self:get '_G' then + if isDeadGlobalChild(child) then + self._child[index] = nil + return nil + end + end return child end @@ -182,6 +201,10 @@ function mt:rawEach(callback, foundIndex) end foundIndex[index] = true end + if self:get '_G' and isDeadGlobalChild(value) then + self._child[index] = nil + goto CONTINUE + end local res = callback(index, value) if res ~= nil then return res |