lua-basics

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Lua Basics

Lua 基础

Best practices for writing effective Lua code in FiveM. This skill covers fundamental Lua patterns, performance optimizations, and code quality guidelines specifically for FiveM development.
在FiveM中编写高效Lua代码的最佳实践。本技能涵盖专为FiveM开发设计的Lua基础模式、性能优化方案以及代码质量准则。

When to use

使用场景

  • Writing or reviewing Lua code for FiveM resources.
  • Questions about Lua best practices, naming conventions, or code structure.
  • Optimizing Lua code for performance.
  • Need guidance on functions, tables, variables, conditionals, or error handling in Lua.
  • 编写或审核FiveM资源的Lua代码时。
  • 关于Lua最佳实践、命名规范或代码结构的疑问。
  • 优化Lua代码性能。
  • 需要获取Lua中函数、表、变量、条件语句或错误处理的指导。

How to use

使用方法

Read individual rule files for detailed explanations and examples:
  • rules/functions.md — Function best practices: size, naming, parameters, exports, guard clauses.
  • rules/tables.md — Table operations: array indices, dereferencing, avoiding table.insert, iterations, array size.
  • rules/variables.md — Variable naming conventions: constants, locals, globals, enums vs booleans.
  • rules/conditionals.md — Conditional patterns: default values, boolean expressions, readability.
  • rules/errors.md — Error handling: assertions, pre-conditions, errors as values, fail loudly.
  • rules/reference-links.md — Official Lua and FiveM documentation resources.
阅读各个规则文件获取详细说明及示例:
  • rules/functions.md —— 函数最佳实践:规模、命名、参数、导出、守卫子句。
  • rules/tables.md —— 表操作:数组索引、解引用、避免使用table.insert、迭代、数组大小。
  • rules/variables.md —— 变量命名规范:常量、局部变量、全局变量、枚举 vs 布尔值。
  • rules/conditionals.md —— 条件语句模式:默认值、布尔表达式、可读性。
  • rules/errors.md —— 错误处理:断言、前置条件、错误作为值、快速失败。
  • rules/reference-links.md —— Lua及FiveM官方文档资源。