[−][src]Macro samp::exec_public
Execute a public AMX function by name.
Notes
Function input arguments should implement AmxCell except Rust strings and slices.
To pass a Rust string there is the next syntax - variable_name => string, for array variable_name => array.
In this case inside the macro memory will be allocated for them and auto-released when the public will be executed.
Examples
Simple execution.
use samp_sdk::exec_public; exec_public!(amx, "SomePublicFunction");
With arguments that implement AmxCell.
use samp_sdk::exec_public; // native:CallPublic(const publicname[], const string[], buffer[], length, &someref); fn call_public(amx: &Amx, pub_name: AmxString, string: AmxString, buffer: UnsizedBuffer, size: usize, reference: Ref<usize>) -> AmxResult<bool> { let buffer = buffer.into_sized_buffer(size); let public_name = pub_name.to_string(); exec_public!(amx, &public_name, string, buffer, reference); Ok(true) }
And with Rust strings and slices.
use samp_sdk::exec_public; // native:CallPublic(const publicname[], const string[]); fn call_public(amx: &Amx, pub_name: AmxString, string: AmxString) -> AmxResult<bool> { let public_name = pub_name.to_string(); let rust_string = "hello!"; let owned_string = "another hello!".to_string(); let rust_array = vec![1, 2, 3, 4, 5]; exec_public!(amx, &public_name, string, rust_string => string, &owned_string => string, &rust_array => array); Ok(true) }