### Initializing Class++ Module in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/gettingStarted.md This Lua snippet demonstrates how to properly initialize the Class++ module within a Roblox script. It retrieves the 'ReplicatedStorage' service, requires the 'Class++' ModuleScript from that location, and then creates a local alias for the 'ClassPP.class' function, which is crucial for defining classes using Class++. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local ClassPP = require(ReplicatedStorage["Class++"]) local class = ClassPP.class ``` -------------------------------- ### Creating a Class with Default Syntax (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/class.md This example demonstrates the default, more concise syntax for defining a new class using `classpp.class`. It showcases the common structure including `constructor`, `destructor`, and access modifier sections like `Public`, `Private`, `Protected`, and `Friend`. ```Lua local Class = class "Class" { constructor = function(self) ... end, destructor = function(self) ... end, Public = { ... }, Private = { ... }, Protected = { ... }, Friend = { ... } } ``` -------------------------------- ### Instantiating an Object and Accessing Default Members in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classCreation.md This example shows how to create an object from the 'Person' class using `person.new()`. It then demonstrates accessing the default 'Age' member, which prints '0' as defined in the class blueprint. ```Lua local class = ClassPP.class local person = class "Person" { Public = { Name = "", Age = 0 } } local newPerson = person.new() print(newPerson.Age) -- Prints "0"! ``` -------------------------------- ### Defining a Class Constructor with Parameters in ClassPP (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classConstructors.md This example illustrates how to define a constructor that accepts parameters. These parameters (`brand`, `model`, `licensePlate`) are passed during object creation via `Car.new()`, enabling the initialization of multiple object members with specific values at instantiation time. ```Lua 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, Public = { Brand = "", Model = "", License_Plate = "" }, } local newCar = Car.new("ABCD", "Ford", "Mustang") print(newCar.Brand, newCar.Model, newCar.License_Plate) -- Prints "ABCD, Ford, Mustang"! ``` -------------------------------- ### Marking Class Abstract with Default Syntax - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/abstract.md This example demonstrates how to use `classpp.abstract` with default syntax sugar to declare a 'Car' class as abstract. This approach simplifies the class definition process by allowing a more concise syntax. ```Lua local Car = abstract { class "Car" { Public = { ... }, ... }} ``` -------------------------------- ### Instantiating Object and Calling Method Inside Definition - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classMethods.md This example shows how to create an instance of the `Car` class and invoke the `getLicensePlate` method. It highlights the use of the `:` operator for method calls, which correctly passes the object itself as the `self` argument, contrasting it with the `.` operator. ```Lua local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", getLicensePlate = function(self) print(self.License_Plate) end }, Private = { License_Plate = "XXXX" } } local newCar = Car.new() newCar:getLicensePlate() ``` -------------------------------- ### Retrieving Class with ClassPP getClass (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/getClass.md This example demonstrates the typical usage of the `classpp.getClass` function in Lua. It shows how to retrieve a `class` object by providing its name as a string, assigning the result to a local variable `Class` for further use. ```Lua local Class = ClassPP.getClass("Class") ``` -------------------------------- ### Example Usage of Util.inClassScope for Private Access in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/util/inClassScope.md This example demonstrates a common invocation of `Util.inClassScope` to check access for a private access specifier. It shows how to pass the `class` object, set `includeInherited` to `false`, `includeFriend` to `true`, and provide a `Classes` table, returning a boolean indicating access permission. ```Lua local isAllowed = Util.inClassScope(class, false, true, Classes) -- For the Private access specifier ``` -------------------------------- ### Marking Class Abstract Without Syntax Sugar - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/abstract.md This example illustrates the usage of `classpp.abstract` without syntax sugar, showing the explicit function calls for defining an abstract 'Car' class. This provides a more verbose but sometimes necessary alternative when syntax sugar is not desired or available. ```Lua local Car = abstract({class("Car")({ Public = { ... }, ... })}) ``` -------------------------------- ### Type-checking Classes and Objects with ClassPP.Type API - Luau Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/types.md This snippet demonstrates using Class++'s `Type.typeof` and `Type.typeofClass` functions to get the runtime types of classes and class objects. It defines a custom 'Person' type and class, then creates an instance and prints its type along with the class's type, showing how the API distinguishes between a class and its instances. ```Luau local class = ClassPP.class local ctypeof, typeofClass = ClassPP.Type.typeof, ClassPP.Type.typeofClass type Person = { Age: number, Name: string, Personality: string, Job: string, Secrets: {string}, Likes: {string}, Dislikes: {string}, getSecrets: (self: Person) -> {string} } local Person = class "Person" { Public = { Age = 0, Name = "", Personality = "", Likes = {}, Dislikes = {}, Job = "", getSecrets = function(self: Person) return self.Secrets end, }, Private = { Secrets = {} } } local newPerson: Person = Person.new() print(ctypeof(Person), ",", ctypeof(newPerson)) -- Prints "Class , Person"! ``` -------------------------------- ### Default Syntax for Calling Type.typeof - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/type/typeof.md This example illustrates the standard way to invoke the `Type.typeof` function, demonstrating how to pass an `object` and capture the returned type string in a local variable. It highlights the typical usage pattern for determining an object's class. ```Lua local objectType = ClassPP.Type.typeof(object) ``` -------------------------------- ### Demonstrating Multilevel Inheritance with Class++ in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/inheritance.md This example illustrates multilevel inheritance, where a class is derived from another derived class. It defines `Person` as the base, `Child` extending `Person`, and `Student` extending `Child`. Members are inherited and can be overridden at each level, demonstrating a hierarchical class structure and further code reuse. ```Lua local class = ClassPP.class local Person = class "Person" { -- Base Class Public = { Name = "", Age = 0, Gender = "", Height = 0 } } local Child = Person.extends "Child" { -- Derived Class Public = { Age = 9, Energetic = true } } local Student = Child.extends "Student" { -- Derived Class from a Derived Class Public = { SchoolId = 0, Grade = 0, Behaviour = "Good" } } local newStudent = Student.new() print(newStudent.Name, newStudent.Age, newStudent.Gender, newStudent.Height, newStudent.Age, newStudent.Energetic, newStudent.SchoolId, newStudent.Grade, newStudent.Behaviour) -- Prints " 9 0 9 true 0 0 Good"! (Spaces represent empty strings) ``` -------------------------------- ### Defining a Basic Class Constructor in ClassPP (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classConstructors.md This snippet demonstrates how to define a basic constructor in ClassPP. The `constructor` function is automatically invoked when a new object is created using `Car.new()`, allowing for initial setup of object properties, such as setting a default `License_Plate` value. ```Lua local class = ClassPP.class local Car = class "Car" { constructor = function(self) self.License_Plate = "YYYY" end, Public = { Brand = "Lamborghini", }, Private = { License_Plate = "XXXX" } } local newCar = Car.new() ``` -------------------------------- ### Defining Class Method with Multiple Parameters Inside Definition - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classMethods.md This snippet illustrates how to define a class method, `getLicensePlate`, that accepts additional parameters beyond `self`. The example shows how to pass an argument (`number`) during the method call, demonstrating that `self` remains the first argument, followed by user-defined parameters. ```Lua local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", getLicensePlate = function(self, number) print(self.License_Plate, number) -- Prints "XXXX 1"! end }, Private = { License_Plate = "XXXX" } } local newCar = Car.new() newCar:getLicensePlate(1) -- Calling the function with an argument ``` -------------------------------- ### Defining Overloaded Methods in Class++ (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/functionOverloading.md This snippet demonstrates how to define overloaded functions in Class++ using the `class.overload` method. It shows a 'Set' method overloaded to accept two, one, or zero arguments, each performing a different action. The example illustrates how Class++ automatically dispatches to the correct function based on the number of arguments provided during the call. ```Lua local class = ClassPP.class local Test = class "Test" { Public = { ValueA = 0, ValueB = 0 } } Test.overload("Public", "Set", { function(self, a, b) print(a, b) self.ValueA = a self.ValueB = b end, function(self, a) print(a) self.ValueA = a end, function(self) print(self.ValueA, self.ValueB) end }) local newTest = Test.new() newTest:Set(1, 2) -- Prints "1 2" newTest:Set(3) -- Prints "3" newTest:Set() -- Prints "3 2" ``` -------------------------------- ### Default Syntax for Calling checkFriendship - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/util/checkFriendship.md This snippet demonstrates the standard way to call the `Util.checkFriendship` function within the ClassPP library. It assigns the boolean result of the friendship check to a local variable `isAFriend`, using the previously defined parameters: `class`, `methodName`, `method`, and `classes`. This is an example of how to integrate the function into an application. ```Lua local isAFriend = ClassPP.Util.checkFriendship(class, methodName, method, classes) ``` -------------------------------- ### Attempting to Define New Object Members (Error) in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classCreation.md This example highlights a limitation in Class++: new members cannot be defined directly on an object after its creation. Attempting to assign a value to a non-existent member like 'Personality' will result in an error, emphasizing that members must be pre-defined in the class. ```Lua local class = ClassPP.class local person = class "Person" { Public = { Name = "", Age = 0 } } local newPerson = person.new() newPerson.Personality = "Cheerful" -- This will error! This class has no member named "Personality". ``` -------------------------------- ### Defining and Using Friend Access Specifier in ClassPP (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/friendAccessSpecifier.md This Lua snippet demonstrates how to define and use the `Friend` access specifier within the ClassPP framework. It shows a `getLicensePlate` function, declared as a friend, accessing the `License_Plate` private member of the `Car` class. The example illustrates that friend functions operate on class instances to access private data. ```Lua local function getLicensePlate(object: any) print(object.License_Plate) end local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", }, Private = { License_Plate = "XXXX" }, Friend = { getLicensePlate } } local newCar = Car.new() getLicensePlate(newCar) ``` -------------------------------- ### Creating a Class Without Syntax Sugar (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/class.md This snippet illustrates how to create a new class using `classpp.class` by explicitly calling the function with the class name and then passing the `classData` table as a separate function call. This method achieves the same result as the default syntax but without the syntactic sugar. ```Lua local Class = class("Class")({ constructor = function(self) ... end, destructor = function(self) ... end, Public = { ... }, Private = { ... }, Protected = { ... }, Friend = { ... } }) ``` -------------------------------- ### Creating and Calling a Static Function in Class++ Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/staticMembers.md This snippet demonstrates how to define a static function using `Test.static("Public", "StaticTestValue", function(...))` and how to correctly invoke it directly on the class (`Test.StaticTestValue("Hi!")`). It also highlights that static functions cannot be called on class instances. ```Lua local class = ClassPP.class local Test = class "Test" { Public = { TestValue = 0 } } Test.static("Public", "StaticTestValue", function(firstArgument) print(firstArgument) -- This will not point to any object, instead it will print whatever it is called with! In this case, it will print "Hi!". end) local newTest = Test.new() newTest:StaticTestValue() -- This will error! Test.StaticTestValue("Hi!") -- This will work fine! ``` -------------------------------- ### Defining and Accessing a Static Property in Class++ Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/staticMembers.md This snippet illustrates how to declare a static property with an initial value using `Test.static("Public", "StaticTestValue", 1)`. It then shows two ways to retrieve the value of this static property: `Test.StaticTestValue.property` and its shorthand `Test.StaticTestValue.p`. ```Lua local class = ClassPP.class local Test = class "Test" { Public = { TestValue = 0 } } Test.static("Public", "StaticTestValue", 1) print(Test.StaticTestValue.property) -- Prints "1"! print(Test.StaticTestValue.p) -- Also prints "1"! ``` -------------------------------- ### Implementing Inheritance with Polymorphism in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/polymorphism.md This snippet demonstrates polymorphism through inheritance using the ClassPP library in Lua. It defines a base `Animal` class with an `animalSound` method, and then creates derived `Pig` and `Dog` classes that override this method. This allows different animal types to respond to the same `animalSound` call with their specific sounds, showcasing how objects of different types can be accessed through a common interface. ```lua local class = ClassPP.class local Animal = class "Animal" { Public = { animalSound = function(self) print("The animal makes a sound") end } } -- Derived class local Pig = Animal.extends "Pig" { Public = { animalSound = function(self) print("The pig says: oink oink") end } } -- Derived class local Dog = Animal.extends "Dog" { Public = { animalSound = function(self) print("The dog says: woof woof") end } } ``` -------------------------------- ### Defining the classpp.class Function Signature (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/class.md This snippet shows the function signature for `classpp.class`, which is used to create a new class. It takes a class name as a string and returns a function that accepts a `classData` table to define the class structure. ```Lua function classpp.class(className: string): (classData: classData) -> class ``` -------------------------------- ### Implementing Function Overloading with Polymorphism in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/polymorphism.md This snippet illustrates function overloading using the ClassPP library in Lua. It defines a `Test` class and uses `Test.overload` to create multiple `Display` methods that share the same name but accept different numbers of arguments. This demonstrates how a single function name can perform different actions based on the input parameters, embodying the 'many forms' aspect of polymorphism. ```lua local class = ClassPP.class local Test = class "Test" {} Test.overload("Public", "Display", { function(self, number1) print("Number: ", number1) end, function(self, number1, number2) print("Numbers: ", number1, number2) end }) ``` -------------------------------- ### Defining a Class with Class++ in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classCreation.md This snippet demonstrates how to define a new class named 'Person' using the `ClassPP.class` function. It initializes public members 'Name' and 'Age' with default values, serving as a blueprint for objects. ```Lua local class = ClassPP.class local person = class "Person" { Public = { Name = "", Age = 0 } } ``` -------------------------------- ### Defining ClassPP getClass Function (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/getClass.md This snippet presents the function signature for `classpp.getClass`, illustrating its type definition. It specifies that the function accepts a `className` of type `string` and returns an object of type `class`, outlining the function's interface. ```Lua function classpp.getClass(className: string): class ``` -------------------------------- ### Defining classpp.abstract Function Signature - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/abstract.md This snippet shows the function signature for `classpp.abstract`, indicating it takes a table of classes and returns a single class. It's used to mark one or more classes as abstract, returning the first class if multiple are provided. ```Lua function classpp.abstract(classTable: {class}): class ``` -------------------------------- ### Default Syntax: Marking a Class Final (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/final.md This snippet demonstrates the default syntax for using `classpp.final` to mark a new class named 'Car' as final. It shows how to define a class inline and pass it to the `final` function using syntax sugar. ```lua local Car = final { class "Car" { Public = { ... }, ... }} ``` -------------------------------- ### Creating a Custom Class Type for Full Auto-completion - Luau Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/types.md This snippet shows how to define a custom Luau type 'Person' that mirrors the class structure, including private members. By explicitly typing the new class instance with this custom type, it enables full auto-completion for all members, both public and private. It demonstrates the `type` keyword and type annotation for class instances. ```Luau local class = ClassPP.class type Person = { Age: number, Name: string, Personality: string, Job: string, Secrets: {string}, Likes: {string}, Dislikes: {string}, getSecrets: (self: Person) -> {string} } local Person = class "Person" { Public = { Age = 0, Name = "", Personality = "", Likes = {}, Dislikes = {}, Job = "", getSecrets = function(self: Person) return self.Secrets end, }, Private = { Secrets = {} } } local newPerson: Person = Person.new() -- This object now fully supports auto-completion! ``` -------------------------------- ### Overloading the Addition Operator for a Vector Class in Class++ (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/operatorOverloading.md This snippet demonstrates how to define a custom Vector3 class in Class++ (Lua) and overload the addition operator (`+`) using the `operator_add` method. It also includes a `__tostring` method for string representation and shows how to instantiate Vector objects and use the overloaded operator. ```Lua local class = ClassPP.class local Vector = class "Vector3" { constructor = function(self, x: number, y: number, z: number) if typeof(x) ~= "number" or typeof(y) ~= "number" or typeof(z) ~= "number" then self.coordinates = {0, 0, 0} return end self.coordinates = {x, y, z} end, Public = { coordinates = {0, 0, 0}, }, } function Vector.Public:operator_add(otherVector) assert(#self.coordinates == #otherVector.coordinates) local coordinates = {} for i = 1, #self.coordinates do coordinates[i] = self.coordinates[i] + otherVector.coordinates[i] end return Vector.new(coordinates[1], coordinates[2], coordinates[3]) end function Vector.Public:__tostring() return "(" .. table.concat(self.coordinates, ", ") .. ")" end local vector1 = Vector.new(4, 5, 2) local vector2 = Vector.new(1, 2, 3) print(vector1 + vector2) -- Prints "(5, 7, 5)" ``` -------------------------------- ### Without Syntax Sugar: Marking a Class Final (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/final.md This snippet illustrates the usage of `classpp.final` without syntax sugar, explicitly showing the function calls and table constructors. It achieves the same result as the default syntax, marking the 'Car' class as final. ```lua local Car = final({class("Car")({ Public = { ... }, ... })}) ``` -------------------------------- ### Defining Class Method Outside Class Definition - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classMethods.md This snippet demonstrates defining a class method, `getLicensePlate`, outside of the class's initial definition using the `function Class.:` syntax. This approach allows for better code formatting and does not require pre-declaration of the function within the class. ```Lua local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", }, Private = { License_Plate = "XXXX" } } function Car.Public:getLicensePlate(number) print(self.License_Plate, number) -- Prints "XXXX 1"! end local newCar = Car.new() newCar:getLicensePlate(1) ``` -------------------------------- ### Defining an Abstract Class in ClassPP (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/nonAccessSpecifiers.md This snippet illustrates the creation of an abstract class using ClassPP's 'abstract' specifier. Abstract classes cannot be instantiated directly, as shown by the 'newBaseCarObj' attempt. They are designed to be inherited by other classes, providing a base structure that subclasses can extend and instantiate, like 'Car'. ```lua local class, abstract = ClassPP.class, ClassPP.abstract local BaseCar = abstract { class "BaseCar" { Public = { Brand = "", Model = "", Year = 0, honk = function(self) print("honk honk!") end } }} local Car = BaseCar.extends "Car" { Public = { Brand = "Ford", Model = "Mustang", Year = 2023 } } local newBaseCarObj = BaseCar.new() -- This will error! local newCarObj = Car.new() -- This will work fine! newCarObj:honk() ``` -------------------------------- ### Defining a Class Destructor in ClassPP (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classConstructors.md This snippet demonstrates how to implement a destructor in ClassPP. The `destructor` function is automatically called when `:Destroy()` is invoked on an object, allowing for cleanup operations like resetting member values before the object is garbage collected, preventing potential memory leaks. ```Lua 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) newCar:Destroy() -- The class object will now be destroyed newCar = nil ``` -------------------------------- ### Defining a Class with Limited Auto-completion - Luau Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/types.md This snippet defines a 'Person' class using Class++ with public and private members. It demonstrates the basic class structure, but notes that auto-completion is limited to public members without a custom Luau type. It initializes a new instance of the class. ```Luau local Person = class "Person" { Public = { Age = 0, Name = "", Personality = "", Likes = {}, Dislikes = {}, Job = "", getSecrets = function(self: Person) return self.Secrets end, }, Private = { Secrets = {} } } local newPerson = Person.new() -- This only supports auto-completion of the members in the Public access specifier! ``` -------------------------------- ### Using checkInheritance for Classes and Methods in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/util/checkInheritance.md This snippet demonstrates the default syntax for calling `ClassPP.Util.checkInheritance`. It shows two use cases: checking inheritance between two classes (`classOne`, `classTwo`) and checking if a class inherits a specific method (`class`, `method`). The result is stored in `isInherited`. ```Lua local isInherited = ClassPP.Util.checkInheritance(classOne, classTwo) -- For classes local isInherited = ClassPP.Util.checkInheritance(class, method) -- For methods ``` -------------------------------- ### Function Signature for checkFriendship - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/util/checkFriendship.md This snippet shows the full function signature for `Util.checkFriendship`. It defines the parameters `class`, `methodName`, `method`, and `classes`, along with their respective types, and specifies that the function returns a boolean value. This signature is crucial for understanding the function's expected inputs and output. ```Lua function Util.checkFriendship(class: class, methodName: string, method: () -> (), classes: {[string]: class}): boolean ``` -------------------------------- ### Function Signature: classpp.final (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/mainModule/final.md This is the function signature for `classpp.final`, indicating it takes a table of classes (`classTable`) and returns a single class. It's used to mark classes as final, preventing further inheritance. ```lua function classpp.final(classTable: {class}): class ``` -------------------------------- ### Implementing Single Inheritance with Class++ in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/inheritance.md This snippet demonstrates basic single inheritance in Class++. It defines a `Vehicle` base class and a `Car` derived class that extends `Vehicle`. The `Car` class overrides the `License_Plate` member while inheriting `Brand`, `Model`, `Year`, and the `honk` function from `Vehicle`. This showcases code reusability and member overriding. ```Lua 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 = Vehicle.extends "Car" { -- 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"! ``` -------------------------------- ### Defining a Basic Class Method Inside Definition - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classMethods.md This snippet demonstrates defining a `getLicensePlate` function directly within the `Public` section of a `Car` class using ClassPP. The function accesses a private member `License_Plate` via `self`, which is implicitly the first argument for all class methods. ```Lua local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", getLicensePlate = function(self) print(self.License_Plate) end }, Private = { License_Plate = "XXXX" } } ``` -------------------------------- ### Type.typeof Function Signature - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/type/typeof.md This snippet presents the function signature for `Type.typeof`, showing that it accepts an `object` of any type and returns a `string`. This signature is crucial for understanding the function's interface and its role in type introspection. ```Lua function Type.typeof(object: any): string ``` -------------------------------- ### Defining Util.inClassScope Function Signature in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/util/inClassScope.md This snippet presents the full function signature for `Util.inClassScope`. It outlines all parameters, including `class`, `includeInherited`, `includeFriend`, an optional `classes` table, and an optional `defaultLevel`, along with its boolean return type. This function is designed to check access permissions within a class scope. ```Lua function Util.inClassScope(class: class, includeInherited: boolean, includeFriend: boolean, classes: {[string]: class}?, defaultLevel: number?): boolean ``` -------------------------------- ### Defining the classData Type in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/types/classData.md This Lua type definition outlines the structure for the `classData` table, which is passed to the `class()` function. It specifies optional fields for a `constructor` and `destructor` function, and tables for `Public`, `Private`, `Protected`, and `Friend` access specifiers, allowing for detailed class property and method organization. ```Lua export type classData = { constructor: (self: any, ...any) -> ()?, destructor: (self: any) -> ()?, Public: {[any]: any}?, Private: {[any]: any}?, Protected: {[any]: any}?, Friend: {any}? } ``` -------------------------------- ### Defining checkInheritance Function in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/util/checkInheritance.md This snippet defines the `checkInheritance` function within the `Util` module. It takes two parameters: a `class` and either another `class` or a `method` (function). The function returns a boolean indicating the inheritance status. ```Lua function Util.checkInheritance(class: class, classOrMethod: class | () -> ()): boolean ``` -------------------------------- ### Updating Object Member Values in Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/classCreation.md This snippet illustrates how to modify the value of an existing member of an object. After creating a 'newPerson' object, its 'Age' member is updated to '21', and the change is verified by printing the new value. ```Lua local class = ClassPP.class local person = class "Person" { Public = { Name = "", Age = 0 } } local newPerson = person.new() newPerson.Age = 21 print(newPerson.Age) -- Prints "21"! ``` -------------------------------- ### Declaring Private Members and Access Restrictions in Class++ (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/accessSpecifiers.md This snippet illustrates the declaration of a private member 'License_Plate' in a Class++ class using Lua. It highlights that private members are only accessible from within the class itself, and attempting to access or modify them from an external instance will result in an error, enforcing encapsulation. ```Lua 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! ``` -------------------------------- ### Defining a Final Class in ClassPP (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/nonAccessSpecifiers.md This snippet demonstrates how to define a final class using ClassPP's 'final' specifier. A final class cannot be inherited by other classes, as shown by the 'BiggerCar' attempt which will result in an error. This is useful for preventing further extension of a class. ```lua local class, final = ClassPP.class, ClassPP.final local Car = final { class "Car" { Public = { Brand = "Ford", } }} local BiggerCar = Car.extends "BiggerCar" { -- This will error! Public = { Brand = "Tesla" } } ``` -------------------------------- ### Declaring and Accessing Public Members in Class++ (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/accessSpecifiers.md This snippet demonstrates how to declare a public member 'Brand' within a Class++ class in Lua. It shows that public members are freely accessible and modifiable from outside the class instance, allowing direct assignment to change their values. ```Lua local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", } } local newCar = Car.new() newCar.Brand = "Tesla" ``` -------------------------------- ### Using Protected Access Specifier in Class++ Inheritance (Lua) Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/tutorials/inheritance.md This snippet demonstrates the `Protected` access specifier in Class++. It defines a `Car` class with a `Protected` `License_Plate` member. A `BiggerCar` class extends `Car` and can access the `Protected` `License_Plate` member through its own member function, `printLicensePlate`. This highlights how `Protected` members are accessible to derived classes but not directly from outside the class hierarchy. ```Lua local class = ClassPP.class local Car = class "Car" { Public = { Brand = "Lamborghini", }, Protected = { License_Plate = "XXXX" } } local BiggerCar = Car.extends "BiggerCar" { Public = { Brand = "Tesla" } } function BiggerCar.Public:printLicensePlate() print(self.License_Plate) -- Will print "XXXX"! end local newCar = BiggerCar.new() newCar:printLicensePlate() ``` -------------------------------- ### Default Usage: ClassPP.Type.typeofClass - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/type/typeofclass.md This snippet illustrates the standard way to call the `typeofClass` function. It demonstrates how to pass a `classObject` to the function and store the returned class type string in a local variable named `objectType`. ```Lua local objectType = ClassPP.Type.typeofClass(classObject) ``` -------------------------------- ### Function Signature: Type.typeofClass - Lua Source: https://github.com/tenebrisnoctua/classpp/blob/main/docs/apiReference/classFunctions/type/typeofclass.md This snippet presents the function signature for `Type.typeofClass`. It indicates that the function accepts an argument named `classObject` of any type and is expected to return a `string` value, representing the class type. ```Lua function Type.typeofClass(classObject: any): string ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.