Module ui.hook_container
HookContainer allows listeners to register and unregister a hook for speakers to execute.
It's an experimental feature: use with cautions, it can easily pin an object in memory and unblock GC from recycling the memory.
Functions
HookContainer:register (name, func) | Register a function to name. |
HookContainer:registerWidget (name, widget) | Register a widget to name. |
HookContainer:unregister (name, func) | Unregister a function from name. |
HookContainer:execute (name, args) | Execute all registered functions of name. |
Functions
- HookContainer:register (name, func)
-
Register a function to name. Must be called with self.
Parameters:
- name string The name of the hook. Can only be an non-empty string.
- func function The function to handle the hook. Can only be a function.
- HookContainer:registerWidget (name, widget)
-
Register a widget to name. Must be called with self.
Parameters:
- HookContainer:unregister (name, func)
-
Unregister a function from name. Must be called with self.
Parameters:
- name string The name of the hook. Can only be an non-empty string.
- func function The function to handle the hook. Can only be a function.
Returns:
-
boolean
Return true if the function is found and removed, otherwise false.
- HookContainer:execute (name, args)
-
Execute all registered functions of name. Must be called with self.
Parameters:
- name string The name of the hook. Can only be an non-empty string.
- args Any kind of arguments sending to the functions.
Returns:
-
number
The number of functions have been executed.