MacroError
UpdatedThe rule behind this error is on the Macros page.
macro name(params) ... end export macro logit(x) print(x) end import { logit } from "./mac"
A compile-time template with expression parameters, called as $name(...). Every local in the body is renamed per expansion. A parameter takes a default, macro sum(a, b = 2), and ... makes the macro variadic. A body that assigns a parameter assigns the name the caller passed: with macro swap(a, b) a, b = b, a end, $swap(x, y) writes x and y. A const there is an error, and prefer_const leaves those names local.
A namespace holds a macro. Inside the group the bare name calls it; outside it reads as $Name.twice(x), and $Outer.Inner.twice(x) through a nested namespace. A private one stays inside the group.
export macro sends the template out and import { logit } brings it in, under the name this file binds; as renames it. export { logit } sends out a macro the file declares or imports, and export { logit } from "./mac" passes one on. A macro is source, not a value, so nothing lands in the module's table and the import binds no local.
The body sees its parameters and the globals of the file it expands in. A name the defining file binds, an import or a local, does not travel with the macro: the expansion reads it as a global where it lands, and alloy flux reports it as an unknown global at the call. A macro that has to reach another module takes the value as a parameter. A macro cannot call itself: the expansion is textual, and it stops at depth 16 with a MacroError. In an expression, a value of more than one term lands in parentheses, so 10 / $sq(2) divides by the whole square.
The word is also free as a name. macro declares only before a name on the same line, so local macro = 1 and t.macro read the Luau way.
