diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-14 16:46:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-14 16:46:50 +0800 |
commit | 8860d1a77c820e017ee82d6ba9ce2ff2b8d90e8b (patch) | |
tree | bf564d69b48f42f32f56457aefae67c3b3da5c66 /server/src | |
parent | 64a27b89294eaf8f191c740f03ab29b629cbdb0a (diff) | |
download | lua-language-server-8860d1a77c820e017ee82d6ba9ce2ff2b8d90e8b.zip |
整理一下代码
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/matcher/vm.lua | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index d3f5da70..df722501 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -102,13 +102,7 @@ function mt:buildTable(source) end end else - local value - if obj.type == '...' then - value = { type = 'list' } - self:unpackDots(value, 1) - else - value = self:getExp(obj) - end + local value = self:getExp(obj) if value.type == 'list' then if index == #source then for i, v in ipairs(value) do @@ -852,6 +846,10 @@ function mt:getExp(exp) return self:buildFunction(exp) elseif tp == 'table' then return self:buildTable(exp) + elseif tp == '...' then + local value = { type = 'list' } + self:unpackDots(value) + return value end error('Unkown exp type: ' .. tostring(tp)) end @@ -864,15 +862,13 @@ end function mt:doReturn(action) for i, exp in ipairs(action) do - if exp.type == '...' then - local values = {} - self:unpackDots(values) - for x, v in ipairs(values) do + local value = self:getExp(exp) + if value.type == 'list' then + for x, v in ipairs(value) do self:setFunctionReturn(self:getCurrentFunction(), i + x - 1, v) end break else - local value = self:getExp(exp) self:setFunctionReturn(self:getCurrentFunction(), i, value) end end |