1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/// 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:
/// ```rust,no_run
/// use samp_sdk::exec_public;
/// # use samp_sdk::amx::Amx;
/// # let amx_owned = Amx::new(std::ptr::null_mut(), 0);
/// # let amx = &amx_owned;
/// exec_public!(amx, "SomePublicFunction");
/// ```
///
/// With arguments that implement `AmxCell`:
/// ```rust,no_run
/// use samp_sdk::exec_public;
/// # use samp_sdk::amx::Amx;
/// # use samp_sdk::cell::{AmxString, UnsizedBuffer, Ref};
/// # use samp_sdk::error::AmxResult;
/// // 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):
/// ```rust,no_run
/// use samp_sdk::exec_public;
/// # use samp_sdk::amx::Amx;
/// # use samp_sdk::cell::{AmxString, UnsizedBuffer, Ref};
/// # use samp_sdk::error::AmxResult;
/// // 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)
/// }
/// ```