summaryrefslogtreecommitdiff
path: root/server/src/vm/value.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-29 14:10:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-29 14:10:10 +0800
commit01c4691c6151bcb65793e93ed44a140fd214d17e (patch)
tree63d5e8475dd4eb42de28fae6990b2ceb85f792d8 /server/src/vm/value.lua
parent37a138389b6242ae9885ec283eba0bc5fa90b2c3 (diff)
downloadlua-language-server-01c4691c6151bcb65793e93ed44a140fd214d17e.zip
解除 value:getChild 的递归
Diffstat (limited to 'server/src/vm/value.lua')
-rw-r--r--server/src/vm/value.lua38
1 files changed, 16 insertions, 22 deletions
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 872e96b6..0c0b8029 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -136,6 +136,7 @@ function mt:getLibChild(index)
local childs = libraryBuilder.child(lib)
return childs[index]
end
+ return nil
end
function mt:eachLibChild(callback)
@@ -149,30 +150,23 @@ function mt:eachLibChild(callback)
end
end
-local function finishGetChild(self, index, source, mark)
+function mt:getChild(index, source)
self:setType('table', 0.5)
- local value = self:rawGet(index)
- if value then
- return value
- end
- local method = self:getMetaMethod('__index')
- if not method then
- local v = self:getLibChild(index)
- return v
- end
- if not mark then
- mark = {}
- end
- if mark[method] then
- return nil
+ local parent = self
+ local value
+ -- 最多检查3层 __index
+ for _ = 1, 3 do
+ value = parent:rawGet(index)
+ if value then
+ break
+ end
+ local method = parent:getMetaMethod('__index')
+ if not method then
+ value = parent:getLibChild(index)
+ break
+ end
+ parent = method
end
- mark[method] = true
-
- return finishGetChild(method, index, source, mark)
-end
-
-function mt:getChild(index, source)
- local value = finishGetChild(self, index)
if not value then
value = create('any', source)
self:setChild(index, value)