3 stable releases
2.0.0 | Feb 5, 2022 |
---|---|
1.0.1 | Nov 14, 2021 |
#16 in #tcl
Used in rtea
11KB
116 lines
rtea-proc
Provides the procedural macros for making rtea more ergonomic. Specifically, it simplifies the init function dance some.
lib.rs
:
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.