Skip to main content

Overview

@param declares the type and optional description of each function parameter. Place one @param per parameter, directly above the function definition.

Syntax

---@param paramName type [description]
---@param paramName? type [description]

Basic usage

---@param name string The player's display name
---@param age number The player's age
function createUser(name, age) end

Optional parameters

Add ? after the name to mark the parameter as nil in some calls:
---@param damage number Base damage to deal
---@param attacker? Entity The attacking entity (may be nil)
function TakeDamage(victim, damage, attacker) end

Union types

---@param id string | number User ID (string or numeric)
function GetUser(id) end

Variadic parameters

Use ... as the parameter name for variadic arguments:
---@param format string Format string
---@param ... any Additional arguments
function printf(format, ...) end

Function-type parameters

---@param callback fun(ply: Player, data: table): boolean
function RegisterCallback(callback) end

Table-type parameters

---@param options { maxHealth: number, armor?: number, speed: number }
function SpawnWithOptions(options) end

Generic parameters

---@generic T
---@param items T[]
---@param predicate fun(item: T): boolean
---@return T[]
function filter(items, predicate) end

String-template generic parameters

Use backticks when the parameter is a class-name string:
---@generic T : Entity
---@param class `T`
---@return T
function ents.Create(class) end
For functions accepting either a class object or class-name string:
---@generic T
---@param name `T`|T
function useClass(name) end
Rule:
  • T treats "some_text" as string
  • `T` treats "some_text" as a class/type name

self parameter

GLuaLS types self as the owning class for methods. Annotate only when you want to be explicit:
---@param self Player
---@param amount number
function Player:GiveMoney(amount) end

Interplay with @fileparam

GLuaLS applies file-level defaults from @fileparam, then workspace defaults from gmod.fileParamDefaults. Explicit @param takes highest priority.