config

Macro declare_event

Source
macro_rules! declare_event {
    ($vis:vis static $sym:ident: Multiple($name:literal $(,)? $($param_name:ident: $args:ty),* $(,)? ) -> $ret:ty;) => { ... };
    ($vis:vis static $sym:ident: Single($name:literal $(,)? $($param_name:ident: $args:ty),* $(,)? ) -> $ret:ty;) => { ... };
}
Expand description

Helper for declaring a named event handler callback signature.

Usage looks like:

declare_event! {
pub static GET_Q_CONFIG_SIG: Multiple(
        "get_queue_config",
        domain: &'static str,
        tenant: Option<&'static str>,
        campaign: Option<&'static str>,
        routing_domain: Option<&'static str>,
    ) -> QueueConfig;
}

A handler can be either Single or Multiple, indicating whether only a single registration or multiple registrations are permitted. The string literal is the name of the event, followed by a fn-style parameter list which names each parameter in sequence, followed by the return value. The names are not currently used in any way, but enhance the readability of the code.

In addition to declaring the signature in a global, some glue is generated that will register the signature appropriately so that lua knows whether it is single or multiple and can act appropriately when kumo.on is called.