This project provides safe and easy to use API bindings to Tcl programming language.
Convert between Rust values and Tcl objects.
Serde data format of Tcl objects.
Run Tcl scripts.
Register Rust functions/closures as tcl commands.
std::Convert
between Rust values and Tcl objects.```rust use std::convert::TryFrom; use tcl::*;
let obj = Obj::from( 0 ); asserteq!( obj.tostring(), "0" ); asserteq!( i32::tryfrom( obj )?, 0 );
let obj = Obj::from( 1 ); asserteq!( obj.asi32(), 1 ); asserteq!( obj.asf64(), 1.0 ); asserteq!( obj.asbool(), true );
let obj = Obj::from(( false, 42, "answer".toowned() )); asserteq!( obj.tostring(), "0 42 answer" ); asserteq!( <(bool,i32,String)>::tryfrom( obj )?, (false, 42, "answer".toowned() ) );
let v = vec![ "alpha".toowned(), "beta".toowned(), "gamma".toowned() ];
let obj: Obj = v.clone().into();
asserteq!( obj.tostring(), "alpha beta gamma" );
asserteq!( Vec::
use std::collections::HashMap;
let mut map = HashMap::new(); map.insert( "alpha".toowned(), 1 ); map.insert( "beta" .toowned(), 2 ); map.insert( "gamma".to_owned(), 3 );
let obj: Obj = map.clone().into();
asserteq!( HashMap::
```
deserialize
d / try_from
Tcl objects.```rust use tcl::*;
struct Struct{ a: i32, b: bool, c: f64 }
let obj = Obj::from( "a 1 b false c 3.14" ); let v: Struct = fromobj( obj.clone() )?; asserteq!( v, Struct{ a: 1, b: false, c: 3.14 });
let v: Struct = obj.clone().tryinto()?; asserteq!( v, Struct{ a: 1, b: false, c: 3.14 });
```
Tcl<T>
to store Rust values in Tcl Obj
s, an vice-vesa.```rust use std::convert::TryFrom; use tcl::*;
let obj = Tcl::newobj( vec![ 1, 1, 2, 3, 5, 8 ]);
let tclobj = Tcl::
```
```rust use tcl::*;
let interpreter = Interpreter::new()?; let a = 3; let b = 7; let c = interpreter.eval(( "expr", a, "", b ))?; assert_eq!( ab, c.as_i32() );
```
```rust use tcl::*;
let interpreter = Interpreter::new()?;
unsafe { // it's safe for #[proc] fn
.
interpreter.defproc( "mul", mul );
}
let c = interpreter.eval( "mul 3 7" )?;
asserteq!( c.as_i32(), 21 );
```
```rust use tcl::*;
let interpreter = Interpreter::new()?;
let cmd = tclfn!( &interpreter, /cmd: "mul", args: "",/
fn mul( a: i32, b: i32 ) -> TclResult
let c = interpreter.eval( "mul 3 7" )?; asserteq!( c.asi32(), 21 );
```
```rust use tcl::*;
let offset = 0; let interpreter = Interpreter::new()?;
let cmd = tclosure!( &interpreter, /cmd: "mul", args: "",/
move |a: i32, b: i32| -> TclResult
let a = 3; let b = 7; let c = interpreter.eval(( "eval", cmd, a, b ))?; asserteq!( c.asi32(), 21 );
```
Under Apache License 2.0 or MIT License, at your will.