summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-25 10:46:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-25 10:46:50 +0800
commit5e6b048c74a51ebddae4308c6be582fd26ebf9d4 (patch)
treebc0b6d4bbb71a7d67272bc9e4e6bd304b5d8ab49 /server
parentf40f74a27e3853bbd027e63d6a3e3660e8071316 (diff)
downloadlua-language-server-5e6b048c74a51ebddae4308c6be582fd26ebf9d4.zip
保护
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/vm.lua25
1 files changed, 23 insertions, 2 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index acf06f98..5f984d6a 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -35,6 +35,24 @@ local function orderTable()
})
end
+local function readOnly(t)
+ return setmetatable({}, {
+ __index = function (self, k)
+ local v = t[k]
+ if type(v) == 'table' then
+ v = readOnly(v)
+ end
+ return v
+ end,
+ __newindex = function (self, k, v)
+ end,
+ __len = function (self)
+ return #t
+ end,
+ __source = t,
+ })
+end
+
local mt = {}
mt.__index = mt
@@ -426,6 +444,9 @@ function mt:updateFunctionArgs(func)
end
function mt:setFunctionArg(func, values)
+ if func.uri ~= self.uri then
+ return
+ end
if not func.argValues then
func.argValues = {}
end
@@ -482,7 +503,7 @@ function mt:getRequire(strValue, destVM)
-- 获取主函数返回值,注意不能修改对方的环境
local mainValue
if main.returns then
- mainValue = main.returns[1]
+ mainValue = readOnly(main.returns[1])
else
mainValue = self:createValue('boolean', {
type = 'name',
@@ -505,7 +526,7 @@ function mt:getLoadFile(strValue, destVM)
-- 取出对方的主函数
local main = destVM.results.main
-- loadfile 的返回值就是对方的主函数
- local mainValue = main
+ local mainValue = readOnly(main)
-- 支持 loadfile 'xxx.lua' 的转到定义
local strSource = strValue.source