I have created a Registry class that registries some data modules, in some cases I want to transform the data before adding it to the registry:
--[[
Decides what to do with the required data from each data module.
Must be overwritten if additional behaviour is intended.
]]
function Registry:Require<T>(object: any)
return object
end
--[[
Adds a new entry to the registry.
]]
function Registry.Add<T>(self: Registry<T>, object: T): T
local newEntry = self:Require(object)
if (typeof(newEntry) ~= "table") then return newEntry end
if (not newEntry.id) then return newEntry end
if (self.entries[newEntry.id]) then return newEntry end
self.entries[newEntry.id] = newEntry
if (newEntry.category) then
if (not self.sorted[newEntry.category]) then
self.sorted[newEntry.category] = {}
end
table.insert(self.sorted[newEntry.category], newEntry)
end
table.insert(self.list, newEntry)
self:Msg(ADD_MSG:format(newEntry.id))
return newEntry
end
I want to make it so the Registry:Require()
method can be defined to adapt to my needs but I can’t get it to work without a warning: