Code: Select all
-- name this file arrr.lua
local mt = {
__eq = function(self, other)
local l1,l2 = #self, #other
if l1 ~= l2 then return false end
for i=1, l1 do
if self[i] ~= other[i] then return false end
end
return true
end
}
local arrr = function(...)
return setmetatable({...}, mt)
end
return arrr
Usage:
Code: Select all
local arrr = require 'arrr'
r, g, b, a = img:getPixel( x, y )
if arrr(r, g , b, a) == arrr(255, 0, 0 , 255) then
-- do stuff
end
Arrr.
Edit: In all honesty, I prefer a more verbose but clear approach:
Code: Select all
local arrayEqual = function(self, other)
local l1,l2 = #self, #other
if l1 ~= l2 then return false end
for i=1, l1 do
if self[i] ~= other[i] then return false end
end
return true
end
...
r, g, b, a = img:getPixel( x, y )
if arrayEqual({r, g , b, a}, {255, 0, 0 , 255}) then
-- do stuff
end