Lua: Zero to Hero

A complete quiz-based curriculum covering Lua from first principles to expert-level, production-grade knowledge. Lua's minimalism is deceptive — nearly everything (objects, modules, namespaces) is built from one primitive, the table, and this track is sequenced around the handful of mechanisms (metatables, closures, coroutines) that make that possible.

How to Use This Quiz Track

  • Work through the parts in order; Part 2 onward assumes comfort with tables and closures from Part 1.
  • Each quiz has 20 multiple-choice questions, ordered from basic recall to edge cases to best-practice judgment calls.
  • Click Show Answer only after committing to a choice — the explanations cover the underlying mechanism (metamethods, upvalue sharing, coroutine state machines), not just the right letter.
  • Expect classic Lua "wat" moments — 1-based indexing, the # operator on tables with holes, and .. string coercion — turned into quiz questions.
  • Questions target Lua 5.4 (the current reference implementation) and call out version differences (5.1/5.2/5.3, LuaJIT) where they matter in practice.

Prerequisites

None for Part 1, though familiarity with any dynamically-typed scripting language helps the table/closure model click faster.

Curriculum

Part 1 — Foundations

#TopicWhy It Matters
01Introduction & Setuplua vs luajit, embedding vs standalone, and version fragmentation (5.1–5.4) shape which features and libraries are actually available.
02Variables & Data TypesGlobals-by-default, nil, and the integer/float subtype split (5.3+) are frequent sources of subtle bugs.
03Operators & ExpressionsString-to-number coercion via arithmetic operators and .. concatenation are classic gotcha territory.
04Control Flowrepeat...until's scoping quirk and the absence of break-with-label (only goto) surprise newcomers.
05Strings & PatternsLua patterns are not regex — the differences trip up anyone assuming PCRE-style syntax.
06TablesThe array/hash duality and the famously undefined # operator on tables with holes are the single biggest source of Lua bugs.

Part 2 — Functions & Scope

#TopicWhy It Matters
07FunctionsMultiple return values and varargs (...) are used pervasively and behave differently from most mainstream languages.
08Closures & UpvaluesShared upvalues across loop iterations are Lua's version of the classic JS var-in-a-loop bug.
09Metatables & Metamethods__index/__newindex and operator metamethods are how Lua achieves everything from OOP to operator overloading.
10OOP with Tables & MetatablesColon-call sugar (obj:method()) hides an implicit self that's a frequent source of attempt to call a nil value errors.

Part 3 — Control & Errors

#TopicWhy It Matters
11Error Handlingpcall/xpcall and non-string error objects are Lua's whole error model — there's no try/catch.
12Coroutinesresume/yield state machines power generators, cooperative schedulers, and game-engine update loops.
13Modules & requirerequire caching and package.path resolution order are essential for structuring any non-trivial project.

Part 4 — Advanced & Systems

#TopicWhy It Matters
14Garbage CollectionIncremental vs. generational GC (5.4) and weak tables matter for anyone building caches or long-running processes.
15The C API & FFILua's defining use case is embedding — the stack-based C API and LuaJIT's FFI are how host applications actually integrate it.
16Advanced Metaprogramming__call, __tostring, and proxy tables via __index/__newindex enable sandboxing and DSL-style APIs.
17Standard Library Deep Divetable.sort stability, os.time granularity, and io buffering behavior matter in real scripts.
18Performance & LuaJITJIT trace compilation, deoptimization triggers, and table pre-sizing are where Lua performance work actually happens.
19TestingFrameworks like busted and luaunit, plus common assertion/mocking patterns, determine test suite trustworthiness.
20Securityload/loadstring on untrusted input and unsandboxed os.execute are the most common Lua vulnerabilities (notably in game modding and CDN edge scripts).
21Exercises & Projects (Capstone)A mixed-review capstone spanning metatables, coroutines, closures, and error handling.