Free through lesson 3

Lua for Beginners

Implementations and types, tables and metatables, closures and coroutines, _ENV sandboxes, LuaRocks and testing, all the way to embedding with the C API. Over 20 lessons, you'll go from reading and writing Lua to embedding it in your own C program and running plugins. Every output shown is real, measured by running it on Lua 5.5.1 and LuaJIT 2.1.

Curriculum

The 20 lessons are split into 5 chapters. We recommend going in order from chapter 1, but feel free to pick out just the parts that interest you. * Lua can't run in the browser, so try things with the Lua 5.5 you install in lesson 1. Wherever 5.4 gives a different result, we show the 5.4 output too. How to write Neovim configs is covered in Neovim, fish & tmux for Beginners.

Chapter 1 — The Shape of Lua (lessons 1–4)

Install Lua, run it in the REPL and from files, and get the skeleton of the language down: types, variables, functions, and strings. We finish by searching and replacing strings with Lua patterns, which are not regular expressions.

Chapter 2 — Tables (lessons 5–8)

Learn tables, Lua's only data structure, and metatables, which change how tables behave. We finish by building classes out of tables, splitting files into modules, and connecting them with require.

Chapter 3 — The Core of the Language (lessons 9–12)

Learn the four mechanisms at the root of how Lua works: closures, coroutines, error handling, and numbers. We finish by measuring floating point, whose display changed between 5.4 and 5.5.

Chapter 4 — In Practice (lessons 13–16)

Work with files and time, sandbox other people's code, and learn to read how memory gets collected. We finish by turning your own module into a rock with LuaRocks and running tests with busted.

Chapter 5 — Embedding (lessons 17–20)

Embed Lua in a C program, pass values back and forth on the stack, and expose C functions to Lua. After measuring the differences with LuaJIT, we finish by building a C host that safely loads Lua plugins.

Once you've finished all 20 lessons, firm up the C you used in chapter 5 from the ground up with C Intro Course, or write configs in Lua with Neovim, fish & tmux for Beginners. A membership unlocks every course.