summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/eachField.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/searcher/eachField.lua')
-rw-r--r--server-beta/src/searcher/eachField.lua101
1 files changed, 68 insertions, 33 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua
index 320fd9f2..6a86314b 100644
--- a/server-beta/src/searcher/eachField.lua
+++ b/server-beta/src/searcher/eachField.lua
@@ -1,30 +1,63 @@
-local function ofLocal(searcher, source, callback)
- if source.ref then
- for _, ref in ipairs(source.ref) do
- if ref.type == 'getlocal' then
- local parent = ref.parent
- local field = searcher:getField(parent)
- if field then
- callback {
- searcher = searcher,
- source = field,
- }
- end
- elseif ref.type == 'getglobal'
- or ref.type == 'setglobal' then
- callback {
- searcher = searcher,
- source = ref,
- }
- end
+local function ofTabel(searcher, value, callback)
+ for _, field in ipairs(value) do
+ if field.type == 'tablefield' then
+ callback {
+ searcher = searcher,
+ source = field.field,
+ }
+ elseif field.type == 'tableindex' then
+ callback {
+ searcher = searcher,
+ source = field.index,
+ }
+ else
+ callback {
+ searcher = searcher,
+ source = field,
+ }
end
end
end
-local function ofGlobal(searcher, source, callback)
+local function ofValue(searcher, value, callback)
+ if value.type == 'table' then
+ ofTabel(searcher, value, callback)
+ end
+end
+
+local function rawField(searcher, source, callback)
+ if source.type == 'getlocal' then
+ local parent = source.parent
+ local field = searcher:getField(parent)
+ if field then
+ callback {
+ searcher = searcher,
+ source = field,
+ }
+ end
+ elseif source.type == 'getglobal'
+ or source.type == 'setglobal' then
+ callback {
+ searcher = searcher,
+ source = source,
+ }
+ end
+end
+
+return function (searcher, source, callback)
searcher:eachRef(source, function (info)
local src = info.source
- if src.type == 'getglobal' then
+ if src.tag == '_ENV' then
+ if src.ref then
+ for _, ref in ipairs(src.ref) do
+ rawField(info.searcher, ref, callback)
+ end
+ end
+ elseif src.type == 'local' then
+ if src.value then
+ ofValue(searcher, src.value, callback)
+ end
+ elseif src.type == 'getlocal' then
if src.parent then
local field = info.searcher:getField(src.parent)
if field then
@@ -34,18 +67,20 @@ local function ofGlobal(searcher, source, callback)
}
end
end
+ elseif src.type == 'setlocal' then
+ ofValue(info.searcher, src.value, callback)
+ elseif src.type == 'getglobal' then
+ if src.parent then
+ local field = info.searcher:getField(src.parent)
+ if field then
+ callback {
+ searcher = info.searcher,
+ source = field,
+ }
+ end
+ end
+ elseif src.type == 'setglobal' then
+ ofValue(info.searcher, src.value, callback)
end
end)
end
-
-return function (searcher, source, callback)
- if source.type == 'local' then
- ofLocal(searcher, source, callback)
- elseif source.type == 'getlocal'
- or source.type == 'setlocal' then
- ofLocal(searcher, source.node, callback)
- elseif source.type == 'getglobal'
- or source.type == 'setglobal' then
- ofGlobal(searcher, source, callback)
- end
-end