Overview
Garry’s Mod uses a “scripted class” pattern. You define a global table, such asENT or SWEP, in a specific file location, and GMod registers it as a class. GLuaLS detects these classes and provides:
- Class registration including inheritance
- Synthesis of
NetworkVargetter/setter pairs - Synthesis of
AccessorFuncgetter/setter pairs - Better completions and type checking for scripted class code
Automatic detection
GLuaLS detects the standard class table from the file’s project folder. For example:
GLuaLS types the detected class table with the base class’s methods and fields, so you get completions and type checking without annotations.
Schemas work automatically for any framework or gamemode. GLuaLS treats
SCHEMA and Schema as aliases for one global schema table, merges members declared across schema files, and exposes gamemode hooks inherited from GM. The schema remains available to files outside the schema/ directory, matching the usual runtime behavior of global schema systems.
Player classes, plugins, and custom project layouts are also supported through the scripted class settings.
AccessorFunc methods
AccessorFunc(table, member, name, ...) creates getter and setter methods. GLuaLS adds those methods to completion and type checking:
---@accessorfunc annotation for custom getters and setters. See @accessorfunc for details.
NetworkVar methods
ENT:NetworkVar(type, slot, name, ...) creates entity accessors. GLuaLS adds the matching methods:
Supported NetworkVar types
Base class inheritance
Scripted classes in GMod inherit from base classes. GLuaLS understands this chain and suggests inherited methods. The scripted class table also gets the standard base type for that scope, such asEntity, Weapon, or Tool. DEFINE_BASECLASS(...) and values like ENT.Base can refine that type further.
Hook overrides in scripted classes
GLuaLS treats functions defined in a scripted class table as engine hook overrides for that class:Class Explorer integration
The VS Code Class Explorer lists detected scripted classes. You can browse groups, such as entities, weapons, effects, and custom scopes, and jump to class definitions. Class grouping and labels come fromgmod.scriptedClassScopes.include.
Scaffolding integration
Scripted class scopes also control class scaffolding. Each scope can define scaffold output files withscaffold.files and a rootDir in gmod.scriptedClassScopes.include.
You can create new classes with your own template layout while GLuaLS keeps class analysis, explorer grouping, and generated files in sync.
See Garry’s Mod settings for all supported fields.
Creating a new class
- Open the Class Explorer in the sidebar.
- Find the group you want, such as Entities.
- Click the + button next to that group.
- Enter the class name.
- The VS Code extension creates the files and opens the main file.
Built-in templates
The VS Code extension includes built-in templates for the standard scripted class types:Custom class scopes
If you use a non-standard directory structure or custom class types, configure GLuaLS to recognize them:.gluarc.json
Fields
Disabling a scripted class group
To disable a built-in scripted class scope, add an override with the sameid and set "disabled": true.
.gluarc.json