Introduction
rbx-classify (or simply Classify) is a simple-to-use super constructor that simplifies the OOP class-creation and clean-up coding process in Roblox Lua.
Its main goal is to simplify the custom-property creation process for classes that don’t use or wrap Roblox instances (and therefore cannot make use of Attributes). It also completely removes the need for the programmer (you!) to have to handle metatables, cleanup, and table proxying.
Features Summary
- Easily wrap your constructor with Classify in one simple function call.
- Mark functions, userdatas, RBXScriptConnections, or other tables with a
::Destroy()
method as disposable in one function call. Very similar to how Maid works. - All wrapped classes are injected with a
::Destroy()
method that cleans up all class data, marked disposables, and locks future references to the class. - Add your own cleanup routine that executes before Classify’s internal
::Destroy()
method by binding to the::_cleaning()
callback. - Easily create custom properties with getters, setters, or targeted binds to quickly link your class to real instance properties.
Planned Features
- Integrate attributes to allow code without direct reference to the created class to be able to modify custom properties with
::GetAttribute()
and::SetAttribute()
if a userdata is provided. - Allow the combined use of getters/setters with targeted binds to allow more robust and customizable property routines.
Example
Here is a very basic example rounded button class made with Classify:
--= Classify Module =--
local classify = require(game.ReplicatedStorage:WaitForChild('Classify'))
--= Class Root =--
local RoundButton = { }
RoundButton.__classname = 'RoundButton'
--= Class Constructor =--
function RoundButton.new(parent: Instance) -- Main Constructor function.
local self = classify(RoundButton) -- Wrap our class with Classify.
local button = Instance.new('TextButton', parent) -- Create a base TextButton.
button.Name = self.ClassName -- ClassName is automatically integrated for you!
button.Size = UDim2.fromOffset(200, 50)
local corner = Instance.new('UICorner', button) -- Give it nice rounded corners :)
corner.CornerRadius = UDim.new(0, 10)
self._button = button -- Create an internal reference to the button for easier referencing.
self.Activated = button.Activated -- Expose reference to Activated event.
self:_mark_disposable(button) -- Mark our TextButton as disposable so it is cleaned up on ::Destroy().
return self -- Return our class to whatever script creates it.
end
--= Class Properties =--
RoundButton.__properties = { -- Create our __properties table so Classify will listen for them.
ButtonText = { -- Bind the Text property to our TextButton.
bind = 'Text', -- What real-world property of our TextButton we're binding to.
target = function(self) return self._button end -- Return a reference to the button so Classify knows what to target.
}
}
--= Return Class =--
return RoundButton
Where do I get Classify?
You can grab a copy of Classify’s source code by visiting its GitHub Repository. Full documentation is also included in the read-me.
That’s all I got for now! If you encounter any issues or have any questions or concerns, feel free to leave a reply and I’ll get back as soon as I can.