Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
middleclass | ||
=========== | ||
|
||
[![Build Status](https://travis-ci.org/kikito/middleclass.png?branch=master)](https://travis-ci.org/kikito/middleclass) | ||
|
||
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](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: | ||
|
||
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 | ||
|
||
|
This file was deleted.
Oops, something went wrong.