Catches a hook. This function is used to act on hooks/events.
bait.catch(name, cb)
+
Catches an event. This function can be used to act on events.
Parameters
string name
The name of the hook.
function cb
The function that will be called when the hook is thrown.
Example
-
bait.catch('hilbish.exit', function()
- print 'Goodbye Hilbish!'
-end)
+1bait.catch('hilbish.exit', function()
+2 print 'Goodbye Hilbish!'
+3end)
bait.catchOnce(name, cb)
-
Same as catch, but only runs the cb once and then removes the hook
Parameters
-
This function has no parameters.
bait.hooks(name) -> table
-
Returns a table with hooks (callback functions) on the event with name.
Parameters
-
This function has no parameters.
bait.release(name, catcher)
+
Catches an event, but only once. This will remove the hook immediately after it runs for the first time.
Parameters
+
string name
The name of the event
function cb
The function that will be called when the event is thrown.
bait.hooks(name) -> table
+
Returns a list of callbacks that are hooked on an event with the corresponding name.
Parameters
+
string name
The name of the function
bait.release(name, catcher)
Removes the catcher for the event with name.
For this to work, catcher has to be the same function used to catch
an event, like one saved to a variable.
Parameters
-
This function has no parameters.
bait.throw(name, ...args)
-
Throws a hook with name with the provided args
Parameters
+
string name
Name of the event the hook is on
function catcher
Hook function to remove
Example
+
1local hookCallback = function() print 'hi' end
+2
+3bait.catch('event', hookCallback)
+4
+5-- a little while later....
+6bait.release('event', hookCallback)
+7-- and now hookCallback will no longer be ran for the event.
+
bait.throw(name, ...args)
+
Throws a hook with name with the provided args.
Parameters
string name
The name of the hook.
any args (This type is variadic. You can pass an infinite amount of parameters with this type.)
The arguments to pass to the hook.