Skip to main content

native

Attribute Macro native 

Source
#[native]
Expand description

Declares a function as a native callback and generates internal support code.

A valid native callback must be a free function that is not async, not unsafe, not extern, has no generic parameters, the first argument takes a &IPluginContext, any remaining arguments are convertible to [cell_t] using [TryIntoPlugin] (possibly wrapped in an [Option]), and returns a type that satisfies the [NativeResult] trait.

When the native is invoked by SourceMod the input arguments will be checked to ensure all required arguments have been passed and are of the correct type, and panics or error results will automatically be converted into a SourceMod native error using [safe_native_invoke].

§Example

use sm_ext::{native, IPluginContext};

#[native]
fn simple_add_native(_ctx: &IPluginContext, a: i32, b: i32) -> i32 {
    a + b
}