Signal
Lua-side duplication of the API of events on Roblox objects.
Signals are needed for to ensure that for local events objects are passed by reference rather than by value where possible, as the BindableEvent objects always pass signal arguments by value, meaning tables will be deep copied. Roblox's deep copy method parses to a non-lua table compatable format.
This class is designed to work both in deferred mode and in regular mode. It follows whatever mode is set.
local signal = Signal.new()
local arg = {}
signal:Connect(function(value)
assert(arg == value, "Tables are preserved when firing a Signal")
end)
signal:Fire(arg)
info
Why this over a direct BindableEvent? Well, in this case, the signal prevents Roblox from trying to serialize and desialize each table reference fired through the BindableEvent.
Functions
isSignal
Signal.
isSignal
(
value:
any
) →
boolean
Returns whether a class is a signal
new
Constructs a new signal.
Fire
Signal:
Fire
(
...:
T
--
Variable arguments to pass to handler
) →
(
)
Fire the event with the given arguments. All handlers will be invoked. Handlers follow
Connect
Signal:
Connect
(
handler:
(
...
T
)
→
(
)
--
Function handler called when :Fire(...)
is called
) →
RBXScriptConnection
Connect a new handler to the event. Returns a connection object that can be disconnected.
Once
Signal:
Once
(
handler:
(
...
T
)
→
(
)
--
One-time function handler called when :Fire(...)
is called
) →
RBXScriptConnection
Connect a new, one-time handler to the event. Returns a connection object that can be disconnected.
Wait
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsSignal:
Wait
(
) →
T
Wait for fire to be called, and return the arguments it was given.
Destroy
Signal:
Destroy
(
) →
(
)
Disconnects all connected events to the signal. Voids the signal as unusable. Sets the metatable to nil.