Skip to main content

Route

A Networking Library, inspired by BridgeNet2 & Bevy_Renet, made for ECS.

See the Intro to get started.

Types

Configuration

interface Configuration {
Channel("Reliable" | "Unreliable")?--

Default: Reliable

Eventstring?--

The event to schedule the Route on in your Matter Loop -- Default: "default"

Ratelimitnumber?--

Amount of allowed invocations a frame

}
NOTE

Ratelimiting is not implemented yet. This feature will come in future versions.

Channel

Reliable: All packets will be sent and received per frame in order. Unreliable: Packets may be dropped but will be received in order.

Functions

new

Route.new(configurationConfiguration?) → ()

Creates a new Route with a unique identifier, channel, and event.

NOTE

All Routes with the same Channel will share a single Remote. It's recommended that you run all your Net scheduling code on a single event.

query

Route:query() → QueryResult

Allows for iteration of all packets of the previous frame. You can filter by Senders by chaining the QueryResult:from() method onto the query method.

NOTE

Due to certain limitations with the Luau Type System, iterating over the QueryResult Object will not return typed values. In order to fix this, call :__iter() on the QueryResult Object.

For example:

for i, sender, ... in route:query():__iter() do
	-- Do something
end

See Querying Data for more information.

send

Route:send(...U...) → SendRequest

Sends data to all clients or to specific recipients from the Route's identifier.

By default, Route:send will send the data to all Clients. You can specify which Clients to receive the data by chaining SendRequest:to and passing { Player }, Player, or Route.Server.

See Sending Data for more information.

addIncomingMiddleware

Route:addIncomingMiddleware((...any) → (...any?)) → ()

Sets a function to be ran on Incoming packets before they are processed. For example, this would run after the Client receives a Packet from the Server over the network: after calling Route:send() on the Server and before calling Route:query() on the Client.

See Middleware for more information.

addOutgoingMiddleware

Route:addOutgoingMiddleware((...any) → (...any?)) → ()

Sets a function to be ran on Outgoing packets before they are sent over the network. For example, this would run before the Server sends a Packet to the Client over the network: after calling Route:send() on the Server and before the Client ever receives the Packet.

See Middleware for more information.

Show raw api
{
    "functions": [
        {
            "name": "__iter",
            "desc": "Creates a QueryResult that returns all Packets in the current frame's snapshot\nfrom the Route's identifier.\n\nSee [Route:query] to filter by Senders.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryResult"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 113,
                "path": "lib/init.luau"
            }
        },
        {
            "name": "query",
            "desc": "Allows for iteration of all packets of the previous frame.\nYou can filter by Senders by chaining the ``QueryResult:from()`` method onto the query method.\n\n:::note\nDue to certain limitations with the Luau Type System, iterating over the QueryResult Object\nwill not return typed values. In order to fix this, call ``:__iter()`` on the QueryResult Object.\n\nFor example:\n```lua\nfor i, sender, ... in route:query():__iter() do\n\t-- Do something\nend\n```\n:::\n\nSee [Querying Data](/docs/getting-started/routes#querying) for more information.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryResult"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 140,
                "path": "lib/init.luau"
            }
        },
        {
            "name": "send",
            "desc": "Sends data to all clients or to specific recipients from the Route's identifier.\n\nBy default, [Route:send] will send the data to all Clients. You can specify which\nClients to receive the data by chaining [SendRequest:to] and passing\n``{ Player }``, ``Player``, or ``Route.Server``.\n\nSee [Sending Data](/docs/getting-started/routes#sending) for more information.",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "U..."
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SendRequest"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 159,
                "path": "lib/init.luau"
            }
        },
        {
            "name": "_queuePackets",
            "desc": "Processes the Route's internal queue and sends it to the supplied Bridge.\nDoing this will reset the internal queue.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 183,
                "path": "lib/init.luau"
            }
        },
        {
            "name": "addIncomingMiddleware",
            "desc": "Sets a function to be ran on Incoming packets before they are processed.\nFor example, this would run after the Client receives a Packet from the Server over the network:\nafter calling ``Route:send()`` on the Server and before calling ``Route:query()`` on the Client.\n\nSee [Middleware](/docs/getting-started/middleware) for more information.",
            "params": [
                {
                    "name": "(...any)",
                    "desc": "",
                    "lua_type": "-> (...any?)"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "()"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 276,
                "path": "lib/init.luau"
            }
        },
        {
            "name": "addOutgoingMiddleware",
            "desc": "Sets a function to be ran on Outgoing packets before they are sent over the network.\nFor example, this would run before the Server sends a Packet to the Client over the network:\nafter calling ``Route:send()`` on the Server and before the Client ever receives the Packet.\n\nSee [Middleware](/docs/getting-started/middleware) for more information.",
            "params": [
                {
                    "name": "(...any)",
                    "desc": "",
                    "lua_type": "-> (...any?)"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "()"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 297,
                "path": "lib/init.luau"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new Route with a unique identifier, channel, and event.\n\n:::note\nAll Routes with the same Channel will share a single Remote. It's recommended that you run all your\nNet scheduling code on a single event.\n:::",
            "params": [
                {
                    "name": "configuration",
                    "desc": "",
                    "lua_type": "Configuration?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 318,
                "path": "lib/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "Configuration",
            "desc": ":::note\nRatelimiting is not implemented yet. This feature will come in future versions.\n:::\n\n### Channel\n\n**Reliable**: All packets will be sent and received per frame in order.\n**Unreliable**: Packets may be dropped but will be received in order.",
            "fields": [
                {
                    "name": "Channel",
                    "lua_type": "(\"Reliable\" | \"Unreliable\")?",
                    "desc": "Default: Reliable"
                },
                {
                    "name": "Event",
                    "lua_type": "string?",
                    "desc": "The event to schedule the Route on in your Matter Loop -- Default: \"default\""
                },
                {
                    "name": "Ratelimit",
                    "lua_type": "number?",
                    "desc": "Amount of allowed invocations a frame"
                }
            ],
            "source": {
                "line": 45,
                "path": "lib/init.luau"
            }
        }
    ],
    "name": "Route",
    "desc": "A Networking Library, inspired by BridgeNet2 & Bevy_Renet, made for ECS.\n\nSee the [Intro](/docs/intro) to get started.",
    "source": {
        "line": 58,
        "path": "lib/init.luau"
    }
}