Callbacks
The Callbacks module provides a standalone, framework-agnostic system for registering and triggering callbacks between the client and server.
Accessing the Module
local CALLBACKS <const> = exports.boii_utils:get("modules.callbacks")
Server
register_callback(name, cb)
Registers a server-side callback that clients can trigger.
Parameters
Name
Type
Description
name
string
The unique identifier for the callback event.
cb
function
The function to execute when the callback is triggered.
Example
CALLBACKS.register("get_server_time", function(source, data, cb)
local response = {
unix = os.time(),
hour = GetClockHours()
}
cb(response)
end)
Client
trigger_callback(name, data, cb)
Triggers a server-side callback and handles the result asynchronously.
Parameters
Name
Type
Description
name
string
The event name to trigger.
data
table
Optional data to send to the server.
cb
function
Callback function to handle the response. Signature: function(response)
Example
CALLBACKS.trigger("get_server_time", nil, function(response)
print("Unix time:", response.unix)
print("In-game hour:", response.hour)
end)
Last updated