middleclass

Object-orientation for Lua

  • Owner: kikito/middleclass
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

middleclass

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
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 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:

local class = require 'middleclass'

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

Performance tests

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

lua performance/run.lua

License

Middleclass is distributed under the MIT license.

Main metrics

Overview
Name With Ownerkikito/middleclass
Primary LanguageLua
Program languageLua (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2010-04-21 21:35:02
Pushed At2023-03-05 16:45:40
Last Commit At2022-01-20 23:31:22
Release Count13
Last Release Namev4.1.1 (Posted on 2018-03-10 12:36:47)
First Release Name1.0 (Posted on 2010-10-11 16:01:43)
用户参与
Stargazers Count1.8k
Watchers Count85
Fork Count194
Commits Count220
Has Issues Enabled
Issues Count42
Issue Open Count2
Pull Requests Count12
Pull Requests Open Count2
Pull Requests Close Count12
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private