summaryrefslogtreecommitdiff
path: root/Data/DefaultContent/Libraries/middleclass/README.md
blob: fc1153bd2d965794a2474cf4050f1639f4fa32bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
middleclass
===========

[![Build Status](https://travis-ci.org/kikito/middleclass.png?branch=master)](https://travis-ci.org/kikito/middleclass)
[![Coverage Status](https://coveralls.io/repos/kikito/middleclass/badge.svg?branch=master&service=github)](https://coveralls.io/github/kikito/middleclass?branch=master)

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

Quick Look
==========

```lua
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
```

Documentation
=============

See the [github wiki page](https://github.com/kikito/middleclass/wiki) for examples & documentation.

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

If you need help updating to a new middleclass version, read `UPDATING.md`.

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:

```lua
local class = require 'middleclass'
```

Specs
=====

This project uses [busted](http://olivinelabs.com/busted/) for its specs. If you want to run the specs, you will have to install it first. Then just execute the following:

```bash
cd /folder/where/the/spec/folder/is
busted
```

Performance tests
=================

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

```bash
lua performance/run.lua
```

License
=======

Middleclass is distributed under the MIT license.