Type Annotations
Unlike any of today’s Lua versions, Lua++ can restrict variables to be of certain type. As projects grow in size, it becomes harder for developers to remember of what type each variable is. Type annotations help prevent insidious bugs that can take hours to discover. In addition, they help enforce interfaces to classes in object-oriented programming.
Lua++ supports five variable primitive types: boolean
, string
, number
, Table
, and Array
, which are described in detail in . To assign a type to a variable, use the :
separator after the variable name. The annotation can also be used on constant variables. If a variable is assigned a value whose type is not equal to the type of the annotation, then a compiler error will be thrown.
Last updated