Skip to main content

Overview

Some functions write results into a table you pass in, instead of returning them. @outparam tells GLuaLS which field gets filled in, so you get proper types and autocomplete after the call. util.TraceLine is a common GMod example: it writes its result into the output field of the table you give it.

Syntax

  • paramName — a parameter on the same function (must match an @param).
  • fieldPath — the field the function writes to. Use dots for nested fields.
  • Type — the type the field will have after the call.

Basic usage

After the call, the output field is typed as TraceResult:

Nested fields

Use dots to target a field inside a field:

Multiple output fields

One @outparam per field the function writes to:

The field must already exist

@outparam narrows the type of a field already on the table. It does not create missing fields. If the field is absent, it stays nil after the call:
Set the field before the call, either in the literal or with an assignment:

Only applies after the call

The outparam type takes effect after the function runs, not before:

Conditional calls

Inside an if block, the type only applies in the branch where the call happens:
Short-circuit expressions like false and util.TraceLine(data) skip the type, because the call might never run.

Aliasing

Pass a different variable pointing to the same table and GLuaLS tracks it:
Reassign the alias before the call and the link breaks:

Duplicate tags

Two @outparam tags for the same field: the second one wins.

Errors

GLuaLS shows an error when:
  • The parameter name doesn’t match any @param on the function.
  • You skip the field path (you can’t target the parameter itself).

@outparam vs @return

@return covers values the function returns. @outparam covers values the function writes into a table argument. A function can use both: