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

# @accessorfunc

> Mark a function that creates matching getter and setter methods.

## Overview

`@accessorfunc` marks a function as an accessor generator. When you call that function, GLuaLS creates `GetPropertyName()` and `SetPropertyName()` methods on the target class. This matches GMod's built-in `AccessorFunc()`.

***

## Syntax

```lua theme={null}
---@accessorfunc
---@accessorfunc N
```

* Without `N`: the first argument of the call is treated as the accessor name
* `N`: a 1-indexed position for the argument that provides the accessor name

***

## How it works

When GLuaLS sees a call to a function marked with `@accessorfunc`, it generates accessor methods on the object:

```lua theme={null}
-- Built-in AccessorFunc is annotated with @accessorfunc 3
AccessorFunc(ENT, "m_bOrient", "Orient", FORCE_BOOL)

-- GLuaLS synthesizes:
-- ENT:GetOrient() -> any
-- ENT:SetOrient(value: any) -> nil
```

GLuaLS types getter and setter values as `any`. Future versions will infer stronger types from the backing field.

***

## Custom accessor generators

If you write your own accessor generator, annotate it with `@accessorfunc`:

```lua theme={null}
---@accessorfunc
function ENT:RegisterProperty(name)
    -- internally sets up getter and setter
end

function ENT:SetupDataTables()
    self:RegisterProperty("Health")   -- adds GetHealth(), SetHealth()
    self:RegisterProperty("Armor")    -- adds GetArmor(), SetArmor()
end
```

***

## Specifying name argument position

If the name is not the first argument:

```lua theme={null}
---@accessorfunc 3
function ENT:RegisterTypedProperty(varType, slot, name)
    -- varType = "Int", slot = 0, name = "Health"
end

function ENT:SetupDataTables()
    self:RegisterTypedProperty("Int", 0, "Health")  -- adds GetHealth(), SetHealth()
end
```

***

## Limits

* Getters return `any` and setters accept `any` unless another annotation provides a more specific type.
* The annotation works on any class, not only GMod scripted entities.

***

## See also

* [NetworkVar methods](/language/scripted-classes#networkvar-methods) - how `self:NetworkVar(...)` creates typed accessors
