Documentation
GitHubTwitter
  • overview
    • What is Lua++?
    • Why Lua++?
  • language improvements
    • Compound Assignments
    • Postfix and Prefix Operators
    • The Continue Statement
    • Constant Variables
    • Type Annotations
      • Function Annotations
    • Classes
      • Constructors
      • Templating
      • Inheritance
      • Encapsulation
    • Events
    • Macros
      • Lenient
      • Comment
      • C-Arrays
  • contributing
    • Installing the Project
Powered by GitBook
On this page

Was this helpful?

  1. language improvements

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.

local a: number = 12
const b: string = "Hello, world!"
PreviousConstant VariablesNextFunction Annotations

Last updated 2 years ago

Was this helpful?