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
  2. Classes

Constructors

Lua++ supports two different kinds of constructors by default: implicit and explicit. Explicit constructors require the parameters to be wrapped in parentheses, while implicit allow the value to be directly passed as shown in the following examples:

class ExplicitConstructor {
    value: number,

    constructor(value: number)
        self.value = value
    end
}

local exp: ExplicitConstructor = ExplicitConstructor(1)
class ImplicitConstructor {
    value: number,

    implicit constructor(value: number)
        self.value = value
    end
}

local imp: ImplicitConstructor = 1
PreviousClassesNextTemplating

Last updated 2 years ago

Was this helpful?