Registry is a utility module in RoClass that keeps track of classes and instances.
It allows you to register classes, register/deregister instances, and retrieve instances by class name.
The Registry module provides a centralized tracking system:
Registry.RegisterClass(class: table): nil
Registers a class with the registry.
class
→ Class table returned by RoClass.new(...):build()
.Registry.RegisterInstance(instance: any): nil
Registers an instance of a class.
instance
→ The instance to register.Registry.DeregisterInstance(instance: any): nil
Removes an instance from the registry.
instance
→ The instance to remove.Registry.GetInstances(className: string): { any }
Retrieves all registered instances of a class.
className
→ Name of the class.Registry.GetClass(className: string): table?
Retrieves the class definition by name.
className
→ Name of the class.nil
if not foundlocal Player = RoClass.new("Player"):build()
RoClass.RegisterClass(Player)
local p1 = Player.new()
local p2 = Player.new()
RoClass.RegisterInstance(p1)
RoClass.RegisterInstance(p2)
local instances = RoClass.GetInstances("Player")
print(#instances) -- 2
RoClass.DeregisterInstance(p1)
local instances = RoClass.GetInstances("Player")
print(#instances) -- 1
local classDef = RoClass.GetClass("Player")
print(classDef._className) -- "Player"
This documentation is part of RoClass. For more examples and detailed guides, see RoClass Docs.