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

Last updated