Macro tcl::tclfn

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

Helps to register rust functions as Tcl commands

Syntax

tclfn!( interp, cmd, args, func )

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. func, the function defined in Rust.

Output

Returns a String of the command name.

Example


use tcl::*;

let interpreter = Interpreter::new()?;

let cmd = tclfn!( &interpreter, /*cmd: "mul", args: "",*/
    fn mul( a: i32, b: i32 ) -> TclResult<i32> { Ok( a * b )}
);

let c = interpreter.eval( "mul 3 7" )?;
assert_eq!( c.as_i32(), 21 );