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.
Awakening
busted's assertions, what Lua counts as true, its types, and its errors.
Numbers
Integers and floats, the two divisions, conversions, the math library and formatting.
- Arithmetic
- Integers and floats
- Conversion
- The math library
- Formatting
- Bitwise operators
- Comparing floats
- Integer limits
Control flow
Choosing and repeating: if, the numeric and generic for, while and repeat, break and goto.
Strings
Strings, their methods, Lua's patterns, splitting and joining, and UTF-8.
- Strings
- String methods
- Patterns
- Split and join
- UTF-8
- Pattern classes
- gsub with functions and tables
- Building strings
- Long strings and escapes
Tables
Lua's one data structure: arrays, dictionaries, iteration, and references.
- Tables as arrays
- Tables as dictionaries
- Iteration
- Table functions
- References
- Length and holes
- Insert, remove and move
- Sets and counting
- Sorting records
- Weak tables
Functions
Functions as values: multiple results, varargs, closures, and methods.
- Functions
- Varargs
- Closures
- Higher-order functions
- Methods
- Recursion and tail calls
- Memoization
- Named arguments
- Iterators
Metatables and objects
Metatables, operators and other metamethods, classes, inheritance, and modules.
Coroutines
Functions that pause and resume: generators, pipelines, and their life cycle.
Errors
Raising and catching errors: values, levels, and handlers.
The standard library
Time and dates, select and unpack, and running code from strings.
Puzzles
Small programs that put the path together: read them closely and predict what they do.