Skip to main content

Registry

A registry is a centralized collection of validated data.

INFO

The type T is the type of the items in the registry.

Functions

new

Registry.new(
parentInstance?,
validationFunction(objany) → boolean?,
processFunction(objInstance) → T?
) → ()

Create a new registry. The parent paramater if passed will just call Registry.loadFromParent, pass nil to skip this. You can pass a validationFunction which gets asserted on every object to ensure its the correct type. Finally a processFunction can be passed which gets run on every object and can convert objects into something else, for example you could create a processFunction like this:

Registry.new(script.Parent.ItemModels, nil, function(instance: Model)
    local item = {}
    for k, v in instance:GetAttributes() do
        items[k] = v
    end
    item.model = instance
    return item
end)
INFO

If your data is stored as module scripts this will automatically pick that up and require the module scripts for you. However if you have a folder with mixed instance (e.g. ModuleScripts and Folders) if will not work properly and require the module scripts but add the raw instacne folders themselves (if no validationFunction is present).

add

Registry:add(
namestring,
objT
) → ()

Adds something to the registry.

Errors

TypeDescription
"Object did not pass validation function"The `obj` passed doesnt pass the `validationFunction` after the `processFunction`

loadFromParent

Registry:loadFromParent(instanceInstance) → ()

Load all the instacnes from the given instance. Note that this only calls :GetChildren() on the instance.

doesExist

Registry:doesExist(namestring) → boolean

Check if an item with the name name exists in the repository.

getItem

Registry:getItem(namestring) → T

Gets an item with the name name from the registry, if it doesn't exist this function will error.

Errors

TypeDescription
"Object with the name "{name}" doesn't exist in the repository."No object with the name `name` exist in the repository. You should use "doesExist" if you are cannot guarantee if an object will exist.
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Create a new registry. The `parent` paramater if passed will just call [Registry.loadFromParent], pass nil to skip this.\nYou can pass a `validationFunction` which gets asserted on every object to ensure its the correct type.\nFinally a `processFunction` can be passed which gets run on every object and can convert objects into something else, for\nexample you could create a processFunction like this:\n```lua\nRegistry.new(script.Parent.ItemModels, nil, function(instance: Model)\n    local item = {}\n    for k, v in instance:GetAttributes() do\n        items[k] = v\n    end\n    item.model = instance\n    return item\nend)\n```\n\n:::info\nIf your data is stored as module scripts this will automatically pick that up and require the module scripts for you. However\nif you have a folder with mixed instance (e.g. ModuleScripts and Folders) if will not work properly and require the module scripts\nbut add the raw instacne folders themselves (if no validationFunction is present).\n:::",
            "params": [
                {
                    "name": "parent",
                    "desc": "",
                    "lua_type": "Instance?"
                },
                {
                    "name": "validationFunction",
                    "desc": "",
                    "lua_type": "(obj: any) -> boolean?"
                },
                {
                    "name": "processFunction",
                    "desc": "",
                    "lua_type": "(obj: Instance) -> T?\r\n"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 43,
                "path": "packages/registry/source/init.luau"
            }
        },
        {
            "name": "add",
            "desc": "Adds something to the registry.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"Object did not pass validation function\"",
                    "desc": "The `obj` passed doesnt pass the `validationFunction` after the `processFunction`"
                }
            ],
            "source": {
                "line": 79,
                "path": "packages/registry/source/init.luau"
            }
        },
        {
            "name": "loadFromParent",
            "desc": "Load all the instacnes from the given `instance`. Note that this only calls `:GetChildren()` on the `instance`.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 92,
                "path": "packages/registry/source/init.luau"
            }
        },
        {
            "name": "doesExist",
            "desc": "Check if an item with the name `name` exists in the repository.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 106,
                "path": "packages/registry/source/init.luau"
            }
        },
        {
            "name": "getItem",
            "desc": "Gets an item with the name `name` from the registry, if it doesn't exist this function will error.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"Object with the name \"{name}\" doesn't exist in the repository.\"",
                    "desc": "No object with the name `name` exist in the repository. You should use \"doesExist\" if you are cannot guarantee if an object will exist."
                }
            ],
            "source": {
                "line": 120,
                "path": "packages/registry/source/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Registry",
    "desc": "A registry is a centralized collection of validated data.\n\n:::info\nThe type `T` is the type of the items in the registry.\n:::",
    "source": {
        "line": 9,
        "path": "packages/registry/source/init.luau"
    }
}