Skip to main content

Overview

@realm sets the realm for a file or function. GLuaLS checks it before filename, folder, and if CLIENT/SERVER inference.

Syntax

---@realm client
---@realm server
---@realm shared

File-level realm

File-level realm annotations are experimental. Use them only when GLuaLS infers the wrong realm for the whole file. Prefer function-level annotations for mixed files.
Place @realm at the top of a file to mark the whole file:
---@realm client

-- GLuaLS treats everything in this file as client-side
surface.DrawRect(0, 0, 100, 100)  -- ✅ no realm mismatch warning

ply:SetHealth(100)  -- ❌ server-only function in a client file

Function-level realm

Set the realm for one function inside a shared file:
-- This is a shared file (no top-level @realm)

---@realm server
function MyAddon.KickPlayer(ply, reason)
    ply:Kick(reason)
end

---@realm client
function MyAddon.ShowNotification(msg)
    notification.AddLegacy(msg, NOTIFY_GENERIC, 5)
end

Realm values

ValueDescription
clientClientside (runs in the CLIENT state)
serverServerside (runs in the SERVER state)
sharedBoth client and server

When @realm is missing

GLuaLS detects realm from:
  • Filename prefix (cl_*, sv_*, sh_*)
  • Directory (client/, server/, lua/autorun/client/, etc.)
  • if CLIENT / if SERVER blocks
Complex files can confuse realm detection.

See also