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
//! 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_";
/// Prefix applied to the accessor that returns the native's Pawn declaration.
pub const INC_PREFIX: &str = "__samp_inc_";
/// Prefix of the hidden function carrying a native's documentation, as written
/// in its Rust doc comment. Feeds `{{DOC:Name}}` in an include template.
pub const DOC_PREFIX: &str = "__samp_doc_";
/// Prefix applied to the handler wrapper generated by `#[event]`.
pub const EVENT_PREFIX: &str = "__samp_event_";
/// Prefix applied to the event registration block consumed by `initialize_plugin!`.
pub const EVENT_REG_PREFIX: &str = "__samp_event_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 handler wrapper that observes a Pawn callback
/// (`OnPlayerConnect`, `OnPlayerSpawn`, …). Parses the callback arguments into
/// the Rust types declared in the signature and invokes the marked method when
/// the callback runs in the gamemode's AMX. Register the handlers via
/// `initialize_plugin!(events: [...])`.
/// 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"); }
/// }
/// ```