Match-IT has nearly 200 data types. A data type defines what a value of that type can contain and also, critically, what can be done with it. In your scripts the type of any value must be defined. It can be defined explicitly or it can be implied from the context. To define the type explicitly, it can be ‘cast’ using one of the Match-IT type names.

For example, to make a value into a Match-IT string:

stringthing = m.str(someotherthing)

This mechanism can also be used to construct values of specific types from their parts. For example:

somemoney = m.money(‘Sterling,100’)

This will make a Match-IT money type that represents £100. The parameter given to m.money in this case is the make symbols for the type. NB: The make symbols must be enclosed in quotes if it’s a literal string, omitting the quotes can lead to strange effects as an undefined value in Lua is interpreted as nil. E.g.:

Fred = 6
areal = m.real(fred)

Here the case of fred is different to Fred, so fred is undefined. This will create a value in areal of 0 not 6.

The data type is implied when dealing with fields in files as each field has a data type associated with it. In this case an appropriate ‘cast’ is done automatically when you assign to a file field, and the type of any value read will be that defined for the field.

A list of type names, and their make symbols, for each module is available in the reference section. The names under the LType column are the names required in your Lua scripts.

Type casting

In general, you can define a data type by a ‘cast’ from a type number (e.g. m.zvMaterial), a type name (e.g. m.TypeNam(‘Material’)), a file number (e.g. m.mch) or a file name (e.g. m.FileNam(‘mch’)). The latter is useful when dealing with an owner file, owner record pair from some file. For example:

msc = m.file(m.msc)

owner = msc.OwnerFile(msc.OwnerRec)

Here the date type of owner will be whatever is appropriate for the contents of the msc.OwnerFile field and its value will be whatever was in the msc.OwnerRec field.

Type coercion

When accessing and assigning Match-IT values in your Lua scripts, Match-IT will try to coerce values to an appropriate type. If the coercion fails, the operation you are attempting will throw an error and the script will terminate. In most sensible cases the coercion will succeed, for example a number can be considered to be a boolean in an IF condition.

When dealing purely with Match-IT measures, all the usual rules apply, e.g. 1 metre + 1 foot will do unit conversions.

When dealing with mixed Match-IT types and Lua types for arithmetic cases, the Lua type will be coerced into the equivalent Match-IT type and then the operation performed, e.g. 1 metre + 1, the lone ‘1’ will be converted to a unitless measure and then the addition performed (note: a unitless measure is units compatible with anything).

When dealing with mixed Match-IT types and Lua types for comparison cases, no coercion is performed (due to, IMO, limitations in the Lua language). This means you must specifically coerce comparison operands, e.g:

limit = 2
test = m.real(1)
if test < limit then ...

Will raise an error, but:

limit = 2
test = m.real(1)
if test < m.real(limit) then ...

Will work as expected.

Equality

Lua considers any non-nil and non-zero value to be true (like C). This in conjunction with the lack of type coercion when doing comparison operations can lead you into trouble if you are not careful. E.g:

x = m.flag(false)
if x then ...

In the above, x is considered to be true by Lua even though it’s a Match-IT false flag! Here, there is an implicit == comparison, to make it work properly you must change it into an explicit comparison. E.g:

x = m.flag(false)
if x == m.flag(true) then ...

This will then work as expected.

Another situation to be wary of is testing for equality with mixed Match-IT and Lua types. E.g:

a = m.real(1)
b = 1
if a == b then ...

In the above, Lua considers a to be not equal to b because they are different types. To make this work as expected, you must again coerce the operands into Match-IT types. E.g.:

a = m.real(1)
b = 1
if a == m.real(b) then ...

This will then work as expected.

Strings

Lua uses the ‘\’ character as the escape character (to denote special values, e.g. \n is the new line character). You must be wary of this when constructing file names and paths from literals. E.g.:

filename = ‘c:\match_it\configs\welcome.wiz’

This will not create what you want because the \m, \c and \w sequences are interpreted as escape sequences, so you end up with ‘c:atch_itonfigselcome.wiz’. Instead use the ‘/’ character like this:

filename = ‘c:/match_it/configs/welcome.wiz’

Arithmetic

When doing arithmetic involving a Match-IT data type, the result is always a Match-IT type of the same type as the first operand. This applies even if the first operand was not initially a Match-IT type. E.g.:

now = m.now()
later = now + 3600
number = 3600 + now

The type of later is a Clock but the type of number is a Real.