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. Leave it out to type the argument itself.Type— the type the field will have after the call.
Typing the argument itself
Leave off the field path when the function fills in the table you pass, instead of a field inside it:Basic usage
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:
Only applies after the call
The outparam type takes effect after the function runs, not before:Conditional calls
Inside anif block, the type only applies in the branch where the call happens:
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: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
@paramon 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: