koans.app

Lua Koans

Lua is a small, fast language designed to live inside other programs. Games, text editors, databases and network tools use it to let people script and extend them. It keeps things simple: a handful of ideas, and one data structure, the table, that serves as array, dictionary, object and module. These koans cover tables, functions and closures, metatables for building your own objects, coroutines, and the standard library.

73 koans in 11 groups, tested with busted. Each is a small program whose tests fail: replace every ___ until they pass.

Start the path

Awakening

busted's assertions, what Lua counts as true, its types, and its errors.

  1. Assertions
  2. Truthiness
  3. Types
  4. Equality
  5. Errors
  6. Locals and globals
  7. Multiple assignment
  8. Constants

Numbers

Integers and floats, the two divisions, conversions, the math library and formatting.

  1. Arithmetic
  2. Integers and floats
  3. Conversion
  4. The math library
  5. Formatting
  6. Bitwise operators
  7. Comparing floats
  8. Integer limits

Control flow

Choosing and repeating: if, the numeric and generic for, while and repeat, break and goto.

  1. if and elseif
  2. The numeric for
  3. while and repeat
  4. break and goto

Strings

Strings, their methods, Lua's patterns, splitting and joining, and UTF-8.

  1. Strings
  2. String methods
  3. Patterns
  4. Split and join
  5. UTF-8
  6. Pattern classes
  7. gsub with functions and tables
  8. Building strings
  9. Long strings and escapes

Tables

Lua's one data structure: arrays, dictionaries, iteration, and references.

  1. Tables as arrays
  2. Tables as dictionaries
  3. Iteration
  4. Table functions
  5. References
  6. Length and holes
  7. Insert, remove and move
  8. Sets and counting
  9. Sorting records
  10. Weak tables

Functions

Functions as values: multiple results, varargs, closures, and methods.

  1. Functions
  2. Varargs
  3. Closures
  4. Higher-order functions
  5. Methods
  6. Recursion and tail calls
  7. Memoization
  8. Named arguments
  9. Iterators

Metatables and objects

Metatables, operators and other metamethods, classes, inheritance, and modules.

  1. Metatables
  2. Operators
  3. Classes
  4. Inheritance
  5. More metamethods
  6. __newindex and proxies
  7. Modules

Coroutines

Functions that pause and resume: generators, pipelines, and their life cycle.

  1. Coroutines
  2. Passing values
  3. Generators
  4. Pipelines
  5. Errors in coroutines

Errors

Raising and catching errors: values, levels, and handlers.

  1. Error values
  2. Error levels
  3. xpcall
  4. To-be-closed variables

The standard library

Time and dates, select and unpack, and running code from strings.

  1. Dates and times
  2. select and unpack
  3. load and environments
  4. string.pack

Puzzles

Small programs that put the path together: read them closely and predict what they do.

  1. FizzBuzz
  2. Word frequencies
  3. Anagrams
  4. Run-length encoding
  5. Roman numerals