Search code examples
classinheritanceluaprototype

Is inheritance in Lua prototype-based or class-based?


Lua is often described as having prototype-based inheritance (for example in this answer). However, the "Inheritance" section of "Programming in Lua" talks about "base class" and "superclass" - terms from class-based inheritance.

Which model, prototype-based or class-based, best describes how inheritance works in Lua?


Solution

  • Lua is prototype-based.

    Technically, there is no class or inheritance or base class, super class in Lua. Lua has some tools like metatables to simulate classical OOP. The main reason that the PiL book uses these terms is to make it easier for the reader to understand.

    If you like the language-lawyer way of describing the syntax, read the reference manual, you won't find these terms there.