Skip to main content

init

Attribute Macro init 

Source
#[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().