> ## 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.

# @enum

> Mark a Lua table as an enumeration with named values.

## Overview

`@enum` marks a local table as an enum type. Table values become valid enum members. GLuaLS can report invalid enum values with `enum-value-mismatch` when you enable that diagnostic.

***

## Syntax

```lua theme={null}
---@enum EnumName
---@enum (key) EnumName
```

***

## Basic enum

```lua theme={null}
---@enum HTTPStatus
local HTTPStatus = {
    OK = 200,
    NOT_FOUND = 404,
    INTERNAL_ERROR = 500,
    BAD_REQUEST = 400,
    UNAUTHORIZED = 401,
}

---@param status HTTPStatus
function HandleResponse(status)
    if status == HTTPStatus.OK then
        -- ...
    end
end
```

***

## String enums

```lua theme={null}
---@enum GameState
local GameState = {
    WAITING = "waiting",
    ACTIVE = "active",
    ENDED = "ended",
}
```

***

## `(key)` modifier

Use `(key)` when the table **keys** are the enum values:

```lua theme={null}
---@enum (key) Direction
local Direction = {
    north = true,
    south = true,
    east = true,
    west = true,
}

---@type Direction
local d = "north" -- ✅
local d2 = "up"   -- ❌ not a Direction
```

***

## Enum vs. @alias

Both `@enum` and `@alias` with `---|` can describe a fixed set of values. Use:

* `@enum` when your addon has a Lua table of named constants that code reads at runtime
* `@alias` with `---|` when a string parameter accepts a fixed set of text values

***

## Common patterns in GMod

```lua theme={null}
---@enum DAMAGE
local DAMAGE = {
    GENERIC = 1,
    CRUSH = 2,
    BULLET = 4,
    SLASH = 8,
    BURN = 16,
}
```

GMod's built-in enums, such as `DAMAGE`, `TEAM`, and `MOVETYPE`, come from the downloaded annotations. You do not need to redeclare them.
