Module:TableTools: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
273 bytes added ,  17 December 2013
clone tn rather than returning an altered tn
(add a complement function)
(clone tn rather than returning an altered tn)
Line 211: Line 211:
error("only one argument passed to 'complement' (minimum is two)", 2)
error("only one argument passed to 'complement' (minimum is two)", 2)
end
end
--[[
-- Now we know that we have at least two sets.
-- Now we know that we have at least two sets.
local ret = select(lim, ...)
-- First, get all the key/value pairs in tn. We can't simply make ret equal to tn,
checkType('complement', lim, ret, 'table')
-- as that will affect the value of tn for the whole module.
--]]
local tn = select(lim, ...)
checkType('complement', lim, tn, 'table')
local ret = {}
for k, v in pairs(tn) do
ret[k] = v
end
-- Remove all the key/value pairs in t1, t2, ..., tn-1.
for i = 1, lim - 1 do
for i = 1, lim - 1 do
local t = select(i, ...)
local t = select(i, ...)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.