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

TypeNameDescription
stringnameUnique name to identify this export within the resource
functionexecFunction to expose; called when another resource invokes util.export.call with this name

Returns

TypeNameDescription
boolstatustrue on successful registration, false otherwise

Examples

Register a simple export
util.export.register("get_player_count", function()
    return 42
end)
Register an export that accepts arguments
util.export.register("add", function(a, b)
    return a + b
end)
Register multiple export from the same resource
util.export.register("greet", function(name)
    return "Hello, " .. name .. "!"
end)

util.export.register("farewell", function(name)
    return "Goodbye, " .. name .. "!"
end)
Overwrite an existing export
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)

On this page