$npx -y skills add TabooHarmony/roblox-brain --skill roblox-luau-coreUse for Luau syntax, tables, control flow, string patterns, math, scope, closures, idioms, or porting code from JavaScript or Python.
| 1 | # Luau Core Language |
| 2 | |
| 3 | ## When to Load |
| 4 | |
| 5 | Load for Luau syntax questions: variables, operators, tables, string patterns, math helpers, scope/closures, common idioms, porting from JS/Python, and sharp edges (1-based indexing, nil semantics, truthiness). For type annotations, use `roblox-luau-types`. For OOP/async/modules, use `roblox-luau-patterns`. |
| 6 | |
| 7 | **Hand off to:** `roblox-luau-types` (type annotations/generics), `roblox-luau-patterns` (OOP/async/modules), `roblox-*` domain skills (engine APIs). |
| 8 | |
| 9 | **Full reference:** `references/full.md` |
| 10 | |
| 11 | ## Quick Reference |
| 12 | |
| 13 | **Basics:** Luau = Lua 5.1 + extensions. Always `local`. No hoisting — callees above callers. Forward-declare for mutual recursion. |
| 14 | |
| 15 | **Extensions over Lua 5.1:** `continue`, `+= -= *=`, `//` floor division, `math.clamp/sign/round`, backtick interpolation, generalized iteration, `table.freeze/clone/clear`. |
| 16 | |
| 17 | **Truthiness:** Only `nil` and `false` are falsy. `0`, `""`, `{}` are truthy. No type coercion in `==` (`0 == "0"` → `false`). |
| 18 | |
| 19 | **Arrays:** 1-based. `#tbl` length — unreliable with nil gaps, keep contiguous. Use `table.insert/remove/find/sort/concat`. Iterate: `for k, v in tbl do`. |
| 20 | |
| 21 | **Strings:** Prefer backticks `` `{name} age {age}` `` over `..`. Patterns (NOT regex): `%a %d %w %s` classes, `* + - ?` quantifiers, `^$` anchors. Functions: `string.match/gmatch/gsub/split`. |
| 22 | |
| 23 | **Tables:** Only compound type. Reference semantics (`=` aliases). `table.clone` is shallow. `nil` removes keys. Dynamic keys need bracket notation `t[key]`. |
| 24 | |
| 25 | **Ternary:** `(cond and val or fallback)` breaks if `val` is falsy. Use `if cond then a else b` for safety. |
| 26 | |
| 27 | **Error handling:** `pcall(fn)` / `xpcall(fn, handler)`. No try/catch. |
| 28 | |
| 29 | **Pitfalls:** |
| 30 | - `a and b or c` fails when `b` is nil/false |
| 31 | - Arrays start at 1, not 0 |
| 32 | - `:` defines implicit self, `.` doesn't |
| 33 | - While-loop closures share variable — capture in local |
| 34 | - No arrow functions, `===`, `!=`, spread, `const/let` |
| 35 | - Reserved keywords can't be identifiers (`return`, `continue`, etc.) |
| 36 | - Use `task.wait/spawn/delay`, never deprecated `wait/spawn/delay` |
| 37 | |
| 38 | **JS→Luau:** `map/filter` → manual loops, `null` → `nil`, `x ?? y` → `x or y`, `x?.y` → `x and x.y`, `===` → `==`, `!==` → `~=`, `import` → `require`, `class` → metatable+`__index`, `try/catch` → `pcall`. |
| 39 | |
| 40 | For detailed examples, see `references/full.md`. |