mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-04 21:29:13 +00:00
Merge pull request #334 from Wilma456/colorcheck
Add Checks to Colors API
This commit is contained in:
commit
836de416bc
@ -19,32 +19,51 @@ black = 32768
|
|||||||
function combine( ... )
|
function combine( ... )
|
||||||
local r = 0
|
local r = 0
|
||||||
for n,c in ipairs( { ... } ) do
|
for n,c in ipairs( { ... } ) do
|
||||||
|
if type( c ) ~= "number" then
|
||||||
|
error( "bad argument #"..n.." (expected number, got " .. type( c ) .. ")", 2 )
|
||||||
|
end
|
||||||
r = bit32.bor(r,c)
|
r = bit32.bor(r,c)
|
||||||
end
|
end
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
function subtract( colors, ... )
|
function subtract( colors, ... )
|
||||||
|
if type( colors ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( colors ) .. ")", 2 )
|
||||||
|
end
|
||||||
local r = colors
|
local r = colors
|
||||||
for n,c in ipairs( { ... } ) do
|
for n,c in ipairs( { ... } ) do
|
||||||
|
if type( c ) ~= "number" then
|
||||||
|
error( "bad argument #"..tostring( n+1 ).." (expected number, got " .. type( c ) .. ")", 2 )
|
||||||
|
end
|
||||||
r = bit32.band(r, bit32.bnot(c))
|
r = bit32.band(r, bit32.bnot(c))
|
||||||
end
|
end
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
function test( colors, color )
|
function test( colors, color )
|
||||||
|
if type( colors ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( colors ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( color ) ~= "number" then
|
||||||
|
error( "bad argument #2 (expected number, got " .. type( color ) .. ")", 2 )
|
||||||
|
end
|
||||||
return ((bit32.band(colors, color)) == color)
|
return ((bit32.band(colors, color)) == color)
|
||||||
end
|
end
|
||||||
|
|
||||||
function rgb8( r, g, b )
|
function rgb8( r, g, b )
|
||||||
if type(r) == "number" and g == nil and b == nil then
|
if type( r ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( r ) .. ")", 2 )
|
||||||
|
elseif type(r) == "number" and g == nil and b == nil then
|
||||||
return bit32.band( bit32.rshift( r, 16 ), 0xFF ) / 255, bit32.band( bit32.rshift( r, 8 ), 0xFF ) / 255, bit32.band( r, 0xFF ) / 255
|
return bit32.band( bit32.rshift( r, 16 ), 0xFF ) / 255, bit32.band( bit32.rshift( r, 8 ), 0xFF ) / 255, bit32.band( r, 0xFF ) / 255
|
||||||
elseif type(r) == "number" and type(g) == "number" and type(b) == "number" then
|
elseif type(r) == "number" and type(g) == "number" and type(b) == "number" then
|
||||||
return
|
return
|
||||||
bit32.lshift( bit32.band(r * 255, 0xFF), 16 ) +
|
bit32.lshift( bit32.band(r * 255, 0xFF), 16 ) +
|
||||||
bit32.lshift( bit32.band(g * 255, 0xFF), 8 ) +
|
bit32.lshift( bit32.band(g * 255, 0xFF), 8 ) +
|
||||||
bit32.band(b * 255, 0xFF)
|
bit32.band(b * 255, 0xFF)
|
||||||
else
|
elseif type( g ) ~= "number" then
|
||||||
error( "Expected 1 or 3 numbers", 2 )
|
error( "bad argument #2 (expected number, got " .. type( g ) .. ")", 2 )
|
||||||
|
elseif type( b ) ~= "number" then
|
||||||
|
error( "bad argument #3 (expected number, got " .. type( b ) .. ")", 2 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user