> ## Documentation Index
> Fetch the complete documentation index at: https://gluals.arnux.net/llms.txt
> Use this file to discover all available pages before exploring further.

# @operator

> Declare operator behavior for a class.

## Overview

`@operator` tells GLuaLS what a class supports for operators like `+`, `==`, `#`, indexing, or calling.

Use it in annotation files or class definitions when GLuaLS cannot infer the operator behavior.

***

## Syntax

```lua theme={null}
---@operator op_name(operand_type): return_type
---@operator call: return_type
```

***

## Usage

Add the operator on the class before the local assignment or returned table:

```lua theme={null}
---@class Vector
---@operator add(Vector): Vector
---@operator sub(Vector): Vector
---@operator mul(number): Vector
local Vector = {}

local v1 = Vector()
local v2 = Vector()

-- GLuaLS understands v3 is a Vector because of the add operator
local v3 = v1 + v2
```

***

## Supported operators

* Arithmetic: `add`, `sub`, `mul`, `div`, `mod`, `pow`, `unm` (unary minus)
* Bitwise: `band`, `bor`, `bxor`, `shl`, `shr`, `bnot`
* Other numeric: `idiv`
* Relational: `eq`, `lt`, `le`
* Other: `len` (length operator `#`), `concat` (concatenation `..`), `call`, `index`

`pairs` is accepted in an annotation but does not change the types GLuaLS reports.
