Course

Lua from the ground up

A tiny language that goes almost everywhere

  • Beginner
  • 12 chapters
  • 194 min read

Learn Lua by running it: values and variables, decisions, loops, text, tables used as lists and as maps, functions, closures, errors, and objects built from metatables, ending with a small program that uses all of it at once.

What You'll Learn

  • Print output, write comments, and run a first program
  • Hold values in local variables and tell integers from floats
  • Branch with if, elseif and else, and know that only nil and false are false
  • Repeat work with while and for, and leave a loop early with break
  • Join, measure, cut and format text with the string library
  • Use a table as a list: insert, remove, walk with ipairs, and sort
  • Use a table as a map, and print its keys in a stable sorted order
  • Name work as functions, return several values, and take a variable number of arguments
  • Capture state in closures and pass functions to functions
  • Raise errors on purpose and catch them with pcall and assert
  • Build objects from metatables, sharing methods and controlling how they print
  • Assemble a small program with a class, a custom sort, and a coroutine

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Any other language you know will make the early chapters quick

Course Content

  1. 01
    Your first Lua

    What Lua is, how to print a line, how comments work, and a first program you can run and change.

    Beginner · 12 min read

    Not started
  2. 02
    Values and variables

    Holding values in variables with local, the two kinds of number, text, booleans, nil, and asking a value what it is with type.

    Beginner · 14 min read

    Not started
  3. 03
    Decisions

    Choosing with if, elseif and else, comparing values, and the truth rule that only nil and false are false.

    Beginner · 14 min read

    Not started
  4. 04
    Loops

    Repeating work with while and for, counting up and down, and leaving a loop once you are finished with it.

    Beginner · 15 min read

    Not started
  5. 05
    Text in depth

    Joining and measuring text, pulling pieces out with sub and find, and laying values out neatly with string.format.

    Intermediate · 16 min read

    Not started
  6. 06
    Tables as arrays

    Using a table as a list, growing and trimming it with insert and remove, walking it with ipairs, and sorting it in place.

    Intermediate · 16 min read

    Not started
  7. 07
    Tables as maps

    Using a table as a set of named fields, reading and writing keys, walking the pairs, and printing them in a stable order.

    Intermediate · 16 min read

    Not started
  8. 08
    Functions

    Naming a block of work with local function, giving values back, returning more than one thing, taking a variable number of arguments, and defaulting a missing one.

    Intermediate · 17 min read

    Not started
  9. 09
    Closures and higher-order functions

    Functions as values you can pass and return, and closures that remember the variables they were created beside.

    Advanced · 18 min read

    Not started
  10. 10
    Errors and pcall

    Raising an error on purpose, protecting a call with pcall, and promising that something is true with assert.

    Advanced · 17 min read

    Not started
  11. 11
    Objects with metatables

    Adding behaviour to a table with a metatable, sharing methods through the index hook, and controlling how an object prints.

    Advanced · 19 min read

    Not started
  12. 12
    A small program, end to end

    Putting the course together: a metatable class, a table of objects, a custom sort, and one more tool — the coroutine.

    Advanced · 20 min read

    Not started