Latest Update:
The Future of Class++ :
What is Class++?
Class++ is a module that aims to bring a class structure very similar to in languages such as C++ and Java to Luau. It brings access specifiers, function and operator overloading, inheritance, and many other concepts to Luau. It even supports auto-completion with inheritance, and has its own Type API!
Why Class++?
Class++ offers a much simpler and easier experience while creating classes and objects, you no longer need to deal with the complexity of metatables to create a class system. And its features allow you to far surpass the things you were able to do with just metatables.
Features
Access Specifiers
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClassPP = require(ReplicatedStorage.ClassPP)
local class = ClassPP.class
local Person = class "Person" {
Public = {
Name = "",
Age = 0
}
}
local newPerson = Person.new()
print(newPerson.Age) -- Prints 0!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClassPP = require(ReplicatedStorage.ClassPP)
local class = ClassPP.class
local Car = class "Car" {
Public = {
Brand = "Lamborghini",
},
Private = {
License_Plate = "XXXX"
}
}
local newCar = Car.new()
newCar.License_Plate = "YYYY" -- This will error! It is only accessible through class functions.
Advanced Inheritation
local class = ClassPP.class
local Vehicle = class "Vehicle" { -- Base Class
Public = {
Brand = "Tesla",
Model = "S",
License_Plate = "BITE 1987",
Year = 2012,
honk = function(self)
print("honk honk!")
end
}
}
local Car = class "Car" (Vehicle, nil) { -- Derived Class
Public = {
License_Plate = "A1B2C3"
}
}
local newCar = Car.new()
newCar:honk()
print(newCar.Brand, newCar.Model, newCar.License_Plate, newCar.Year) -- Prints "Tesla S A1B2C3 2012"!
Constructors and Destructors
local class = ClassPP.class
local Car = class "Car" {
constructor = function(self, brand, model, licensePlate)
self.License_Plate = licensePlate
self.Brand = brand
self.Model = model
end,
destructor = function(self)
self.License_Plate = ""
self.Brand = ""
self.Model = ""
end,
Public = {
Brand = "",
Model = "",
License_Plate = ""
},
}
local newCar = Car.new("ABCD", "Ford", "Mustang")
print(newCar.Brand, newCar.Model, newCar.License_Plate) -- Prints "ABCD, Ford, Mustang"!
newCar:Destroy() -- The class object will now be destroyed
newCar = nil
There are a lot more features in Class++, to learn more about them and the syntax, you can visit the documentation!
Classic Way For Comparison:
local Car = {}
Car.__index = Car
function Car.new()
local newcar = {}
setmetatable(newcar, Car)
newcar.Brand = "Lamborghini"
newcar.License_Plate = "XXXX"
return newcar
end
return Car
-------------------
local newCar = Car.new()
print(newCar.Brand)
API
Read the API
function classpp.class(className: string): (inheritedClasses) & (classData)
Creates a new class with the given classData table. An optional inheritedClasses parameter allows your new class to inherit from other classes.
Parameters:
className: string
The class name for the newclass.inheritedClasses: (...class)
Theclasses your new class will inherit from.classData: table
TheclassDatatable that contains the data about the new class.
Returns:
class
function classpp.getClass(className: string): class
Returns the class with the given className, if it exists.
Parameters:
className: string
The name of the desiredclass.
Returns:
class
To see all the methods and properties in the API, you can visit the API Reference
page.








