#[init]Expand description
Designate an initialization function to run when this library is loaded via Wolfram LibraryLink.
#[init] can be applied to at most one function in a library.
The function annotated with #[init] will automatically call initialize().
LibraryLink libraries are not required to define an initialization function.
§Panics
Any panics thrown during the executation of #[init] will automatically be caught,
and an error code will be returned to the Wolfram Kernel.
If the initialization function panics, the Wolfram Kernel will prevent other LibraryLink functions exported from that library from being loaded.
§Example
Define an initialization function:
use wolfram_library_link as wll;
#[wll::init]
fn init_my_library() {
println!("library is now initialized");
}§Behavior
If a library exports a function called WolframLibrary_initialize(), that
function will automatically be called by the Wolfram Kernel when the library is
loaded.
#[init] works by generating a definition for WolframLibrary_initialize().
Designate an initialization function to run once, when this library is
loaded via Wolfram LibraryLink — distinct from [export], which wraps a
function called on every invocation from Wolfram.
The annotated function must take no arguments and return (). #[init]
can be applied to at most one function in a library, and a library isn’t
required to define one at all.
Behind the scenes, the macro generates a WolframLibrary_initialize() C
symbol — the well-known entry point the Wolfram Kernel calls
automatically when the library is loaded, before any exported function
runs.
§Panics
Panics inside the #[init] function are caught and reported to the Kernel
as an error code. If initialization panics, the Kernel will not load any
of this library’s other exported functions.
§Example
use wolfram_export::init;
#[init]
fn init_my_library() {
println!("library is now initialized");
}