Object-orientation for Lua
Go to file
2013-09-18 23:14:01 +02:00
performance fixed perf tests 2013-09-18 23:13:41 +02:00
spec ported tests to busted 2013-09-17 20:55:50 +02:00
.travis.yml fix travis.yml 2013-09-17 21:05:47 +02:00
changelog.txt Updated changelog 2011-09-19 00:37:53 +02:00
middleclass.lua made includes a private method 2013-09-17 01:14:57 +02:00
MIT-LICENSE.txt changed from BSD to MIT license 2011-09-19 00:24:00 +02:00
README.md new README 2013-09-18 23:14:01 +02:00

middleclass

Build Status

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

h1. Quick Look

local class = require 'middleclass'

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

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

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

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

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

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

local lemon = Lemon:new()

print(lemon:isSweet()) -- false

h1. Documentation

See the "github wiki page":https://github.com/kikito/middleclass/wiki for examples & documentation.

h1. Installation

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'

h1. Specs

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
busted

h1. Performance tests

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

lua performance/run.lua