diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-25 11:02:06 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-25 11:02:06 +0800 |
commit | f956fc7f9ee8e2c4595b3fa843ebfaa41f97469e (patch) | |
tree | 6011233555b333aee34269191ee1053319b856d2 /server/src/core/vm.lua | |
parent | 8860d44ef8b00355f87ccdeb82b143e999ee912e (diff) | |
download | lua-language-server-f956fc7f9ee8e2c4595b3fa843ebfaa41f97469e.zip |
更新库的支持
Diffstat (limited to 'server/src/core/vm.lua')
-rw-r--r-- | server/src/core/vm.lua | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua index 054e111f..b2e8ff7d 100644 --- a/server/src/core/vm.lua +++ b/server/src/core/vm.lua @@ -4,6 +4,8 @@ local createValue = require 'core.value' local DefaultSource = { start = 0, finish = 0 } local GlobalValue +local LibraryValue = {} +local LibraryChild = {} -- 根据赋值顺序决定遍历顺序的表 local function orderTable() @@ -752,26 +754,23 @@ end function mt:getLibChild(value, lib, parentType) if lib.child then - if self.libraryChild[lib] then - value.child = self.libraryChild[lib] + if LibraryChild[lib] then + value:setChild(LibraryChild[lib]) return end - self.libraryChild[lib] = {} + -- 要先声明缓存,以免死循环 + LibraryChild[lib] = value:getChild() for fName, fLib in pairs(lib.child) do local fField = value:createField(fName) local fValue = self:getLibValue(fLib, parentType) self:setValue(fField, fValue) end - value:eachField(function (k, v) - self.libraryChild[lib][k] = v - end) - value.child = self.libraryChild[lib] end end function mt:getLibValue(lib, parentType, v) - if self.libraryValue[lib] then - return self.libraryValue[lib] + if LibraryValue[lib] then + return LibraryValue[lib] end local tp = lib.type local value @@ -815,7 +814,7 @@ function mt:getLibValue(lib, parentType, v) else value = self:createValue(tp or 'any') end - self.libraryValue[lib] = value + LibraryValue[lib] = value value.lib = lib value.parentType = parentType @@ -1485,8 +1484,6 @@ local function compile(ast, lsp, uri) globals= {}, main = nil, }, - libraryValue = {}, - libraryChild = {}, lsp = lsp, uri = uri, }, mt) @@ -1499,8 +1496,6 @@ local function compile(ast, lsp, uri) vm.scope = nil vm.chunk = nil - vm.libraryValue = nil - vm.libraryChild = nil return vm end |