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:
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:Current limitations
- Synthesized getters return
anyand setters acceptany; GLuaLS does not infer these types from the field name or var type yet - Works on any class, not just GMod scripted entities
- Not gated by
gmod.enabled
See also
- NetworkVar synthesis - how
self:NetworkVar(...)generates typed accessors