AntWorks - Object Oriented Library for rbxLua

AntWorks is a library for OOP in rbxLua, some aspects of the library use the roblox api which means that it at its current state only supports rbxLua. The goal of the library is to provide the user with simple yet very powerful means to create classes and objects. A full api documentation along with more examples can be found in the github repository.

Why AntWorks?


I dare to say that AntWorks is one of the simpler OOP libraries out there, the syntax resembles that of which you would use to create classes manually in lua. It doesnt force you to have a hierarchal inheritance structure. Even after the object has been instantiated it still supports methods like inheritence.

Features


Inheritence - Very flexible inheritance allowing both objects and classes to inherit from multiple sources.

DataTypeLimits - Supports limitations to the datatype of the value which can be set at index.

Multimethods - Supports the creation and usage of multimethods.

readOnly/locked properites - The ability to lock indexes making them readOnly. You could also lock the entire object and then unlock specific indexes.

Events - Allows you to easily create new custom events, with simple management of connections helping you avoid memory leaks.

Changed event - Including a changed event which will fire whenever an index-s value within your AntObject is changed.

Example usage


This is how a class would look if it was manually implamented in lua without the use of any library.
I borrowed this example from @TheNexusAvenger btw.

local TestClass = {}

--[[
Constructor for TestClass.
--]]
function TestClass.new(Value)
    --Create the base object.
    local Object = {Value = Value}
    setmetatable(Object,TestClass)
    TestClass.__index = TestClass

    --Return the object.
    return Object
end

--[[
Returns the value of the class.
--]]
function TestClass:GetValue()
    return self.Value
end

--Create an instance of the class.
local TestObject = TestClass.new(2)
print(TestObject:GetValue()) --2

This is how it would look using AntWorks.

local AntClass = require("AntClass")
local TestClass = AntClass("Test")

----Setting the constructor function
TestClass:SetConstruct(function(self, Value)
	self.Value = Value
	return self
end)

function TestClass:GetValue()
	return self.Value
end

--Create an instance of the class.
local TestObject = TestClass.new(2)
print(TestObject:GetValue())
10 Likes

I really like how you could casually use self with this API like any other language uses this. Thank table-based methods and metatable extensions.

1 Like

2019-07-29:
Minor optimizations, mostly to the multimethods.