C_FunctionContainers.CreateCallback

From Warcraft Wiki
Jump to navigation Jump to search
Flavors
Links
Info
Added in 10.0.0 / 1.15.0

Creates a function container that invokes a cancellable callback function.

container = C_FunctionContainers.CreateCallback(func)

Arguments

func
function - A Lua function to be called.

Returns

container
FunctionContainer - A container object bound to the supplied function.

Details

  • The supplied callback must be a Lua function. The API will reject C functions and any non-function values.

Example

The following snippet creates a function container and schedules it to be executed every second, cancelling itself after five calls.

local container
container = C_FunctionContainers.CreateCallback(function()
    container.timesCalled = container.timesCalled + 1

    if container.timesCalled == 5 then
        container:Cancel()
    end

    print("Called!")
end)

container.timesCalled = 0
C_Timer.NewTicker(1, container)

Patch changes