Skip to content

Connect

Connect sets a callback for a given message when it is sent. A message can only have one connection, but you can always connect your messages into a choice signal implementation. Callbacks can be removed with light.disconnect(). Message callbacks will be spawned asynchronously with thread reuse. To create a non-yielding callback you can use light.connect_sync()

This function can error if there is already a callback connected.

Consider calling light.disconnect() first if this is an issue.

function light.connect

Client Synchronous Errors
1
2
3
4
function connect<Data>(
    message: Message<Data>,
    callback: (Data) -> ()
): ()

function light.connect

Server Synchronous Errors
1
2
3
4
function connect<Data>(
    message: Message<Data>,
    callback: (Player, Data) -> ()
): ()

Some example code using light.connect():

1
2
3
light.connect(messages.ping, function(player)
    print("pong!")
end)