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
//! Proc macros for the `rust-samp` toolkit.
//!
//! - `#[native]` — generates the `extern "C"` FFI wrapper for a Rust function,
//! parsing arguments via [`AmxCell`] and handling the return value.
//! - `initialize_plugin!` — generates the entry points required by the server
//! (`Supports`/`Load`/`Unload`/`AmxLoad`/`AmxUnload`/`ProcessTick` on SA-MP
//! and `ComponentEntryPoint` + vtable on Open Multiplayer), as well as native registration.
//! - `#[derive(SampPlugin)]` — shortcut for an empty `impl SampPlugin for T {}`.
//!
//! This crate only compiles when loaded by `samp` via reexport — it has no
//! runtime API of its own.
//!
//! [`AmxCell`]: samp::cell::AmxCell
use TokenStream;
/// Prefix applied to the name of the `extern "C"` wrapper function generated by `#[native]`.
/// Avoids collision with any function name declared by the developer.
pub const NATIVE_PREFIX: &str = "__samp_native_";
/// Prefix applied to the name of the native registration block in `initialize_plugin!`.
pub const REG_PREFIX: &str = "__samp_reg_";
/// Generates the `extern "C"` wrapper that reads the AMX argument table, parses
/// it into the Rust types declared in the signature and invokes the marked method.
/// Generates the entry points required by the server (SA-MP + Open Multiplayer), the Rust
/// `IComponent` vtable and the registration of the plugin's native list.
/// Generates `impl SampPlugin for T {}` with all methods using the default behavior
/// (empty). Use for structs that do not need to customize any lifecycle callback —
/// write the `impl SampPlugin` manually when some method needs custom logic.
///
/// ```rust,ignore
/// use samp::prelude::*;
///
/// #[derive(SampPlugin)]
/// struct SimplePlugin { counter: u32 }
///
/// // With logic in on_load → do not use the derive
/// struct AdvancedPlugin;
/// impl SampPlugin for AdvancedPlugin {
/// fn on_load(&mut self) { println!("plugin loaded"); }
/// }
/// ```