3 unstable releases
0.2.0 | Feb 5, 2022 |
---|---|
0.1.1 | Nov 14, 2021 |
0.1.0 | Nov 14, 2021 |
#5 in #tea
22 downloads per month
60KB
1K
SLoC
Rust Tcl Extension Architecture (rtea)
Makes writing Tcl extensions in Rust ergonomic.
lib.rs
:
rtea tries to be the Rust TEA (Tcl Extension Architecture).
The library provides the necessary wrappers around the Tcl stubs implentation to write a "rusty" extension to Tcl without having to use unsafe code.
Example
The following example assumes that you are in the root directory of a project
with a cdylib
target and the two files given below. If you execute:
cargo build
tclsh example.tcl
Then you should see the following output:
Hello, world!
Hello from Rust!
src/lib.rs
use rtea::*;
#[module_init(Example, "1.0.0")]
fn init(interp: &Interpreter) -> Result<TclStatus, String> {
interp.create_command("example", example)
}
fn example(interp: &Interpreter, args: Vec<&str>) -> Result<TclStatus, String> {
interp.eval("puts {Hello, world!}").map_err(|e| e.get_string().to_string())?;
interp.set_result("Hello from Rust!");
Ok(TclStatus::Ok)
}
example.tcl
load ./target/debug/libexample.so
puts [example]
The Tcl code above uses load
just to show that the module can properly
interact with Tcl. Production uses should wrap the shared object as a
Tcl package and load it using package require example
.
The module_init
macro already handles registering the "example"
package.
Note
This code assumes that it extends Tcl and treats any violations of Tcl's API (unexpected null-pointers, non-UTF8 strings, etc.) as irrecovable errors that should panic.