Expand description
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.
Structs§
- A wrapper around a Tcl interpreter object.
- A wrapper for Tcl object types.
- A wrapper for creating stateful commands.
Enums§
- Error codes for unwrapping a Tcl interpreter.
- A wrapper for Tcl return status codes.
- A wrapper for values passed to Tcl’s unload function.
Attribute Macros§
- Helper for creating the initialization function for Tcl extensions.