lua-Coat
Yet Another Lua Object-Oriented Model

References

This module provides the ability to create type contraints which are used in attribute definition.

All functions are stored in a global space.

Global Functions

coerce.type = { from = via [, from = via, ...] }

Declares the type coerce from the type named from via a function via.

enum.name = { string1, string2 [, ...] }

Creates a subtype name for a given set of strings.

subtype.name = { as = parent, where = validator [, message = msg ] }

Creates a subtype name from the type parent which passes the constraint specified in the function validator, the optional msg is used as error message.

Examples

require 'Coat.Types'

subtype.Natural = {
    as = 'number',
    where = function (val) return val > 0 end,
}

subtype.NaturalLessThanTen = {
    as = 'Natural',
    where = function (val) return val < 10 end,
    message = "This number (%d) is not less than ten!",
}

enum.Colour = { 'Red', 'Green', 'Blue' }

subtype.DateTime = {
    as = 'string',
    where = function (val) return true end,
}

coerce.DateTime = {
    number = function (val) return os.date("!%d/%m/%Y %H:%M:%S", val) end
}