function_call

Macro function_call 

Source
macro_rules! function_call {
    ($function: ident, $($args:expr), +) => { ... };
    ($function: ident) => { ... };
}
Expand description

Macro for convenient function calling with automatic argument conversion.

This macro simplifies calling functions by automatically converting arguments to Variables and handling the function call syntax.

ยงExamples

use plux_rs::{function_call, function::{Function, DynamicFunction, Arg, FunctionOutput}};
use plux_rs::variable::VariableType;

let add = DynamicFunction::new(
    "add",
    vec![
        Arg::new("a", VariableType::I32),
        Arg::new("b", VariableType::I32),
    ],
    Some(Arg::new("result", VariableType::I32)),
    |args| -> FunctionOutput {
        let a = args[0].parse_ref::<i32>();
        let b = args[1].parse_ref::<i32>();
        Ok(Some((a + b).into()))
    }
);

// Call with arguments
let result = function_call!(add, 5, 3);
assert_eq!(result.unwrap(), Some(8.into()));

// Call without arguments
let no_args_func = DynamicFunction::new(
    "hello",
    vec![],
    Some(Arg::new("message", VariableType::String)),
    |_| -> FunctionOutput { Ok(Some("Hello!".into())) }
);
let message = function_call!(no_args_func);