From 0f8123a8a45db5c568149e03876d4f3c57dacc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 20 Dec 2018 16:53:59 +0800 Subject: =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=85=B6=E4=BB=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/vm.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'server/src/matcher/vm.lua') diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index c9fe1fd0..05b4f2e6 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -35,6 +35,24 @@ local function orderTable() }) end +local function deepCopy(t, mark, new) + mark = mark or {} + new = new or {} + for k, v in pairs(t) do + if type(v) == 'table' then + if mark[v] then + new[k] = mark[v] + else + mark[v] = {} + new[k] = deepCopy(v, mark, mark[v]) + end + else + new[k] = v + end + end + return new +end + local mt = {} mt.__index = mt @@ -1157,6 +1175,19 @@ function mt:createEnvironment() gValue.child = envValue.child end +function mt:mergeRequire(value, destVM) + -- 取出对方的主函数 + local main = destVM.results.main + -- 获取主函数返回值,注意不能修改对方的环境 + local mainValue + if not main.returns then + mainValue = self:createValue('nil') + else + mainValue = deepCopy(main.returns[1]) + end + self:mergeValue(value, mainValue) +end + function mt:loadRequires() if not self.lsp or not self.lsp.workspace then return @@ -1168,6 +1199,7 @@ function mt:loadRequires() -- 如果循环require,这里会返回nil local destVM = self.lsp:loadVM(uri) if destVM then + self:mergeRequire(req.value, destVM) end end end -- cgit v1.2.3