#[hook]
Expand description
The hook
attribute is used to define functions that may be used as proc hooks,
and to optionally hook those procs upon library initialization.
Examples
Here we define a hook that multiplies a number passed to it by two.
It can now be used to hook procs, for example hooks::hook("/proc/double_up", double_up);
ⓘ
#[hook]
fn double_up(num: Value) {
if let Some(num) = num.as_number() {
Value::from(num * 2.0);
}
Value::null()
}
This function is used to hook /mob/proc/on_honked
.
By specifying the proc path, we hook the proc immediately upon startup.
ⓘ
#[hook("/mob/proc/on_honked")]
fn on_honked(honker: Value) {
src.call("gib", &[]);
honker.call("laugh", &[]);
Value::null()
}