lloyAlloy on GitHub
Attributes
Docs

Attributes

Updated
Attributes
import { Attributes } from "@alloy/std/roblox"

attribute icon(asset: string) on struct, variant

@icon("rbxassetid://1")
struct Sword
    damage: number
end

local asset = Attributes.get(Sword, icon)

Declared metadata, readable at runtime. An attribute declaration binds its name to an Attribute<T> value, so the attr of each static is the name as written, not a string.

An attribute with one parameter reads as that value, several as a table that names them, and none as true.

Statics

Attributes.get

Attributes.get<T>(target: any, attr: Attribute<T>): T?

The value an attribute carries on a function, a struct, or an enum, or nil when it carries none. attr is the declared name, not a string.

import { Attributes } from "@alloy/std/roblox"

attribute icon(asset: string) on struct
@icon("rbxassetid://1")
struct Sword as damage: number end
print(Attributes.get(Sword, icon))

Attributes.field

Attributes.field<T>(struct: any, field: string, attr: Attribute<T>): T?

The attribute's value on one field of a struct, by the field's name.

import { Attributes } from "@alloy/std/roblox"

attribute label(text: string) on field
struct Sword
    @label("Damage") damage: number
end
print(Attributes.field(Sword, "damage", label))

Attributes.variant

Attributes.variant<T>(enum: any, variant: string, attr: Attribute<T>): T?

The attribute's value on one variant of an enum, by the variant's name.

import { Attributes } from "@alloy/std/roblox"

attribute weight(n: number) on variant
enum Drop
    @weight(3) Coin
end
print(Attributes.variant(Drop, "Coin", weight))

Attributes.fields

Attributes.fields<T>(struct: any, attr: Attribute<T>): { [string]: T }

Every field of a struct that carries the attribute, as a table of field name to value.

import { Attributes } from "@alloy/std/roblox"

attribute label(text: string) on field
struct Sword
    @label("Damage") damage: number
end
print(Attributes.fields(Sword, label).damage)

Attributes.of

Attributes.of(target: any): any

Everything declared on the target, as the compiler wrote it. Use it to walk attributes no name is known for.

import { Attributes } from "@alloy/std/roblox"

attribute icon(asset: string) on struct
@icon("rbxassetid://1")
struct Sword as damage: number end
print(Attributes.of(Sword) ~= nil)