Skip to main content

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

Do not add file-level realm overrides if inference is already correct. It can hide real cross-realm mistakes. Prefer function-level overrides.
Put ---@realm at the top of a file or on a function:
See the @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 with cl_, 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/... and gamemodes/<name>/...
  • Addon or gamemode root: lua/..., gamemode/..., and entities/...

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 Client
  • AddCSLuaFile() (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 like AddCSLuaFile("file.lua") + include("file.lua")
  • IncludeCS() with no filename is ignored
  • require("mod") marks the required module as Shared
  • include("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 checks only when necessary. Other features depend on realm detection. In most cases, disable only specific diagnostics from settings.
Disable realm diagnostics workspace-wide:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
.gluarc.json
Or set the known realm for a specific file:

Per-function realm overrides

Override or set realm detection for an individual function:
Use function-level annotations when only one function needs a different realm.

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
The badge appears in completions as well, so you can check a function’s realm before inserting it. Realm also filters autocomplete. In client files, server-only functions are hidden (and vice versa). If a function seems missing, check inferred realm first.