A simple object-oriented programming library for Lua with inheritance, metamethods, class variables, and mixin support.
middleclass is a simple object-oriented programming library for Lua that provides class-based inheritance, metamethod support, and mixin functionality. It solves the problem of implementing traditional OOP patterns in Lua's prototype-based environment by offering a clean, minimal API for creating classes and managing inheritance hierarchies.
Lua developers who want to implement object-oriented patterns in their projects, particularly game developers using Lua with engines like LÖVE or Corona SDK, and those building applications that benefit from class-based organization.
Developers choose middleclass because it provides just enough structure for OOP without being overly complex, maintains Lua's flexibility, has excellent performance, and offers features like metamethod support and mixins that other Lua OOP libraries lack.
Object-orientation for Lua
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a clean, intuitive interface for class creation and inheritance, as demonstrated in the quick look example with simple 'class' calls and method definitions, reducing boilerplate code.
Enables overloading Lua operators and other metamethods within classes, a feature highlighted in the key features that allows for expressive object behavior not common in other Lua OOP libraries.
Includes weak mixin support for reusing code across unrelated classes, facilitating modular design without deep inheritance chains, as noted in the key features.
Comes with performance tests and is designed to be lightweight, ensuring minimal overhead in resource-constrained environments like game development, as mentioned in the performance section.
Offers a detailed wiki with examples and documentation, plus changelogs and update guides, making it easy to learn and maintain, as referenced in the README.
Limits class hierarchies to single inheritance, which can be restrictive for projects that need to combine functionalities from multiple base classes, a missing feature compared to more complex OOP systems.
Lacks advanced OOP constructs like interfaces, abstract classes, or built-in serialization, requiring manual implementation for sophisticated object-oriented patterns.
Adds a third-party library to projects, which might introduce compatibility issues or bloat in minimal Lua environments, and updates may require migration efforts as indicated by the UPDATING.md file.