From d65825e90bc7137f50cafc36ba0972db5e6a55be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 10 Oct 2019 11:06:35 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/core/getglobal.lua | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 server-beta/src/core/getglobal.lua (limited to 'server-beta/src/core/getglobal.lua') diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua new file mode 100644 index 00000000..ffa35176 --- /dev/null +++ b/server-beta/src/core/getglobal.lua @@ -0,0 +1,49 @@ +local m = {} + +function m:def(source, callback) + local env = source.node + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + self:search(ref, 'special', 'def', callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', 'def', callback) + end + end + end +end + +function m:ref(source, callback) + local env = source.node + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + callback(ref, 'get') + self:search(ref, 'special', 'ref', callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', 'ref', callback) + end + end + end +end + +function m:field(source, callback) + self:search(source, 'getglobal', 'ref', function (src) + local parent = src.parent + local tp = parent.type + if tp == 'setfield' + or tp == 'getfield' + or tp == 'setmethod' + or tp == 'getmethod' + or tp == 'setindex' + or tp == 'getindex' then + callback(parent) + end + end) +end + +return m -- cgit v1.2.3