Skip to content

Attributes

Luau supports a set of built-in attributes that can be applied to function declarations to adjust the behavior of the compiler, type analysis, or runtime. This page documents all available attributes and their parameters. Attributes are not user-definable.

For an overview of attribute syntax, see the syntax reference.

@native requests that the function be compiled with native code generation, which can improve performance for compute-heavy functions. It is the function-level equivalent of the --!native script directive, and takes no parameters.

@native does not apply recursively to functions defined inside the annotated function; inner functions must be marked separately:

@deprecated marks a function as deprecated. The linter will warn whenever a deprecated function is called, and the LSP will display it in a visually distinct style in autocompletion.

To provide more helpful warning messages, use the parameterized form with use (the recommended replacement) and reason (an explanation):

Both parameters are optional. The resulting warning messages follow this format:

AttributeWarning message
@deprecatedFunction 'oldApi' is deprecated.
@[deprecated {reason = "..."}]Function 'oldApi' is deprecated. <reason>
@[deprecated {use = "newApi()"}]Function 'oldApi' is deprecated, use 'newApi()' instead.
@[deprecated {use = "newApi()", reason = "..."}]Function 'oldApi' is deprecated, use 'newApi()' instead. <reason>

If the deprecated function is a member of a table or class, the warning message uses Member 'class.func' is deprecated instead of Function 'func' is deprecated.

The @[name(...)] syntax is used for attributes that accept parameters. Parameters are literal values — nil, booleans, numbers, strings, or table constructors. Multiple attributes can be grouped inside a single @[]:

@attr, @[attr], and @[attr()] are all equivalent. For single-parameter attributes whose argument is a string or table, the parentheses are optional: