summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/searcher')
-rw-r--r--server-beta/src/searcher/eachGlobal.lua1
-rw-r--r--server-beta/src/searcher/getLibrary.lua29
-rw-r--r--server-beta/src/searcher/isGlobal.lua28
3 files changed, 9 insertions, 49 deletions
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