[−][src]Struct samp::prelude::Amx
A wrapper around a raw pointer to an AMX and exported functions.
Methods
impl Amx[src]
pub fn new(ptr: *mut AMX, fn_table: usize) -> Amx[src]
Create an AMX wrapper.
Arguments
ptr is a raw pointer passed by callbacks (AmxLoad for example).
fn_table is a address to the exported function from AMX.
Example
use samp_sdk::amx::Amx; use samp_sdk::consts::ServerData; use samp_sdk::raw::types::AMX; static mut AMX_EXPORTS: usize = 0; #[no_mangle] pub extern "system" fn Load(server_data: *const usize) -> i32 { unsafe { AMX_EXPORTS = server_data.offset(ServerData::AmxExports.into()).read(); } return 1; } #[no_mangle] pub extern "system" fn AmxLoad(amx_ptr: *mut AMX) { let _amx = Amx::new(amx_ptr, unsafe { AMX_EXPORTS }); }
pub fn register(&self, natives: &[AMX_NATIVE_INFO]) -> Result<(), AmxError>[src]
Register a list of plugin natives functions.
Example
use samp_sdk::amx::Amx; use samp_sdk::raw::types::{AMX, AMX_NATIVE_INFO}; use std::ffi::CString; #[no_mangle] pub extern "system" fn AmxLoad(amx_ptr: *mut AMX) { // let amx_exports = ...; // see `Amx::new()` example. let amx = Amx::new(amx_ptr, amx_exports); let native_name = CString::new("MyNativeName").unwrap(); // that's safe, because there is no zero chars. let natives = vec![AMX_NATIVE_INFO { name: native_name.as_ptr(), func: my_native, }]; let _ = amx.register(&natives); } extern "C" fn my_native(amx: *mut AMX, args: *mut i32) -> i32 { println!("YOYW!"); return 0; }
pub fn exec(&self, index: AmxExecIdx) -> Result<i32, AmxError>[src]
Execs an AMX function.
Examples
use samp_sdk::amx::Amx; fn log_player_money(amx: &Amx) { let index = amx.find_public("AntiCheat_GetPlayerMoney").unwrap(); amx.push(1); // a player with ID 1 match amx.exec(index) { Ok(money) => println!("Player {} has {} money.", 1, money), Err(err) => println!("Error: {:?}", err), } }
pub fn find_native(&self, name: &str) -> Result<i32, AmxError>[src]
pub fn find_public(&self, name: &str) -> Result<AmxExecIdx, AmxError>[src]
Returns an index of a public by its name.
Examples
use samp_sdk::amx::Amx; use samp_sdk::error::AmxResult; fn has_on_player_connect(amx: &Amx) -> AmxResult<bool> { let public_index = amx.find_public("OnPlayerConnect")?; Ok(i32::from(public_index) >= 0) }
pub fn find_pubvar<T>(&self, name: &str) -> Result<Ref<T>, AmxError> where
T: AmxPrimitive, [src]
T: AmxPrimitive,
Returns a pointer to a public variable.
Example
use samp_sdk::amx::Amx; // let amx = Amx::new(...); let version = amx.find_pubvar::<f32>("my_plugin_version")?; if *version < 1.0 { println!("You're badass"); } else { println!("Alright!"); }
pub fn flags(&self) -> Result<AmxFlags, AmxError>[src]
Return flags of a compiled AMX.
pub fn get_ref<T>(&self, address: i32) -> Result<Ref<T>, AmxError> where
T: AmxPrimitive, [src]
T: AmxPrimitive,
Get a reference (Ref<T>) to a value stored inside an AMX.
Example
use samp_sdk::amx::Amx; // fn test_native(&self, amx: &Amx, reference: Ref<f32>) -> AmxResult<f32> fn test_native(&self, amx: &Amx, cell_idx: i32) -> AmxResult<f32> { let reference = amx.get_ref::<f32>(cell_idx)?; return Ok(*reference) }
pub fn push<'a, T>(&'a self, value: T) -> Result<(), AmxError> where
T: AmxCell<'a>, [src]
T: AmxCell<'a>,
Push a value that implements AmxCell to an AMX stack.
pub fn allocator(&self) -> Allocator[src]
Get a heap Allocator for current Amx.
Example
use samp_sdk::amx::Amx; let allocator = amx.allocator(); let string = allocator.allot_string("Hello!")?; let player_id = 10; amx.push(string)?; amx.push(player_id)?; amx.exec(AmxExecIdx::UserDef(21))?;
pub fn amx(&self) -> NonNull<AMX>[src]
Returns a pointer to a raw AMX structure.
pub fn header(&self) -> NonNull<AMX_HEADER>[src]
Returns a pointer to an AMX_HEADER.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> From for T[src]
impl<T, U> TryFrom for T where
T: From<U>, [src]
T: From<U>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId[src]
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,