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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?