Skip to main content

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

  • 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:
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:

Specifying name argument position

If the name is not the first argument:

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