mcpField
L
lua-basics

lua-basics

github.com/germanfndezDevelopment19386 installsUpdated 2w ago
Repository

About lua-basics

lua-basics is a skill for writing and reviewing Lua in FiveM resources. It provides concrete conventions for code structure, tables, performance, and error handling.

Key features

  1. 01Naming and variable-scope conventions
  2. 02Array iteration and table patterns
  3. 03Guard clauses and boolean defaults
  4. 04Guidance on assertions and error values
  5. 05Function-size and API design rules

Use cases

  1. 01Writing Lua for a FiveM resource
  2. 02Reviewing Lua naming and structure
  3. 03Improving array and table handling
  4. 04Handling expected and unexpected errors

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/germanfndez/fiveai-skills --skill lua-basics

After installing, type/lua-basicsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

rules/
conditionals.md
errors.md
functions.md
reference-links.md
tables.md
variables.md

Details

From the project README

Lua Basics

Idiomatic, performant Lua patterns for FiveM: functions, tables, variables, conditionals and errors.

Activation Contract

Load this skill when writing or reviewing any Lua in a FiveM resource, or when the user asks about Lua naming, structure, performance, tables or error handling.

Hard Rules

  • Naming: ALL_CAPS constants, camelCase locals, PascalCase globals, _ for unused variables.
  • Prefer local; declare locals as close to first use as possible; group file-level globals at the top of a single client/server file.
  • Do not use table.insert; append with t[#t + 1] = v or maintain your own size counter.
  • Iterate arrays with numeric for i = 1, #t; imply array indices ({ a, b }) instead of writing them out.
  • Extract repeated table dereferences into locals; use t.key for constant keys and t[var] for dynamic keys.
  • Use guard clauses and early returns; never write if x then return true else return false end.
  • Prefer positive boolean expressions; set defaults with value = value or default.
  • Use assert for pre-conditions instead of if not x then error() end; fail loudly on unexpected state; return errors as values for expected failures.
  • Limit parameters; avoid boolean parameters in APIs (use enums); pass named local functions instead of inline ones.
  • Keep functions small, single-level of abstraction, and document exports.

Decision Gates

SituationPattern
Expected failure (not found, invalid input)return nil, err or false
Programmer error / impossible stateassert / error
Flag with more than two meaningsenum table, not boolean
Function reused more than once as argumentlocal function then pass by name
Append to arrayt[#t + 1] = v

Execution Steps

  1. Apply naming and scope rules to every identifier.
  2. Replace nested if with guard clauses.
  3. Replace table.insert and pairs on arrays with index writes and numeric loops.
  4. Add assert pre-conditions at function entry.
  5. Re-read for size: split any function mixing high- and low-level code.

Output Contract

Return Lua that follows the naming, locality, table and error-handling rules above; annotate any deliberate deviation.

References

  • rules/functions.md — size, naming, parameters, exports, guard clauses.
  • rules/tables.md — indices, dereferencing, table.insert, iteration, size.
  • rules/variables.md — naming, enums vs booleans, declaration location.
  • rules/conditionals.md — defaults, boolean expressions, readability.
  • rules/errors.md — assert, pre-conditions, errors as values, fail loudly.
  • rules/reference-links.md — official Lua and FiveM documentation.

Upstream docs: https://www.lua.org/manual/5.4/

Comments

Markdown supported