Похоже, вы по существу пересекаете любое количество таблиц вместе.Я уверен, что есть библиотеки для этого, но вот наивная реализация:
local idTables = {
["idsA"] = {1, 2, 3, 4},
["idsB"] = {4, 5, 6, 7},
["idsC"] = {4, 8, 9, 10}
}
local intersection = {}
local firstTable = true
for key, tbl in pairs(idTables) do
-- If this is the first table we are looking at, populate
-- our intersection table as a map, mapping every ID that appears to a flag.
-- Note that the choice of flag being a bool is somewhat arbitrary
if firstTable then
for _, v in ipairs(tbl) do
intersection[v] = true
end
firstTable = false
else
-- Otherwise, we already have a table to intersect against, so for every
-- ID in our intersection map, lets check this next table, to see if
-- every element of this next table against our intersection map
for knownId,_ in pairs(intersection) do
local newTableHasKnownId = false
for _,id in ipairs(tbl) do
if id == knownId then
-- This new table of IDs we're iterating does have the current ID of
-- the intersection table we're looking at. We can flag it as such, and stop
-- looking for that known ID
newTableHasKnownId = true
break
end
end
-- Drop the 'known' ID from the intersection map if it wasn't in the table
-- we just iterated.
if not newTableHasKnownId then
intersection[knownId] = nil
end
end
end
end
print('intersection results:')
for key,_ in pairs(intersection) do
print(key)
end