Struct FunctionContainer

From Warcraft Wiki
Jump to navigation Jump to search

FunctionContainer objects wrap a single Lua function to be executed later as a callback from native APIs.

Function containers are exposed to the scripting environment as userdata handles with a set of predefined methods to control execution of the callback. It is permitted to store additional user-defined fields on function containers, so long as they do not conflict with any of the predefined methods.

Methods

FunctionContainer:Cancel() - Cancels the callback, preventing the stored function from being called.
FunctionContainer:Invoke(...) - Invokes the callback if not cancelled, passing the supplied arguments. Does not return any values.
FunctionContainer:IsCancelled() - Checks if the stored callback has been cancelled.

Details

  • Function containers objects can be supplied in-place of function arguments to some APIs such as C_Timer.After.
  • Function containers can only store Lua functions.
    • It is not possible to create a function container that directly calls a native API function, nor any function that has been securely hooked.
    • It is also not possible to create a function container that will call a non-function value, including objects with a __call metamethod.
  • It is not possible to use standard Lua functions such as next or pairs to iterate over any stored fields on function container objects.
  • Attempting to replace any predefined methods will raise an "Attempted to assign to read-only key" error.
  • The stored function within the container cannot be retrieved.

Patch changes

See also