Object-orientation for Lua

License: MIT

Language: Lua


Build Status Coverage Status

A simple OOP library for Lua. It has inheritance, metamethods (operators), class variables and weak mixin support.

Quick Look

local class = require 'middleclass'

local Fruit = class('Fruit') -- 'Fruit' is the class' name

function Fruit:initialize(sweetness)
  self.sweetness = sweetness

Fruit.static.sweetness_threshold = 5 -- class variable (also admits methods)

function Fruit:isSweet()
  return self.sweetness > Fruit.sweetness_threshold

local Lemon = class('Lemon', Fruit) -- subclassing

function Lemon:initialize()
  Fruit.initialize(self, 1) -- invoking the superclass' initializer

local lemon = Lemon:new()

print(lemon:isSweet()) -- false


See the github wiki page for examples & documentation.

You can read the file to see what has changed on each version of this library.

If you need help updating to a new middleclass version, read


Just copy the middleclass.lua file wherever you want it (for example on a lib/ folder). Then write this in any Lua file where you want to use it:

local class = require 'middleclass'


This project uses busted for its specs. If you want to run the specs, you will have to install it first. Then just execute the following:

cd /folder/where/the/spec/folder/is

Performance tests

Middleclass also comes with a small performance test suite. Just run the following command:

lua performance/run.lua


Middleclass is distributed under the MIT license.

Project Statistics

Sourcerank 9
Repository Size 198 KB
Stars 1,033
Forks 116
Watchers 84
Open issues 1
Dependencies 0
Contributors 9
Tags 13
Last updated
Last pushed

Top Contributors See all

Enrique García Cota Peter Melnichenko Norman Clarke Michael Ebens kenshin Linus Evan Sebastián Moreno Qais Patankar

Recent Tags See all

v4.1.1 March 10, 2018
v4.1.0 July 02, 2016
v4.0.0 December 31, 2015
v3.2.0 November 23, 2015
v3.1.0 November 02, 2015
3.0.1 December 06, 2013
v3.0.0 September 19, 2013
2.0 September 18, 2011
1.4 March 30, 2011
1.3 February 01, 2011
1.2 December 07, 2010
1.1 November 23, 2010
1.0 October 11, 2010

Interesting Forks See all

Object-orientation for Lua
Lua - MIT - Last pushed - 2 stars
Object-orientation for Lua
Lua - BSD-3-Clause - Updated - 1 stars
Object-orientation for Lua
MIT - Updated - 1 stars
Object-orientation for Lua
Lua - MIT - Last pushed - 1 stars
Object-orientation for Lua
Lua - MIT - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2017-04-29 02:02:55 UTC

Login to resync this repository