Próbuję odjąć tabelę od tabeli w Lua, więc tabela zwrotna będzie odejmowaniem t1 od t2.Odejmij tabelę od tabeli w Lua
Wydaje się, że to działa, ale czy jest to skuteczniejszy sposób?
function array_sub(t1, t2)
-- Substract Arrays from Array
-- Usage: nretable = array_sub(T1, T2) -- removes T1 from T2
table.sort(t1)
for i = 1, #t2 do
if (t2[i] ~= nil) then
for j = 1, #t1 do
if (t2[i] == t1 [j]) then
table.remove (t2, i)
end
end
end
end
return t2
end
local remove ={1,2,3}
local full = {}; for i = 1, 10 do full[i] = i end
local test ={}
local test = array_sub(remove, full)
for i = 1, #test do
print (test[i])
end
W rodzimych operacjach arytmetycznych Lua nie są realizowane dla standardowych wartości tabel! Podany kod spowoduje błąd ... – Piglet