English for Lua Developers
Learn the English vocabulary for Lua: tables, metatables, coroutines, and explaining why a small embeddable scripting language needs precise words for its few core concepts.
Lua conversations tend to reuse a small set of powerful words over and over, since the language deliberately has few core concepts, so being precise about tables, metatables, and coroutines matters more than in languages with a larger built-in vocabulary of data structures.
Key Vocabulary
Table — Lua’s single core data structure, an associative array that can act as a list, a map, a record, or an object depending on how its keys are used.
“There’s no separate array type — that config is just a table using integer keys, so #config gives you its length like an array.”
Metatable — a table attached to another table that defines how it behaves for operations like addition, indexing, or comparison, effectively implementing operator overloading and inheritance.
“We added a metatable with an __index function so missing keys fall back to the parent object instead of returning nil.”
Coroutine — a cooperative, non-preemptive thread of execution that can suspend itself with yield and be resumed later, used for things like generators and game scripting without real OS threads.
“Instead of spawning a thread, we wrapped the dialogue script in a coroutine so it can yield mid-sentence and resume next frame.”
Closure / upvalue — a function that captures variables from its enclosing scope (its upvalues), keeping them alive and shared across calls even after the outer function has returned.
“That counter function is a closure over the upvalue count, which is why each call remembers the previous total.”
Embedding a scripting engine — the practice of compiling Lua into a host application (often written in C or C++) so designers or modders can script behavior without recompiling the engine itself. “The whole point of embedding a scripting engine is that level designers can tweak enemy behavior in Lua without waiting on an engine rebuild.”
Common Phrases
- “Is this table being used as an array, a map, or an object here?”
- “Did we set a metatable on this, or is that method call going to fail silently?”
- “Should this be a coroutine, or do we actually need real concurrency here?”
- “Is that variable an upvalue captured by the closure, or a fresh local each call?”
- “Why are we embedding a scripting engine here instead of hardcoding this logic in the engine itself?”
Example Sentences
Explaining a data structure choice to a teammate: “We don’t need a separate class system — a table with a metatable gives us inheritance and method dispatch, which is all this needs.”
Reviewing a gameplay script: “Turn this state machine into a coroutine so the NPC can yield between steps instead of us hand-rolling a tick counter.”
Onboarding a new scripter: “Remember that Lua closures capture upvalues by reference, so if two functions share one, changing it in one place affects both.”
Professional Tips
- Clarify how a table is being used (list-like vs map-like) in code review — mixed usage is a common source of subtle bugs around
#andpairsvsipairs. - Explain metatable behavior explicitly when reviewing “object-oriented” Lua code — it’s easy for readers unfamiliar with
__indexto miss where methods are actually coming from. - Recommend coroutines for anything that needs to pause and resume over multiple frames or steps — it’s more idiomatic than manual state machines in most Lua game code.
- Warn new scripters about shared upvalues in closures — accidental sharing across callbacks is one of the most common Lua bugs in embedded scripting.
Practice Exercise
- Explain how a single table type in Lua can serve as both an array and an object, and why that flexibility matters.
- Describe what a metatable does and give an example of an operation it can customize.
- Write a sentence explaining why a game might use a coroutine instead of a real thread for scripting dialogue.