Catalog / Lua Cheatsheet
Lua Cheatsheet
A concise reference for Lua syntax, data types, control structures, and standard library functions. Perfect for quick lookup and reminding yourself of the essentials.
Basics & Syntax
Basic Syntax
Comments |
|
Variables |
|
Assignment |
|
Chaining Assignment |
|
Statements |
Statements do not need to end with a semicolon (;) |
Case Sensitivity |
Lua is case sensitive |
Data Types
|
Operators
Arithmetic Operators |
|
Relational Operators |
|
Logical Operators |
|
Concatenation Operator |
|
Length Operator |
|
Control Structures
Conditional Statements
|
Example:
|
Looping Statements
|
Example (while loop):
|
Example (for loop):
|
Example (foreach loop):
|
Break and Return
|
Exits the innermost loop. |
|
Exits the function. |
Tables
Table Basics
Tables are the primary data structure in Lua. They are associative arrays that can be indexed with any value (except |
Table Creation and Access
Creating a Table |
|
Accessing Elements |
|
Adding/Modifying Elements |
|
Removing Elements |
|
Table Functions
|
Example (insert):
|
Example (remove):
|
Functions
Function Definition
|
Example:
|
Function Calls
Calling a Function |
|
Calling a Method |
|
Returning Values |
Functions can return multiple values: |
Variable Arguments
Use |
Example:
|