---
name: luau-core
description: "Use for idiomatic, correct pure Luau language work focused on syntax, functions, tables, control flow, metatables, standard library behavior, and Lua compatibility details outside Roblox APIs, deep typing, or performance tuning."
luau-core
When to Use
Use this skill when the task is primarily about plain Luau language behavior:
- Writing or fixing pure Luau syntax.
- Choosing idiomatic control flow, variable scope, or function structure.
- Working with tables as arrays, dictionaries, or object-like values.
- Using the standard library correctly.
- Applying metatables for indexing, operators, iteration, or object-like patterns.
- Checking whether a Lua feature or idiom is compatible with Luau.
Do not use this skill when the task is mainly about:
- Luau type annotations, generics, inference, refinements, or strictness policy.
- Profiling, optimization strategy, or performance tradeoffs.
- Roblox engine APIs, services, events, classes, networking, data, or gameplay architecture.
Decision Rules
- Use this skill if the answer can stay within pure Luau syntax, semantics, idioms, and standard library usage.
- If the task centers on type aliases, annotations, generics, exported types, or analyzer behavior, hand off to
luau-types.
- If the task centers on allocation patterns, hot loops, benchmarking, profiling, or optimization strategy, hand off to
luau-performance.
- If the task depends on
game, Instance, services, remotes, datastores, UI, physics, or other Roblox runtime concepts, use the appropriate roblox/* skill instead.
- If a request mixes core language work with out-of-scope topics, answer only the pure Luau portion and explicitly exclude the rest.
- If unsure, prefer the narrower interpretation and omit material that could overlap another skill.
Instructions
- Treat Luau as Lua 5.1 plus selected Luau extensions. Do not assume Lua 5.2+ features unless Luau explicitly supports them.
- Prefer
local variables and local function declarations by default. Use globals only when the broader scope is required by the task.
- Keep control flow direct. Prefer normal
if, elseif, else, loops, break, and continue over clever boolean tricks.
- Use Luau-specific syntax when it improves correctness or readability:
if ... then ... else ... expressions instead of a and b or c ternary emulation.
- Compound assignment such as
+= when the left side should only be evaluated once.
- Generalized iteration
for k, v in table do when iterating a table directly is the clearest form.
- Model tables intentionally:
- Arrays for ordered numeric sequences.
- Dictionaries for keyed lookup.
- Metatable-backed records only when custom behavior materially improves the API.
- Use
: for method definitions and calls that conceptually pass self; use . for plain function access.
- Prefer built-in library functions over handwritten helpers when the standard library already expresses the operation clearly.
- Use metatables sparingly and explicitly. Define only the metamethods needed for the abstraction and avoid surprising behavior.
- When discussing compatibility, call out unsupported assumptions early, such as
goto, bitwise operators, integer-only reasoning, or full Lua standard library access.
- Keep all examples host-agnostic and pure Luau. Do not rely on Roblox engine objects or services.
Using References
- Open
references/getting-started-and-syntax.md for syntax forms, literals, assignments, expression forms, and Luau-only syntax additions.
- Open
references/functions-tables-operators-scope-and-control-structures.md for the core execution model: functions, closures, tables, truthiness, iteration, and control flow.
- Open
references/metatables-and-userdata-concepts.md for metamethod behavior, object-like table patterns, raw operations, and userdata boundaries.
- Open
references/library-and-grammar-reference.md for standard-library selection and compact grammar reminders for statements and expressions.
- Open
references/compatibility-notes.md when a request compares Luau with Lua or depends on version-specific behavior.
- Do not open or cite references outside this skill unless the task clearly crosses into another skill's scope.
Checklist
- The solution is valid Luau syntax.
- Scope is explicit and defaults to
local.
- Control flow is clear and uses the simplest correct construct.
- Table usage is intentional: array, dictionary, or metatable-backed record.
- Iteration choice matches the data shape.
- Standard library usage is correct and simpler than a custom helper.
- Any metatable behavior is minimal, predictable, and documented in code if non-obvious.
- No deep type-system material is included.
- No performance-tuning guidance is included.
- No Roblox engine APIs or architecture advice is included.
Common Mistakes
- Treating
0 or "" as falsy. In Luau, only false and nil are falsy.
- Using
a and b or c as a ternary replacement when b can be false or nil.
- Assuming arrays are zero-based instead of one-based.
- Mixing method and function syntax, such as defining with
: and calling with ..
- Relying on dictionary iteration order.
- Forgetting that missing function arguments become
nil and extra arguments are ignored.
- Using globals where locals or closures are the correct fit.
- Overusing metatables for simple data containers.
- Assuming newer Lua features like
goto, bitwise operators, or integer semantics exist in Luau.
Examples
Use if expressions instead of boolean ternary tricks
local function labelScore(score)
return if score >= 100 then "high" else "normal"
end
Prefer locals and straightforward control flow
local function firstPositive(values)
for _, value in values do
if value > 0 then
return value
end
end
return nil
end
Use tables intentionally
local queue = {}
queue[#queue + 1] = "a"
queue[#queue + 1] = "b"
local first = table.remove(queue, 1)
Use method syntax for object-like tables
local Counter = {}
Counter.__index = Counter
function Counter.new()
return setmetatable({ value = 0 }, Counter)
end
function Counter:increment()
self.value += 1
return self.value
end
Add metatables only when behavior is deliberate
local Range = {}
Range.__index = Range
function Range.new(minimum, maximum)
return setmetatable({ minimum = minimum, maximum = maximum }, Range)
end
function Range:contains(value)
return value >= self.minimum and value <= self.maximum
end
function Range:__tostring()
return string.format("[%d, %d]", self.minimum, self.maximum)
end
1---2name: luau-core3description: ---4---5---6name: luau-core7description: "Use for idiomatic, correct pure Luau language work focused on syntax, functions, tables, control flow, metatables, standard library behavior, and Lua compatibility details outside Roblox APIs, deep typing, or performance tuning."8---910# luau-core1112## When to Use1314Use this skill when the task is primarily about plain Luau language behavior:1516- Writing or fixing pure Luau syntax.17- Choosing idiomatic control flow, variable scope, or function structure.18- Working with tables as arrays, dictionaries, or object-like values.19- Using the standard library correctly.20- Applying metatables for indexing, operators, iteration, or object-like patterns.21- Checking whether a Lua feature or idiom is compatible with Luau.2223Do not use this skill when the task is mainly about:2425- Luau type annotations, generics, inference, refinements, or strictness policy.26- Profiling, optimization strategy, or performance tradeoffs.27- Roblox engine APIs, services, events, classes, networking, data, or gameplay architecture.2829## Decision Rules3031- Use this skill if the answer can stay within pure Luau syntax, semantics, idioms, and standard library usage.32- If the task centers on type aliases, annotations, generics, exported types, or analyzer behavior, hand off to `luau-types`.33- If the task centers on allocation patterns, hot loops, benchmarking, profiling, or optimization strategy, hand off to `luau-performance`.34- If the task depends on `game`, `Instance`, services, remotes, datastores, UI, physics, or other Roblox runtime concepts, use the appropriate `roblox/*` skill instead.35- If a request mixes core language work with out-of-scope topics, answer only the pure Luau portion and explicitly exclude the rest.36- If unsure, prefer the narrower interpretation and omit material that could overlap another skill.3738## Instructions39401. Treat Luau as Lua 5.1 plus selected Luau extensions. Do not assume Lua 5.2+ features unless Luau explicitly supports them.412. Prefer `local` variables and `local function` declarations by default. Use globals only when the broader scope is required by the task.423. Keep control flow direct. Prefer normal `if`, `elseif`, `else`, loops, `break`, and `continue` over clever boolean tricks.434. Use Luau-specific syntax when it improves correctness or readability:44 - `if ... then ... else ...` expressions instead of `a and b or c` ternary emulation.45 - Compound assignment such as `+=` when the left side should only be evaluated once.46 - Generalized iteration `for k, v in table do` when iterating a table directly is the clearest form.475. Model tables intentionally:48 - Arrays for ordered numeric sequences.49 - Dictionaries for keyed lookup.50 - Metatable-backed records only when custom behavior materially improves the API.516. Use `:` for method definitions and calls that conceptually pass `self`; use `.` for plain function access.527. Prefer built-in library functions over handwritten helpers when the standard library already expresses the operation clearly.538. Use metatables sparingly and explicitly. Define only the metamethods needed for the abstraction and avoid surprising behavior.549. When discussing compatibility, call out unsupported assumptions early, such as `goto`, bitwise operators, integer-only reasoning, or full Lua standard library access.5510. Keep all examples host-agnostic and pure Luau. Do not rely on Roblox engine objects or services.5657## Using References5859- Open `references/getting-started-and-syntax.md` for syntax forms, literals, assignments, expression forms, and Luau-only syntax additions.60- Open `references/functions-tables-operators-scope-and-control-structures.md` for the core execution model: functions, closures, tables, truthiness, iteration, and control flow.61- Open `references/metatables-and-userdata-concepts.md` for metamethod behavior, object-like table patterns, raw operations, and userdata boundaries.62- Open `references/library-and-grammar-reference.md` for standard-library selection and compact grammar reminders for statements and expressions.63- Open `references/compatibility-notes.md` when a request compares Luau with Lua or depends on version-specific behavior.64- Do not open or cite references outside this skill unless the task clearly crosses into another skill's scope.6566## Checklist6768- The solution is valid Luau syntax.69- Scope is explicit and defaults to `local`.70- Control flow is clear and uses the simplest correct construct.71- Table usage is intentional: array, dictionary, or metatable-backed record.72- Iteration choice matches the data shape.73- Standard library usage is correct and simpler than a custom helper.74- Any metatable behavior is minimal, predictable, and documented in code if non-obvious.75- No deep type-system material is included.76- No performance-tuning guidance is included.77- No Roblox engine APIs or architecture advice is included.7879## Common Mistakes8081- Treating `0` or `""` as falsy. In Luau, only `false` and `nil` are falsy.82- Using `a and b or c` as a ternary replacement when `b` can be `false` or `nil`.83- Assuming arrays are zero-based instead of one-based.84- Mixing method and function syntax, such as defining with `:` and calling with `.`.85- Relying on dictionary iteration order.86- Forgetting that missing function arguments become `nil` and extra arguments are ignored.87- Using globals where locals or closures are the correct fit.88- Overusing metatables for simple data containers.89- Assuming newer Lua features like `goto`, bitwise operators, or integer semantics exist in Luau.9091## Examples9293### Use `if` expressions instead of boolean ternary tricks9495```luau96local function labelScore(score)97 return if score >= 100 then "high" else "normal"98end99```100101### Prefer locals and straightforward control flow102103```luau104local function firstPositive(values)105 for _, value in values do106 if value > 0 then107 return value108 end109 end110111 return nil112end113```114115### Use tables intentionally116117```luau118local queue = {}119120queue[#queue + 1] = "a"121queue[#queue + 1] = "b"122123local first = table.remove(queue, 1)124```125126### Use method syntax for object-like tables127128```luau129local Counter = {}130Counter.__index = Counter131132function Counter.new()133 return setmetatable({ value = 0 }, Counter)134end135136function Counter:increment()137 self.value += 1138 return self.value139end140```141142### Add metatables only when behavior is deliberate143144```luau145local Range = {}146Range.__index = Range147148function Range.new(minimum, maximum)149 return setmetatable({ minimum = minimum, maximum = maximum }, Range)150end151152function Range:contains(value)153 return value >= self.minimum and value <= self.maximum154end155156function Range:__tostring()157 return string.format("[%d, %d]", self.minimum, self.maximum)158end159```