Lua

A small, simple scripting language used in games, mods and apps.

Lua is a small scripting language (the interpreter is about 300KB) that many programs embed so users can script them, including Roblox, World of Warcraft addons, Neovim and Redis. Its short, simple syntax makes it a good first language, especially if you are interested in game scripting.

  • Beginner
  • 8 lessons
Not started yet
Start lesson 1

Lessons

  1. Hello, LuaWrite your first Lua program and learn variables and basic types. Lua has a small syntax, so it is a comfortable place to start if you are new to programming.
  2. Conditions & LoopsLearn if statements, while and repeat loops, and the two kinds of for loop. Lua marks blocks with keywords such as then, do and end instead of braces.
  3. TablesLua has one data structure, the table, which works as an array, a dictionary and an object. Learn to create tables and loop over them.
  4. FunctionsLearn to write functions, return several values at once, and use closures. In Lua, functions are values you can store in tables and pass to other functions.
  5. Strings & the Standard LibraryLearn the string functions and the rest of Lua's small standard library: table, math, io and os. It is small enough to learn in full.
  6. OOP & MetatablesLua has no classes. Instead it has metatables, which change how tables behave. Learn how to use them to build objects with methods and to overload operators.
  7. Your First Game with LÖVEBuild a small game with LÖVE, a free 2D game framework. You write three functions (load, update and draw) and LÖVE handles the window, graphics and input.
  8. Lua CheatsheetThe whole language on one page — it fits.

Install it on your own computer

Install the standalone interpreter to follow the lessons. For games, LÖVE (love2d.org) is a free 2D engine, and Roblox Studio has its own version of Lua (Luau) built in.

Bash
winget install DEVCOM.Lua
# Or scoop install lua

lua -v            # Lua 5.4.x
lua hello.lua     # run a file
lua               # interactive REPL

# For games: download LÖVE from https://love2d.org

What people build with Lua

Learn the basics first, then pick up these tools when a project needs them.

Practical uses

  • Embed scripting inside larger applications
  • Create game behavior and modifications
  • Configure editors and infrastructure tools
  • Build lightweight automation

Projects to try

  1. Text adventure
  2. Neovim plugin
  3. LÖVE2D platformer
  4. Embedded rules engine

Common tools and packages

LuaRocksLÖVE2DOpenRestyBustedPenlightLPegLuaJITNeovim API

Well-known software

NeovimRoblox experiencesWorld of Warcraft addonsRedis scriptsWiresharkAwesomeWM