diff options
Diffstat (limited to 'server-beta/src/core/getglobal.lua')
-rw-r--r-- | server-beta/src/core/getglobal.lua | 49 |
1 files changed, 49 insertions, 0 deletions
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 |