Classes
Last updated
Last updated
Lua++ has been designed to support real object-oriented programming by implementing classes. They function similarly to Lua tables but eliminate the need for simulated solutions using metamethods. Classes in Lua++ have similar syntax and behaviors to those in TypeScript and are structured like so:
Token | Description |
---|---|
To demonstrate just how superior classes are to the legacy tables, consider code fragments that calculate the area of a triangle.
Contrast code above with the following implementation in classic Lua:
As illustrated, Lua++ classes provide a simple and straightforward interface for getting and setting member variables while Lua’s tables perform a similar function but are awkward and inconvenient.
tag
The type name given to the class.
template-spec
Optional template specifications.
base-list
Optional list of classes this class will derive members from.
member-list
List of members.