Skip to content

Latest commit

 

History

History
80 lines (54 loc) · 1.74 KB

README.md

File metadata and controls

80 lines (54 loc) · 1.74 KB

Sunclass

Build Status

A simple OOP library for Lua, based on the Sunscript implementation of classes.

  • Mixins / Multiple Inheritance
  • Invoking superclass methods
  • Operator overloading / Metamethods
  • Simple, intuitive, easy to use and install

Installation

Drag and drop sunclass.lua into your project directory, then add this line to your code:

local class = require("sunclass")

Unit Tests

Unit tests are stored in the spec folder.

Perform unit tests with Busted: busted

Documentation

Simple class

local SimpleClass = class("SimpleClass")

-- constructor, automatically called
function SimpleClass:initialize()
end

-- definition of a class method
function SimpleClass:classMethod()
end

-- class instancing and method calling
local instance = SimpleClass:new()
instance:classMethod()

Class inheritance and invoking super methods.

-- definition of a super class
local SuperClass = class("SuperClass")

function SuperClass:classMethod()
end

-- definition of a derived class
local SimpleClass = class("SimpleClass", SuperClass)

function SimpleClass:classMethod()
	self.super:classMethod()
end

Mixins / Multiple inheritance

You can actually have an unlimited number of inheritances

-- definition of a mixin class
local Mixin = class("Mixin")

function Mixin:randomFunction()
end

-- definition of a class that derives off of another class and has a mixin.
local SimpleClass = class("SimpleClass", SuperClass, Mixin)

function SimpleClass:classMethod()
	self.super:classMethod()
end

License

Sunclass is licensed under the MIT license.