Overview
Garry’s Mod Lua runs in two realms: client (CLIENT) and server (SERVER). Code that runs in both is called shared.
Many GMod API functions only exist in one realm (for example, LocalPlayer() is client-only). Calling them in the wrong realm is a common bug.
GLuaLS works out where each file and code block runs, then reports realm-restricted calls that cannot run there.
Realm detection
GLuaLS combines file names, project folders, load calls, code branches, and annotations. Most projects need no extra setup.@realm annotations
Put ---@realm at the top of a file or on a function:
@realm annotation reference for full syntax. A function annotation can be more specific than its file.
File names
GLuaLS assigns realms to files that begin withcl_, sv_, or sh_:
Project folders
GLuaLS assigns realms to files in common GMod directories:
This works for both common workspace layouts:
- Garry’s Mod root:
addons/<name>/lua/...andgamemodes/<name>/... - Addon or gamemode root:
lua/...,gamemode/..., andentities/...
CLIENT and SERVER branches
Within shared files, GLuaLS narrows realm within if CLIENT / if SERVER blocks:
Load calls
When call-based detection is on, GLuaLS also looks at file-loading calls:AddCSLuaFile("file.lua")marks that file as ClientAddCSLuaFile()(no args) adds a Shared hint to the current file (stronger filename/path hints can still resolve as Client or Server)IncludeCS("file.lua")is treated likeAddCSLuaFile("file.lua")+include("file.lua")IncludeCS()with no filename is ignoredrequire("mod")marks the required module as Sharedinclude("file.lua")passes realm hints to the included file
AddCSLuaFile does not mark the caller as server. It only affects the target file.
These rules also apply to annotated wrappers. GLuaLS can follow common file.Find loader loops too, including wrappers described by the GMod annotations.
See @call_arg for wrapper examples.
Loading defaults
Default path-based realm rules follow Garry’s Mod’s usual loading conventions and similar addon patterns. See Lua Loading Order for reference.Realm diagnostics
Disabling realm checks
Disable realm diagnostics workspace-wide:.gluarc.json
Per-function realm overrides
Override or set realm detection for an individual function:Realm in hover and autocomplete
GMod API hovers and completions show where a symbol is available:- Client badge: function is clientside only
- Server badge: function is serverside only
- Shared badge: function is available on both realms