Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kikito/middleclass
Object-orientation for Lua
https://github.com/kikito/middleclass
Last synced: 25 days ago
JSON representation
Object-orientation for Lua
- Host: GitHub
- URL: https://github.com/kikito/middleclass
- Owner: kikito
- License: mit
- Created: 2010-04-21T21:35:02.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2023-03-05T16:45:40.000Z (over 1 year ago)
- Last Synced: 2024-09-30T15:41:00.710Z (about 1 month ago)
- Language: Lua
- Homepage: https://github.com/kikito/middleclass
- Size: 199 KB
- Stars: 1,754
- Watchers: 88
- Forks: 190
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
- awesome-love2d - middleclass - Simple OOP library for Lua; has inheritance, metamethods (operators), class variables and weak mixin support (class-commons). (OO)
- awesome-playdate - middleclass - A simple OOP library for Lua that introduces inheritance, operator overloads, static variables, and mixin support. (Game Development / Programming Frameworks & Languages)
- awesome-defold - middleclass
README
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
endFruit.static.sweetness_threshold = 5 -- class variable (also admits methods)
function Fruit:isSweet()
return self.sweetness > Fruit.sweetness_threshold
endlocal Lemon = class('Lemon', Fruit) -- subclassing
function Lemon:initialize()
Fruit.initialize(self, 1) -- invoking the superclass' initializer
endlocal 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.