From fa0f8b12d5e6d15bd3a3fdb994c20d2fce2a1fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 12 Dec 2018 16:10:26 +0800 Subject: =?UTF-8?q?find=5Flib=E6=94=AF=E6=8C=81=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/find_lib.lua | 14 +++++++++++++- server/src/matcher/vm.lua | 34 +++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua index d2b5d6a8..e4ea6e02 100644 --- a/server/src/matcher/find_lib.lua +++ b/server/src/matcher/find_lib.lua @@ -22,7 +22,19 @@ local function findLib(var) return lib, fullKey, false end else - return lib, lib.name, false + local res + if not lib.source then + return lib, lib.nick or lib.name, false + end + for _, source in ipairs(lib.source) do + if source.type == value.parentType then + res = source + end + end + if not res then + return lib, lib.nick or lib.name, false + end + return lib, res.nick or res.name or lib.nick or lib.name, false end end diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index 16d5fe20..928a954f 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -386,9 +386,34 @@ function mt:createValue(type, source, v) source = source or DefaultSource, value = v, } + local lib = library.object[type] + if lib then + self:getLibChild(value, lib, 'object') + end return value end +function mt:getLibChild(value, lib, parentType) + if lib.child then + if self.libraryChild[lib] then + value.child = self.libraryChild[lib] + return + end + self.libraryChild[lib] = {} + for fName, fLib in pairs(lib.child) do + local fField = self:createField(value, fName) + local fValue = self:getLibValue(fLib, parentType) + self:setValue(fField, fValue) + end + if value.child then + for k, v in pairs(value.child) do + self.libraryChild[lib][k] = v + end + end + value.child = self.libraryChild[lib] + end +end + function mt:getLibValue(lib, parentType, v) if self.libraryValue[lib] then return self.libraryValue[lib] @@ -433,13 +458,7 @@ function mt:getLibValue(lib, parentType, v) value.lib = lib value.parentType = parentType - if lib.child then - for fName, fLib in pairs(lib.child) do - local fField = self:createField(value, fName) - local fValue = self:getLibValue(fLib, parentType) - self:setValue(fField, fValue) - end - end + self:getLibChild(value, lib, parentType) return value end @@ -875,6 +894,7 @@ local function compile(ast) calls = {}, }, libraryValue = {}, + libraryChild = {}, }, mt) -- 创建初始环境 -- cgit v1.2.3