A minimal, cross-platform Tcl interpreter implemented in Rust.
- Lightweight: Designed for embedded systems and resource-constrained environments
- Cross-Platform: Runs on native, wasm32-unknown-unknown, and wasm32-wasip1 targets
- Tcl Compatible: Supports familiar Tcl syntax and commands
- Expect Support: Process automation capabilities similar to classic
expect - Embedded Ready: Optional
embeddedfeature forno_stdenvironments withalloc
cargo build --release# Execute a script file
./target/release/rtcl -f script.tcl
# Evaluate a command
./target/release/rtcl -c "puts hello"# Interactive REPL
./target/release/rtcl -irtcl> set x 42
42
rtcl> puts "x = $x"
x = 42
rtcl> expr 1 + 2 * 3
7
rtcl> .exit
| Command | Description |
|---|---|
set | Get or set a variable |
puts | Print a string |
if | Conditional execution |
while | While loop |
for | For loop |
foreach | Iterate over list |
expr | Evaluate expression |
proc | Define procedure (limited) |
return | Return from procedure |
break | Exit loop |
continue | Continue to next iteration |
| Command | Description |
|---|---|
list | Create a list |
llength | Get list length |
lindex | Get list element |
lappend | Append to list variable |
concat | Concatenate strings |
| Command | Description |
|---|---|
string length | String length |
string range | Substring |
string tolower | Lowercase |
string toupper | Uppercase |
string trim | Trim whitespace |
| Command | Description |
|---|---|
incr | Increment variable |
append | Append to string variable |
catch | Catch errors |
error | Throw error |
info exists | Check variable |
info commands | List commands |
rename | Rename/delete command |
eval | Evaluate script |
uplevel | Evaluate in caller scope |
Supports standard Tcl expressions:
expr 1 + 2 * 3 ; => 7
expr $x > 0 ; => 1 (true)
expr {$a == $b} ; comparison
expr {abs(-5)} ; function call
Supported operators: +, -, *, /, %, <, >, <=, >=, ==, !=, &&, ||, !
Supported functions: abs, int, double, round, floor, ceil, sqrt, pow, sin, cos, tan, log, exp, min, max
use rtcl_expect::{spawn,ExpectError};letmut proc = spawn("ssh",&["user@host"])?;
proc.expect("password:",Duration::from_secs(10))?;
proc.send_line("mypassword")?;rtcl/
├── crates/
│ ├── rtcl-core/ # Core interpreter (cross-platform, wasm/wasi compatible)
│ ├── rtcl-cli/ # Command-line interface
│ └── rtcl-expect/ # Expect-style process automation
└── tasks/ # Task files for development
| Target | Status |
|---|---|
| Native (Linux, macOS, Windows) | ✅ Supported |
| wasm32-unknown-unknown | ✅ Supported |
| wasm32-wasip1 | ✅ Supported |
# Cargo.toml
[dependencies]
rtcl-core = { version = "0.1", default-features = false }use rtcl_core::{Interp,Value};letmut interp = Interp::new();
interp.eval("set x 42").unwrap();For no_std environments with alloc:
# Cargo.toml
[dependencies]
rtcl-core = { version = "0.1", default-features = false, features = ["embedded"] }#![no_std]externcrate alloc;use rtcl_core::{Interp,Value};letmut interp = Interp::new();
interp.eval("set x 42").unwrap();- Procedure definitions are simplified
- No namespace support yet
- Limited error stack traces
- Some string commands may differ slightly
BSD 2-Clause License (same as jimtcl)