From 6b3920292359646f0f24f8770d83e8db755ef896 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, 7 Dec 2018 11:37:14 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/compile.lua | 32 +++++++++++++++++++++----------- server/src/matcher/find_lib.lua | 19 ++++++++++++++----- 2 files changed, 35 insertions(+), 16 deletions(-) (limited to 'server') diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua index f2017af2..5ed3e97a 100644 --- a/server/src/matcher/compile.lua +++ b/server/src/matcher/compile.lua @@ -97,6 +97,27 @@ function mt:getField(parent, key, source) return var end +function mt:isGlobal(var) + if var.type ~= 'field' then + return false + end + if not var.parent then + return false + end + return var.parent.key == '_ENV' or var.parent.key == '_G' +end + +function mt:getApi(func) + if not func then + return nil + end + func = func.value or func + if self:isGlobal(func) then + return func.key + end + return nil +end + function mt:checkName(name) local var = self:getVar(name[1], name) self:addInfo(var, 'get', name) @@ -111,17 +132,6 @@ function mt:checkDots(source) self:addInfo(dots, 'get', source) end -function mt:getApi(func) - if not func then - return nil - end - func = func.value or func - if func.type == 'field' and func.parent.key == '_ENV' then - return func.key - end - return nil -end - function mt:searchCall(call, func) local results = {} for i, exp in ipairs(call) do diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua index e52d1673..d4cb6bf2 100644 --- a/server/src/matcher/find_lib.lua +++ b/server/src/matcher/find_lib.lua @@ -99,14 +99,23 @@ local function getLibs() return Libs end -local function checkLibAsGlobal(var, name, lib) +local function isGlobal(var) + if var.type ~= 'field' then + return false + end + if not var.parent then + return false + end + return var.parent.key == '_ENV' or var.parent.key == '_G' +end + +local function checkLibAsGlobal(var, name) -- 检查是否是全局变量 local value = var.value or var - if value.type == 'field' and value.parent.key == '_ENV' then - if value.key == name then - return name - end + if value.key == name and isGlobal(value) then + return name end + return nil end local function checkLib(var, name, lib) -- cgit v1.2.3