Skip to content
Ryan M. Wackelin edited this page Nov 13, 2015 · 5 revisions

Welcome to the SOUL wiki!

Simple Object (Oriented) Utility Library is a pure Lua library originally created for Open Computers (a mod that adds computers to Minecraft), forum post here.

Basics

The library currently has two modules: Class and Mixin.

Mixins

Mixins contain most of the features of normal mixins, they can be copied, included into one another, and checked for containment in one another. Mixin functionality could be used to implement Interfaces by simply including a table full of error("Not Implemented") methods.

local mix1 = Mixin:copy()
function talk ()
    print("Hello!")
end
print(mix1:talk()) -- Hello

local mix2 = Mixin:copy()
mix2:include(mix1)
print(mix2:hasa(mix1)) -- true

Classes

Classes contain all of the features of mixins, in fact they are literal copies of them. What makes them different though is their ability to have a 'super' or base class. The 'super' class is stored as the metatable so the class does not contain its parents methods directly, this allows for polymorphic behaviors and type checking. On top of 'super', classes also have constructors and the ability to create instances through the __init and new methods. It should be noted that in most cases the base class constructor should be initialized in the child classes constructor directly (shown below).

local class1 = Class:extend()
function class1:__init (value)
    Class.__init(self)
    self.value = value
end

instance = class1:new(256)
print(instance.value) -- 256

Clone this wiki locally