Connections
This page provides an overview of the getconnections function, its uses, and its implementation internally in RbxStu V3.
Connections in Roblox are, in general, a weird concept. They come in two forms.
C Connections
and.Luau Connections
Luau connections are connections formed using the RBXScriptSignal
structure, while C connections are natively created using the C implementation of it, instead of its Luau abstraction.
To interact with connections, you can make use of the UNC-defined getconnections
function.
High-Level Overview:
getconnections
works by obtaining the connections that are part of the RBXScriptSignal's linked list and pushing a Luau representation of the native structures.
Low-Level Overview:
getconnections
works by first obtaining a pointer to the head of the list. This is done by first establishing a connection itself using :Connect
, obtaining anRBXScriptConnection
, also known as a SignalBridge
in some cases. This signal bridge holds pointers to the head of the list and to the 'owner,' being the signal itself. After obtaining the respective pointer, it is dereferenced over and over until we reach the end of the list, pushing an abstraction that will do the required modifications to the structure with each function.
Remarks
All connections are only being fired on the client. No connection is ever fired to the server side when using the Connections API. This is why functions like replicatesignal
exist, as there is no way to replicate signals using the approach getconnection
uses.
RbxStuConnection
This is an abstraction on top of the ROBLOX connection structure, it can be used to manage all the aspects of a Luau Connection, yet not all of a C connection.
Fields
Enabled:
boolean
If true, the connection is fired when the event is triggered, else, it is false.
Function:
function
?
This field is
nil
onC Connections
and on connections that were established in another Luau VM (Actor/different global state).
LuaConnection:
boolean
Whether the connection was established using C or Luau, resulting in false or true, respectively.
ForeignState:
boolean
Whether the connection was established in another Luau VM (Actor/different global state).
Thread:
thread
The thread that established the connection.
This field is
nil
onC Connections
and on connections that were established in another Luau VM (Actor/different global state).
Functions
function
RbxStuConnection:Fire(...) -> ()
Proxy to RbxStuConnection:Defer(...)
function
RbxStuConnection:Defer(...) -> ()
Fires the connection by utilising
task.defer
on a new thread created by the Roblox global state; this prevents potentialEnvironment Hijack
attempts.Connections formed by another Luau VM will not be fired and will error on call.
Attempting to call
C Connections
will error due to security complications.
function
RbxStuConnection:Disable() -> ()
This function will disable the connection from being fired; however, it will not disconnect it.
function
RbxStuConnection:Enable() -> ()
This function will allow the connection to be fired when the event is triggered.
function
RbxStuConnection:Disconnect() -> ()
This function will disconnect the connection by calling
RBXScriptConnection:Disconnect()
on it.This allows the developer to know you have disconnected it; thus, unless you want to be destructive, it is heavily recommended to use
RbxStuConnection:Enable()
andRbxStuConnection:Disable()
instead.
Remarks
While firing across Luau VMs is planned to be supported, it is currently not included on the alpha release of RbxStu V3 due to security concerns with memory corruptions by potentially passing GCables across the LVM boundary, which could at any moment be freed by the other Luau VM, resulting in dangerous conditions.
Low-Level Overview
The Function
andThread
fields are referenced on the Luau Registry
. This means you can grab the function from the field and search for it in the Lua Registry
. This also means you could replace it yourself using hookfunction
, creating hookconnection
if you will; this also means (most likely) that if a thread or function is present on the,Luau Registry
then it is likely it is the result of an RBXScriptSignal connection.
Examples
Obtaining all connections of an RBXScriptSignal
Disabling all connections of an RBXScriptSignal
Disconnecting all connections of an RBXScriptSignal
There is no alternative API to the Connections API, and there are no plans to include replicatesignal
due to its potential complexity.
Last updated