macro_rules! exec_public {
($amx:expr, $pubname:expr) => { ... };
(@ $amx:expr, $al:ident, $arg:expr) => { ... };
(@ $amx:expr, $al:ident, $arg:expr, $($tail:tt)+) => { ... };
(@ $amx:expr, $al:ident, $arg:expr => string) => { ... };
(@ $amx:expr, $al:ident, $arg:expr => string, $($tail:tt)+) => { ... };
(@ $amx:expr, $al:ident, $arg:expr => array) => { ... };
(@ $amx:expr, $al:ident, $arg:expr => array, $($tail:tt)+) => { ... };
($amx:expr, $pubname:expr, $($args:tt)+) => { ... };
}Expand description
Executes an AMX public function by name.
Resolves the function index via amx_FindPublic and pushes the arguments
before invoking amx_Exec. Types implementing AmxCell are passed directly.
Rust strings and slices use alternative syntax (expr => string / => array):
the macro allocates memory on the AMX heap, copies the content, and releases
everything when the Allocator goes out of scope.
ยงExamples
Without arguments:
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)
}With Rust strings and slices (automatic allocation on the AMX heap):
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)
}