Macro tcl::tclosure

source ·
tclosure!() { /* proc-macro */ }
Expand description

Helps to register rust closures as Tcl commands

Syntax

tclosure!( interp, cmd, args, closure )

Input parameters

  1. interp, the Tcl interpreter instance.

  2. cmd, the name of the command being registered in Tcl. Optional.

  3. args, the arguments provided in Tcl on executing the command. Optional.

  4. 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 );