tclosure!() { /* proc-macro */ }
Expand description
Helps to register rust closures as Tcl commands
Syntax
tclosure!( interp, cmd, args, closure )
Input parameters
-
interp, the Tcl interpreter instance.
-
cmd, the name of the command being registered in Tcl. Optional.
-
args, the arguments provided in Tcl on executing the command. Optional.
-
closure, the closure defined in Rust.
Output
Returns a String
of the command name.
Example
use tcl::*;
let offset = 0;
let interpreter = Interpreter::new()?;
let cmd = tclosure!( &interpreter, /*cmd: "mul", args: "",*/
move |a: i32, b: i32| -> TclResult<i32> { Ok( a * b + offset )}
);
let a = 3;
let b = 7;
let c = interpreter.eval(( "eval", cmd, a, b ))?;
assert_eq!( c.as_i32(), 21 );