Overview
@class defines a named type that other annotations can use. Classes support inheritance, generic type parameters, access control, and field definitions.
Syntax
Basic class
Inheritance
Use: ParentClass to extend another class. The child class gets the parent’s fields and methods.
Multiple inheritance
Exact classes
Mark a class as(exact) to prevent dynamic field additions. GLuaLS can report a diagnostic when code assigns a field outside the class definition:
In GLuaLS, this annotation has no effect. GLuaLS treats all classes as partial by default and turns related diagnostics off. GLuaLS keeps it for EmmyLua compatibility.
Partial classes
(partial) extends an existing class without relisting all fields:
In GLuaLS, this annotation has no effect. GLuaLS treats all classes as partial by default and turns related diagnostics off. GLuaLS keeps it for EmmyLua compatibility.
Generic classes
Add type parameters with angle brackets. You can use type parameters in field types:Field access control
Use access modifiers in@field:
Access modifiers are optional. They affect type checking only, not runtime behavior. GLuaLS checks them and can report diagnostics when code uses private or protected fields from the wrong place.
Attaching a class to a local variable
When you place---@class above a local statement, GLuaLS types that variable as an instance of the class:
@type: