Skip to content

Instantly share code, notes, and snippets.

@exerro
Created June 12, 2016 17:15
Show Gist options
  • Save exerro/f5b81c1054bf6075eb02c481f8599318 to your computer and use it in GitHub Desktop.
Save exerro/f5b81c1054bf6075eb02c481f8599318 to your computer and use it in GitHub Desktop.
local function isByte( n )
return type( n ) == "number" and n >= 0 and n < 256
end
types.define( "byte", { type = "custom", value = isByte } )
types.define( "optional byte", "byte | nil" )
types.define( "colour", "{ byte, byte, byte, optional byte }" )
print( types.check( { 1, 2 }, "colour" ) ) --> false
print( types.check( { 1, 2, 3 }, "colour" ) ) --> true
print( types.check( { 1, 2, 3, 4 }, "colour" ) ) --> true
print( types.check( { 1, 2, 3, 4, 5 }, "colour" ) ) --> false
print( types.check( { 6127, 32189, 412 }, "colour" ) ) --> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment