summaryrefslogtreecommitdiff
path: root/script-beta/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-09 15:15:47 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-09 15:15:47 +0800
commitfc3dbc4a1fb36f243991bd70bf9104bc750f000f (patch)
treed4fe16065d5088bc87d6667294d8d08beba8b628 /script-beta/vm
parent9f621b6076181e577748dda3966bbc526586445d (diff)
downloadlua-language-server-fc3dbc4a1fb36f243991bd70bf9104bc750f000f.zip
支持pcall的返回值
Diffstat (limited to 'script-beta/vm')
-rw-r--r--script-beta/vm/eachRef.lua42
1 files changed, 29 insertions, 13 deletions
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 72d7c012..f4804a77 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -3,7 +3,8 @@ local files = require 'files'
local vm = require 'vm.vm'
local library = require 'library'
-local function ofCall(func, index, callback)
+local function ofCall(func, index, callback, offset)
+ offset = offset or 0
vm.eachRef(func, function (info)
local src = info.source
local returns
@@ -13,7 +14,7 @@ local function ofCall(func, index, callback)
if returns then
-- 搜索函数第 index 个返回值
for _, rtn in ipairs(returns) do
- local val = rtn[index]
+ local val = rtn[index-offset]
if val then
callback {
source = val,
@@ -82,16 +83,17 @@ local function ofReturn(rtn, index, callback)
end
end
-local function ofSpecialCall(call, func, index, callback)
+local function ofSpecialCall(call, func, index, callback, offset)
local name = func.special
+ offset = offset or 0
if name == 'setmetatable' then
- if index == 1 then
+ if index == 1 + offset then
local args = call.args
- if args[1] then
- vm.eachRef(args[1], callback)
+ if args[1+offset] then
+ vm.eachRef(args[1+offset], callback)
end
- if args[2] then
- vm.eachField(args[2], function (info)
+ if args[2+offset] then
+ vm.eachField(args[2+offset], function (info)
if info.key == 's|__index' then
vm.eachRef(info.source, callback)
if info.value then
@@ -100,10 +102,10 @@ local function ofSpecialCall(call, func, index, callback)
end
end)
end
- vm.setMeta(args[1], args[2])
+ vm.setMeta(args[1+offset], args[2+offset])
end
elseif name == 'require' then
- if index == 1 then
+ if index == 1 + offset then
local result = vm.getLinkUris(call)
if result then
local myUri = guide.getRoot(call).uri
@@ -118,9 +120,9 @@ local function ofSpecialCall(call, func, index, callback)
end
local args = call.args
- if args[1] then
- if args[1].type == 'string' then
- local objName = args[1][1]
+ if args[1+offset] then
+ if args[1+offset].type == 'string' then
+ local objName = args[1+offset][1]
local lib = library.library[objName]
if lib then
callback {
@@ -131,6 +133,20 @@ local function ofSpecialCall(call, func, index, callback)
end
end
end
+ elseif name == 'pcall'
+ or name == 'xpcall' then
+ if index >= 2-offset then
+ local args = call.args
+ if args[1+offset] then
+ vm.eachRef(args[1+offset], function (info)
+ local src = info.source
+ if src.type == 'function' then
+ ofCall(src, index, callback, 1+offset)
+ ofSpecialCall(call, src, index, callback, 1+offset)
+ end
+ end)
+ end
+ end
end
end