Skip to content
Back to skills

Writing Lua

ASecurity

Use when writing or editing Lua 5.4+ or LuaJIT modules, scripts, or configuration, or making a hot path faster. Triggers on `.lua` files, `require` modules, local scoping, metatables, coroutines, `pcall` error handling, or LuaJIT loop tuning, even when the user doesn't say 'Lua'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsgo

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill writing-lua --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Lua?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing Lua
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-writing-lua/badge)](https://www.skillsdirectory.com/skills/xonovex-writing-lua)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: writing-lua
description: "Use when writing or editing Lua 5.4+ or LuaJIT modules, scripts, or configuration, or making a hot path faster. Triggers on `.lua` files, `require` modules, local scoping, metatables, coroutines, `pcall` error handling, or LuaJIT loop tuning, even when the user doesn't say 'Lua'."
---

# Lua Coding Guidelines

Write Lua modules with local state, explicit error handling, and clear interfaces.

## Requirements

- Lua ≥ 5.4, or LuaJIT 2.1 for the hot-path tunings.

## Essentials

- **Module pattern** - Always `local`, one module per file returning table, see [references/module-pattern.md](references/module-pattern.md), [references/local-variables.md](references/local-variables.md)
- **Code organization** - Prefer table-based modules and simple functions, see [references/module-pattern.md](references/module-pattern.md), [references/metatables.md](references/metatables.md)
- **Cooperative tasks** - Use coroutines for async patterns, see [references/coroutines.md](references/coroutines.md)
- **Validation** - Validate inputs, see [references/input-validation.md](references/input-validation.md)
- **Hot paths** - Plain numeric loops and lookups cached in locals, only where profiling shows the need, see [references/hot-paths.md](references/hot-paths.md)
- **Paradigm** - Functional style → **applying-fp**; class/OO design (metatable-based) → **applying-oop**

## Gotchas

- Arrays are 1-indexed; a `nil` hole breaks the `#` length operator (it stops at the first nil)
- Tables are both array and hash; mixing them is fine but iteration order isn't guaranteed for the hash part
- `/` always returns a float; use `//` for integer floor division: `total // per_page`, not `math.floor(total / per_page)`
- Variables are global by default unless declared `local`: forgetting `local` in a loop counter leaks into the surrounding scope
- Hot-path tuning beyond what profiling shows (manual unrolling, FFI arrays, SIMD-style tricks) adds code and no speed

## Progressive disclosure

- Read [references/module-pattern.md](references/module-pattern.md) - Load when creating reusable modules or organizing code structure
- Read [references/local-variables.md](references/local-variables.md) - Load when encountering global variable issues or scoping problems
- Read [references/metatables.md](references/metatables.md) - Load when implementing object-oriented patterns or operator overloading
- Read [references/coroutines.md](references/coroutines.md) - Load when implementing cooperative multitasking or async patterns
- Read [references/input-validation.md](references/input-validation.md) - Load when adding type checks or parameter validation
- Read [references/idiomatic-patterns.md](references/idiomatic-patterns.md) - Load when learning common Lua idioms or patterns
- Read [references/hot-paths.md](references/hot-paths.md) - Load when a profile shows a hot loop or a LuaJIT trace to tune

Files in this skill

  • SKILL.md2.9 KB
  • eval-output.json5.7 KB
  • eval-trigger.json8.5 KB
  • moon.yml86 B
  • references/coroutines.md666 B
  • references/hot-paths.md825 B
  • references/idiomatic-patterns.md634 B
  • references/input-validation.md446 B
  • references/local-variables.md389 B
  • references/metatables.md502 B
  • references/module-pattern.md344 B
  • sources.json1.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.