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:
class [tag [template-spec] : [base-list]] {
member-list
}
Token
Description
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.
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.