Crate rtea_proc

Crate rtea_proc 

Source
Expand description

rtea-proc provides macros to ergonomically wrap the initialization and unload functions expected by TEA.

The library provides the simple macros to conveniently wrap Rust initialization and unload functions without having to deal with extern "C" or raw pointers.

§Example

use rtea::{Interpreter, TclStatus, TclUnloadFlag}; // Implicit dependency of macro when invoked.

#[module_init(Example, "1.0.0")]
fn init(interp: &Interpreter) -> Result<TclStatus, String> {
    safe_init(interp, args)?;
    // Add additional commands that may not be safe for untrusted code...
    Ok(TclStatus::Ok)
}

#[module_safe_init(Example, "1.0.0")]
fn safe_init(_interp: &Interpreter) -> Result<TclStatus, String> {
    // Add commands that are safe even for untrusted code...
    Ok(TclStatus::Ok)
}

#[module_unload(Example)]
fn unload(interp: &Interpreter) -> Result<TclStatus, String> {
    safe_unload(interp, args)?;
    // Remove the additional commands that were not considered "safe"...
    Ok(TclStatus::Ok)
}

#[module_safe_unload(Example)]
fn safe_unload(_interp: &Interpreter) -> Result<TclStatus, String> {
    // Remove the "safe" set of commands
    Ok(TclStatus::Ok)
}

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

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