From 9aaf4607376e11a35fe04ef86baa3c18a9d90864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 15 Mar 2019 15:50:39 +0800 Subject: =?UTF-8?q?=E8=A7=A3=E9=99=A4=E6=AD=BB=E6=8E=89=E7=9A=84=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E5=8F=98=E9=87=8F=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/vm/global.lua | 1 + server/src/vm/value.lua | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'server/src/vm') 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 -- cgit v1.2.3