liminfo

Lua Reference

Free reference guide: Lua Reference

31 results

About Lua Reference

This Lua Reference is a searchable cheat sheet that covers Lua programming language syntax across six core categories: Basics, Tables, Functions, Modules, Metatables, and Coroutines. Each entry includes the syntax pattern, a concise description, and copy-ready code examples you can use immediately.

The reference covers essential Lua constructs including local variable declarations, if/elseif/else conditionals, numeric and generic for loops, while/repeat loops, string operations like concatenation and formatting, string.find and string.gsub pattern matching, table creation and manipulation with table.insert, table.remove, table.sort, and table.concat.

Advanced topics include function definitions with multiple return values, variadic arguments, closures, module creation with require, metatable programming with __index, __add, __tostring, __call metamethods, and coroutine control via coroutine.create, coroutine.yield, coroutine.wrap, and coroutine.status.

Key Features

  • Complete Lua syntax reference with 36+ entries organized into 6 categories
  • Covers basic syntax: variables, conditionals, for/while/repeat loops, and string operations
  • Table operations including insert, remove, sort, concat, unpack, and length operator
  • Function topics: definitions, multiple return values, variadic arguments, and closures
  • Module system with require, module creation patterns, and package.path configuration
  • Metatable programming: __index, __add, __tostring, __call metamethods
  • Coroutine reference: create, yield, wrap, resume, and status checking
  • Instant keyword search and category filtering with no account required

Frequently Asked Questions

What Lua topics does this cheat sheet cover?

This reference covers six categories: Basics (variables, conditionals, loops, string operations, string.format, string.find/gsub), Tables (creation, insert, remove, sort, concat, unpack, length), Functions (definitions, multiple returns, variadic arguments, closures), Modules (require, module creation, package.path), Metatables (__index, __add/__mul, __tostring, __call, setmetatable), and Coroutines (create, yield, wrap, status).

How do I declare local variables in Lua?

Use the local keyword: local x = value. For example, local name = "Kim", local age = 30, local active = true. Variables without local are global by default, which is generally discouraged in Lua programming.

What is the difference between pairs() and ipairs() in Lua?

ipairs(arr) iterates over array-like tables with integer keys in order (1, 2, 3...), stopping at the first nil. pairs(tbl) iterates over all key-value pairs in a table, including string keys and non-sequential integer keys, but in no guaranteed order.

How do Lua metatables work?

Metatables let you customize table behavior. Use setmetatable(t, mt) to assign a metatable. The __index metamethod handles missing key lookups, __add/__mul enable operator overloading, __tostring customizes string conversion, and __call lets a table be called like a function.

How do coroutines work in Lua?

Coroutines provide cooperative multitasking. Use coroutine.create() to create one, coroutine.resume() to start or continue execution, and coroutine.yield() to pause. coroutine.wrap() creates a function-like wrapper, and coroutine.status() reports whether a coroutine is suspended, running, or dead.

How do I create and use modules in Lua?

Create a module by defining a local table M = {}, adding functions to it (function M.greet(name) ... end), then returning it (return M). Load modules with require("modulename"). Configure search paths via package.path.

What string operations are available in Lua?

Lua provides string concatenation with .., length with #s, substring with string.sub(), case conversion with string.upper()/string.lower(), formatted strings with string.format(), pattern searching with string.find(), and pattern replacement with string.gsub().

Is this reference free to use?

Yes, completely free with no usage limits and no account required. All processing runs locally in your browser. The interface works on desktop, tablet, and mobile with dark mode support.