util.export.register
Shared
Registers an exported function for the calling resource
Syntax
local status = util.export.register(
name,
exec
)Exports allow resources to expose functions to other resources.
- Scoped to the resource — the export is automatically tied to the resource that calls
util.export.register; it cannot be registered from outside a resource environment. - Overwrite behaviour — registering an export under a name that already exists will silently replace the previous function.
- Lifecycle — all export registered by a resource are automatically cleaned up when that resource stops.
Parameters
| Type | Name | Description |
|---|---|---|
string | name | Unique name to identify this export within the resource |
function | exec | Function to expose; called when another resource invokes util.export.call with this name |
Returns
| Type | Name | Description |
|---|---|---|
bool | status | true on successful registration, false otherwise |
Examples
util.export.register("get_player_count", function()
return 42
end)util.export.register("add", function(a, b)
return a + b
end)util.export.register("greet", function(name)
return "Hello, " .. name .. "!"
end)
util.export.register("farewell", function(name)
return "Goodbye, " .. name .. "!"
end)util.export.register("get_status", function()
return "initialising"
end)
-- Later in the same resource, replace it with a live value:
util.export.register("get_status", function()
return "running"
end)