middleclass

Object-orientation for Lua

  • 所有者: kikito/middleclass
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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.

主要指标

概览
名称与所有者kikito/middleclass
主编程语言Lua
编程语言Lua (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2010-04-21 21:35:02
推送于2023-03-05 16:45:40
最后一次提交2022-01-20 23:31:22
发布数13
最新版本名称v4.1.1 (发布于 2018-03-10 12:36:47)
第一版名称1.0 (发布于 2010-10-11 16:01:43)
用户参与
星数1.8k
关注者数85
派生数194
提交数220
已启用问题?
问题数42
打开的问题数2
拉请求数12
打开的拉请求数2
关闭的拉请求数12
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?