From 0d1a38eb45e67c5e724cba354ca673344d69b4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sun, 10 Nov 2019 19:27:19 +0800 Subject: =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/searcher/eachGlobal.lua | 1 + server-beta/src/searcher/getLibrary.lua | 29 +++-------------------------- server-beta/src/searcher/isGlobal.lua | 28 +++++----------------------- 3 files changed, 9 insertions(+), 49 deletions(-) (limited to 'server-beta/src') diff --git a/server-beta/src/searcher/eachGlobal.lua b/server-beta/src/searcher/eachGlobal.lua index 8f556976..27ee0f21 100644 --- a/server-beta/src/searcher/eachGlobal.lua +++ b/server-beta/src/searcher/eachGlobal.lua @@ -21,6 +21,7 @@ local function eachGlobal(source, callback) end result[name][#result[name]+1] = info result[name].mode[info.mode] = true + searcher.cache.isGlobal[src] = true end) for _, info in pairs(result) do callback(info) diff --git a/server-beta/src/searcher/getLibrary.lua b/server-beta/src/searcher/getLibrary.lua index 3b9714a3..062c8937 100644 --- a/server-beta/src/searcher/getLibrary.lua +++ b/server-beta/src/searcher/getLibrary.lua @@ -5,39 +5,16 @@ local library = require 'library' local function getLibrary(source) local name = guide.getKeyName(source) if not name then - return + return nil end local sname = name:match '^s|(.+)$' if not sname then - return + return nil end if searcher.isGlobal(source) then return library.global[sname] end - local node = source.node - if not node then - return - end - - local lib - searcher.eachRef(node, function (info) - local src = info.source - if info.mode == 'get' and searcher.isGlobal(node) then - local nodeName = guide.getKeyName(src) - if not nodeName then - return - end - local sNodeName = nodeName:match '^s|(.+)$' - if not sNodeName then - return - end - local tbl = library.global[sNodeName] - if tbl then - lib = lib or tbl[sname] - end - end - end) - return lib + return nil end function searcher.getLibrary(source) diff --git a/server-beta/src/searcher/isGlobal.lua b/server-beta/src/searcher/isGlobal.lua index 72a9448b..e4093b58 100644 --- a/server-beta/src/searcher/isGlobal.lua +++ b/server-beta/src/searcher/isGlobal.lua @@ -1,28 +1,10 @@ local searcher = require 'searcher.searcher' - -local function isGlobal(source) - local node = source.node - if not node then - return false - end - local global = searcher.eachRef(node, function (info) - if info.source.tag == '_ENV' then - return true - end - end) - return global or false -end +local guide = require 'parser.guide' function searcher.isGlobal(source) - local cache = searcher.cache.isGlobal[source] - if cache ~= nil then - return cache + source = guide.getRoot(source) + if not searcher.cache.eachGlobal[source] then + searcher.eachGlobal(source, function () end) end - cache = isGlobal(source) - searcher.cache.isGlobal[source] = cache - searcher.eachRef(source, function (info) - local src = info.source - searcher.cache.isGlobal[src] = cache - end) - return cache + return searcher.cache.isGlobal[source] == true end -- cgit v1.2.3