Skip to main content

CradleServer

This item only works when running on the server. Server

This is the API Documentation for the Cradle module. It contains all the API functions for the server.

local Cradle = require(game:GetService("ReplicatedStorage").Cradle)

Properties

RemoteComm

CradleServer.RemoteComm: table

Contains the Remote Communication Module.

tip

See the Networking guide to learn more about it.

Component

CradleServer.Component: table

Contains the Component Module.

tip

See the Components guide to learn more about it.

Modules

CradleServer.Modules: table

Contains all modules in the Modules folder.

Shared

CradleServer.Shared: table

Contains all modules that is stored in the Modules Folder.

Packages

CradleServer.Packages: table

Contains all modules in the Packages folder.

Util

deprecated in v1.0.0
</>
This was deprecated in v1.0.0

This item is deprecated. Do not use it for new work.

CradleServer.Util: table

Contains all modules in the Packages folder.

Functions

RegisterMiddleware

CradleServer:RegisterMiddleware(
prioritynumber,
functionfunc,
servicestable?
) → nil

Registers a middleware function to be called before a service's remote object is invoked.

caution

This will only run when the server has received a request from the client.

Usage
CradleServer:RegisterMiddleware(1, function()
	print("This is a middleware function")
end, {
	Cradle:GetService("SomeService"),
	Cradle:GetService("AnotherService"),
})

CreateService

CradleServer:CreateService(
Namestring,
Clienttable
) → Service

Creates a new service.

caution

Services must be created before calling Cradle:Start()

Usage
local SomeService = Cradle:CreateService({
	Name = "SomeService",
	Client = {},
})

function SomeService.Client:SomeRemoteFunction()
	print("SomeService has been called!")
	return "Hello from the server!"
end

function SomeService:Init()
	print("SomeService has been initialised!")
end

function SomeService:Start()
	print("SomeService has started!")
end

GetService

CradleServer:GetService(serviceNamestring) → Service

Gets a service by name. Throws a warning if the service is not found.

Load

CradleServer:Load() → nil

Loads all services and components.

caution

This must be called before calling Cradle:Start()

Start

CradleServer:Start() → nil

Starts all services and components.

caution

This must be called after calling Cradle:Load()

Show raw api
{
    "functions": [
        {
            "name": "RegisterMiddleware",
            "desc": "Registers a middleware function to be called before a service's remote object is invoked. \n\n:::caution\nThis will only run when the server has received a request from the client.\n:::\n\n:::note Usage\n```lua\nCradleServer:RegisterMiddleware(1, function()\n\tprint(\"This is a middleware function\")\nend, {\n\tCradle:GetService(\"SomeService\"),\n\tCradle:GetService(\"AnotherService\"),\n})\n```\n:::",
            "params": [
                {
                    "name": "priority",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "function",
                    "desc": "",
                    "lua_type": "func"
                },
                {
                    "name": "services",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 214,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "CreateService",
            "desc": "Creates a new service.\n\n:::caution\nServices must be created before calling `Cradle:Start()`\n:::\n\n:::note Usage\n```lua\nlocal SomeService = Cradle:CreateService({\n\tName = \"SomeService\",\n\tClient = {},\n})\n\nfunction SomeService.Client:SomeRemoteFunction()\n\tprint(\"SomeService has been called!\")\n\treturn \"Hello from the server!\"\nend\n\nfunction SomeService:Init()\n\tprint(\"SomeService has been initialised!\")\nend\n\nfunction SomeService:Start()\n\tprint(\"SomeService has started!\")\nend\n```\n:::",
            "params": [
                {
                    "name": "Name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "Client",
                    "desc": "",
                    "lua_type": "table"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Service"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 266,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "GetService",
            "desc": "Gets a service by name. Throws a warning if the service is not found.",
            "params": [
                {
                    "name": "serviceName",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Service"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 287,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "CreateComponent",
            "desc": "Creates a new component.",
            "params": [
                {
                    "name": "ModuleScript",
                    "desc": "",
                    "lua_type": "mod"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "nil"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 305,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Load",
            "desc": "Loads all services and components.\n\n:::caution\nThis must be called before calling `Cradle:Start()`\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 326,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Start",
            "desc": "Starts all services and components.\n\n:::caution\nThis must be called after calling `Cradle:Load()`\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 361,
                "path": "src/CServerInternal.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "RemoteComm",
            "desc": "Contains the Remote Communication Module.\n\n:::tip\nSee the [Networking](networking) guide to learn more about it.\n:::",
            "lua_type": "table",
            "source": {
                "line": 46,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Component",
            "desc": "Contains the Component Module.\n\n:::tip\nSee the [Components](/docs/components) guide to learn more about it.\n:::",
            "lua_type": "table",
            "source": {
                "line": 57,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Modules",
            "desc": "Contains all modules in the Modules folder.",
            "lua_type": "table",
            "source": {
                "line": 64,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Shared",
            "desc": "Contains all modules that is stored in the Modules Folder.",
            "lua_type": "table",
            "source": {
                "line": 71,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Packages",
            "desc": "Contains all modules in the Packages folder.",
            "lua_type": "table",
            "source": {
                "line": 78,
                "path": "src/CServerInternal.lua"
            }
        },
        {
            "name": "Util",
            "desc": "Contains all modules in the Packages folder.",
            "lua_type": "table",
            "deprecated": {
                "version": "v1.0.0",
                "desc": null
            },
            "source": {
                "line": 86,
                "path": "src/CServerInternal.lua"
            }
        }
    ],
    "types": [],
    "name": "CradleServer",
    "desc": "This is the API Documentation for the Cradle module. It contains all the API functions for the server.\n\n```lua\nlocal Cradle = require(game:GetService(\"ReplicatedStorage\").Cradle)\n```",
    "realm": [
        "Server"
    ],
    "source": {
        "line": 11,
        "path": "src/CServerInternal.lua"
    }
}