Navigation

localType=require"simionx.Type"-- A function with parameter checked against a built-in type.functionsqrt(x)Type.nonnegative_integer:check(x)returnmath.sqrt(x)endassert(sqrt(0)==0)-- A custom type.localT_color=Type(function(o)returno=="red"oro=="blue"end,"color")-- A function with named parameter validation.localargtfunctionformat_thing(t)argt=argtorType{mass=Type.number,color=T_color+Type['nil']};argt:check(t)returnt.mass.." "..(t.color==niland"unknown"ort.color)endassert(format_thing{mass=10,color="blue"}=="10 blue")

For a table t to match the type, it must have the same keys as the
type table, and the values of t must match the corresponding
types in the type table.

Note that in the above we write Type['nil'] rather than Type.nil.
The latter is syntactially invalid in Lua since nil is a reserved
word in Lua.

Note

This page is abridged from the full SIMION 8.1.1 "Supplemental Documentation" (Help file). The following additional sections can be found in the full version of this page accessible via the "Help > Supplemental Documentation" menu in SIMION 8.1.1: