summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/vm/eachRef.lua22
-rw-r--r--script-beta/vm/getMeta.lua2
2 files changed, 21 insertions, 3 deletions
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 6d34d28b..507b713d 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -2,9 +2,27 @@ local guide = require 'parser.guide'
local files = require 'files'
local vm = require 'vm.vm'
+local function ofParentMT(func, callback)
+ if not func or func.type ~= 'function' then
+ return
+ end
+ local parent = func.parent
+ if not parent or parent.type ~= 'setmethod' then
+ return
+ end
+ local node = parent.node
+ if not node then
+ return
+ end
+ vm.eachRef(node, callback)
+end
+
local function ofLocal(loc, callback)
-- 方法中的 self 使用了一个虚拟的定义位置
- if loc.tag ~= 'self' then
+ if loc.tag == 'self' then
+ local func = guide.getParentFunction(loc)
+ ofParentMT(func, callback)
+ else
callback(loc)
end
local refs = loc.ref
@@ -191,7 +209,7 @@ end
--- 获取所有的引用
--- 可以穿透函数返回值
-function vm.eachRef(source, callback, max)
+function vm.eachRef(source, callback)
local mark = {}
eachRef(source, function (src)
if mark[src] then
diff --git a/script-beta/vm/getMeta.lua b/script-beta/vm/getMeta.lua
index 4915f616..49e9cf34 100644
--- a/script-beta/vm/getMeta.lua
+++ b/script-beta/vm/getMeta.lua
@@ -26,7 +26,7 @@ local function eachMetaOfRecv(source, callback)
if special ~= 'setmetatable' then
return
end
- vm.eachFieldInTable(call.args[1])
+ vm.eachFieldInTable(call.args[1], callback)
local mt = call.args[2]
if mt then
callback(mt)