Skip to main content

Crate rtea

Crate rtea 

Source
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§

Interpreter
A wrapper around a Tcl interpreter object.
Object
ObjectType
A wrapper for Tcl object types.
RawObject
A wrapper for Tcl objects.
StatefulCommand
A wrapper for creating stateful commands.
TclBuf
An owned buffer of Tcl-managed memory.

Enums§

Error
Error codes for unwrapping a Tcl interpreter.
TclStatus
A wrapper for Tcl return status codes.
TclUnloadFlag
A wrapper for values passed to Tcl’s unload function.

Traits§

TclObjectType

Functions§

tcl_string
Allocates a null-terminated copy of rust_str in Tcl-managed memory and returns it as a TclBuf.

Attribute Macros§

module_init
Helper for creating the initialization function for Tcl extensions.
module_safe_init
Helper for creating the “safe” initialization function for Tcl extensions.
module_safe_unload
Helper for unloading a “safe” Tcl extensions
module_unload
Helper for unloading a Tcl extension.

Derive Macros§

TclObjectType
Creates a Tcl Object Type for this struct