lloyAlloy on GitHub
Standard library
Docs

Standard library

Updated

A file imports each std name it uses, from the module that holds it:

import { HashMap, Set } from "@alloy/std/collections"
import { Serialize, Deserialize } from "@alloy/std/serde"

@derive(Serialize, Deserialize)
struct Save
    coins: number
end

local owners = new HashMap<<string, Save>>()

The modules:

@alloy/std/collections  HashMap Set BitSet Queue Heap Array Symbol
@alloy/std/iter         Iter
@alloy/std/result       Result Ok Err
@alloy/std/async        Future Scope
@alloy/std/signal       Signal SignalConnection Signalish
@alloy/std/traits       Display Debug Clone Default Eq PartialEq Ord Add Sub Mul Div
@alloy/std/serde        Serialize Deserialize
@alloy/std/types        Partial Readonly Sink
@alloy/std/roblox       R15Character R6Character Attributes

@alloy/std alone holds every name, and import * as c from "@alloy/std/collections" binds a module, so c.HashMap reads the value and the type. An alias, import { HashMap as Map }, binds the name under the alias. An import writes nothing to the output: the emit reaches every std name through the runtime, so an import and an ambient name compile to the same Luau.

The names the language owns need no import: Future, Result, Ok, Err, Array, and the traits of @alloy/std/traits. A keyword, a literal, or an operator writes them: async returns a Future, try gives a Result, [ ] builds an Array, and ==, <, +, and tostring call the traits.

[std] globals sets the rest:

alloy.tomlalloy.toml
[std]
globals = "none"               # the default: a file imports each name
# globals = "all"              # every std name is ambient
# globals = ["Signal", "Iter"]  # these names are ambient

A name the file does not reach reports an ImportError that names the line to write, once per name. alloy flux --fix writes every missing import. The editor offers the same fix, and a completion of a std name writes its import.

ArrayThe array type of the std: a Luau array with the std's methods on its metatable.Literals carry the shared metatable: len, push, pop, first, last, map, filter, find, find_index, contains, index_of, for_each, reduce, slice, concat, reverse, sort_by, join; from, new, with_capacity.AttributesDeclared metadata, readable at runtime.get, field, variant, of, fields: the metadata attributes declared.BitSetA set of whole numbers from 0 up, from the std, with one bit per number in a buffer.ErrThe failure case of a Result.FutureA memoized task, from the std: it runs once, settles once, and every await after that reads the same value.async functions return one; resolve, reject, delay, all, race, any, all_settled; andThen, cancel, is_settled.HashMapA map with methods, from the std.get, set, has, remove, len, keys, values, entries, get_or_insert, clear; from.HeapA binary heap, from the std: pop yields the least value under less, which defaults to <, so numbers and strings need no comparator and tables take one.push, pop, peek, len, is_empty, clear under a comparator; to_array sorts; from.IterA lazy iterator, from the std: each step wraps the last, and nothing runs until collect, for_each, a reducer, or a for loop pulls.from, range, next, map, filter, take, skip, take_while, chain, collect, for_each, count, any, all, find, reduce, first, last.OkThe success case of a Result.PartialEvery field of T, optional.Mapped types built by type functions, overridable per file.QueueA first-in, first-out queue over a ring of indices, from the std: push at the back costs the same at any size, and so does pop at the front.push, pop, peek, len, is_empty, clear, to_array; a for loop reads it front to back.R15CharacterThe character a player spawns on the R15 rig: a Model with HumanoidRootPart as a Part?, each of the fifteen body parts as a MeshPart?, Humanoid with its Animator and HumanoidDescription, BodyColors, and the Animate and Health scripts.R6CharacterThe character a player spawns on the R6 rig: a Model with HumanoidRootPart, Head, Torso, and the four limbs as a Part? each, Humanoid with its Animator and HumanoidDescription, BodyColors, and the Animate and Health scripts.ReadArrayThe array a read T[] names: every reader of Array<T> and none of its writers.What read T[] and write T[] name: the readers alone, or push alone.ReadonlyEvery field of T, read only.ResultOk(value) or Err(error), from the std.Ok and Err with unwrap, expect, unwrap_or, map, map_err, is_ok, is_err, ok; try and ? for early returns; Result.pcall.ScopeA cleanup bag, from the std.add, remove, clean, extend, len; a cleanup bag that delete drains.SetA set with methods, from the std.add, has, remove, len, union, intersection, difference, to_array; from.SignalA typed signal, from the std, with the shape of RBXScriptSignal, so code that takes one takes the other.Connect, Once, Wait, Fire, FireDeferred, DisconnectAll, Destroy, each with a snake_case twin; wrap and collect for any signal-like source.SinkEvery field of T, write only.SymbolA unique key that no string can collide with, from the std: a frozen table that prints as Symbol(name).A unique key no string can collide with.TraitsThe trait shapes the std exports, for a bound and for impl X for Struct.Add, Sub, Mul, Div, Eq, PartialEq, Ord, Display, Debug, Clone, Serialize: the shapes a bound names.WriteArrayThe array a write T[] names: push and the index, nothing that reads.