LuLua · Lesson 6 of 8
OOP & Metatables
Lua doesn't have classes — it has metatables, hooks that change how tables behave. Every Lua OOP system (including Roblox's) is built from this one mechanism.
A metatable customizes what happens on events like 'key not found' (__index) or 'table + table' (__add). The classic class pattern: put methods on a prototype table, and point instances' __index at it — missing lookups fall through to the prototype.
◆ Note
Roblox's Luau and most game engines use exactly this pattern (or wrap it). When Roblox docs say 'object-oriented programming', this __index trick is what's underneath.
Roblox's Luau and most game engines use exactly this pattern (or wrap it). When Roblox docs say 'object-oriented programming', this __index trick is what's underneath.