Skip to main content

function

Macro function 

Source
macro_rules! function {
    {// #0
        $name:ident ($($arguments:tt)+) $(-> $return_type:ty)? $body:block
    } => { ... };
    (// #1
        $name:ident use $func:path
    ) => { ... };
    (// #2
        @Return $return_type:ty
    ) => { ... };
    (// #3
        @Return
    ) => { ... };
    {// #4
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        $ctx:ident, $data:ident, $args:ident $(,)?
    } => { ... };
    {// #5
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        $ctx:ident, $data:ident, _ $(,)?
    } => { ... };
    {// #6
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        $ctx:ident, _, $args:ident $(,)?
    } => { ... };
    {// #7
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        _, $data:ident, $args:ident $(,)?
    } => { ... };
    {// #8
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        _, _, $args:ident $(,)?
    } => { ... };
    {// #9
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        _, $data:ident, _ $(,)?
    } => { ... };
    {// #10
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        $ctx:ident, _, _ $(,)?
    } => { ... };
    {// #11
        @Parameters [$c:ident, $d:ident, $a:ident $(,)?]
        _, _, _ $(,)?
    } => { ... };
}
Expand description

Defines a function intended for context registration by generating its ABI-compatible wrapper and binding it to a Rust implementation.

Expands to a &'static constant of type FunctionImplementation, intended to be added to a FunctionSet.

This macro supports two forms: one that defines a function inline, and another that binds to an existing Function using the use keyword.

For larger or more complex implementations, the latter can provide better IDE support. However, it introduces two distinct items with the same semantics, so naming should be chosen carefully to avoid confusion.

§Panics and Debugging

If a panic occurs on the call stack, the process will abort. The runtime may print a backtrace to stderr, but it may lack sufficient symbol information (such as function names and source locations) for meaningful debugging.

For example, when using the MSVC toolchain on Windows, including the generated .pdb file alongside the .dll (in the .ane package) allows debuggers and crash reporting tools to resolve symbols and produce human-readable stack traces.

§Full Examples

mod lib {
    use fre_rs::prelude::*;
    fre_rs::function! {
        method_name (ctx, data, args) -> Object {
            return ctx.get_actionscript_data();
        }
    }
    fre_rs::function! (method_name2 use method_implementation);
    fn method_implementation <'a> (ctx: &mut CurrentContext<'a>, data: Option<&mut dyn Any>, args: &[Object<'a>]) -> Object<'a> {as3::null}
}

§Minimal Examples

mod lib {
    fre_rs::function! {
        method_name (_, _, _) {}
    }
}