Struct samp_sdk::amx::AMX
[−]
[src]
pub struct AMX { /* fields omitted */ }AMX struct that holds raw types::AMX pointer.
Methods
impl AMX[src]
pub fn new(amx: *mut AMX) -> AMX[src]
Converts a raw types::AMX pointer.
Shouldn't used directly in your code. AMX::new() is calling from raw natives functions.
pub fn register(&self, natives: &Vec<AMX_NATIVE_INFO>) -> AmxResult<()>[src]
Registers natives functions
Examples
fn amx_load(amx: AMX) -> Cell { let natives = natives!{ "SomeFunction" => some_function, "AnotherFunction" => another_function }; amx.register(&natives).unwrap(); AMX_ERR_NONE }
pub fn allot(&self, cells: usize) -> AmxResult<(Cell, usize)>[src]
Allocates memory cells inside AMX.
Return
Return typle of two addresses:
- The address of the variable relatived to AMX data section.
- The physical address.
Examples
Allot one cell to a reference to a value and push it.
let (amx_addr, phys_addr) = amx.allot(1)?; let value: &mut i32 = phys_addr as &mut i32; *value = 655; amx.push(amx_addr)?;
pub fn release(&self, address: Cell) -> AmxResult<()>[src]
Frees all memory above input address.
pub fn get_address<'a, T: Sized>(&self, address: Cell) -> AmxResult<&'a mut T>[src]
Get an address of a reference value given to native.
Examples
// native: SomeNative(&int_value); fn some_native(amx: &AMX, args: *mut Cell) -> Cell { let ptr = std::ptr::read(args.offset(1)); let int_value: &mut i32 = amx.get_address(ptr).unwrap(); *int_value = 10; }
pub fn push<T: Sized>(&self, value: T) -> AmxResult<()>[src]
Pushes a primitive value or an address to AMX stack.
Examples
let index = amx.find_public("OnPlayerHPChanged").unwrap(); let player_id: u32 = 12; let health: f32 = 100.0; amx.push(health); amx.push(player_id); amx.exec(index);
pub fn push_array<T: Sized>(&self, array: &[T]) -> AmxResult<Cell>[src]
Pushes a slice to the AMX stack.
Examples
let func = amx.find_public("GiveMeArray")?; let player_data = vec![1, 2, 3, 4, 5]; let player_ids = vec![1, 2, 3, 4, 5]; let amx_addr = amx.push_array(&player_data)?; // push an array and save address relatived to first item on the heap. amx.push_array(&player_ids)?; // push the next array amx.exec(func)?; // exec the public amx.release(amx_addr)?; // release all allocated memory inside AMX
pub fn push_string(&self, string: &str, packed: bool) -> AmxResult<Cell>[src]
Allots memory for a string and pushes it to the AMX stack.
Please, don't use it directly! Better use macros exec!, exec_public! and exec_native!.
pub fn exec(&self, index: i32) -> AmxResult<i64>[src]
Execs an AMX function.
Examples
let index = amx.find_native("GetPlayerMoney").unwrap(); amx.push(1); // a player with ID 1 match amx.exec(index) { Ok(money) => log!("Player has {} money.", money), Err(err) => log!("Error: {:?}", err), }
pub fn find_public(&self, name: &str) -> AmxResult<i32>[src]
Returns an index of a public by its name.
Examples
let public_index = amx.find_public("OnPlayerConnect").unwrap();
pub fn find_native(&self, name: &str) -> AmxResult<i32>[src]
pub fn find_pubvar<T: Sized>(&self, name: &str) -> AmxResult<&mut T>[src]
Returns a pointer to a public variable.
pub fn string_len(&self, address: *const Cell) -> AmxResult<usize>[src]
Gets length of a string.
pub fn get_string(&self, address: *const Cell, size: usize) -> AmxResult<String>[src]
Gets a string from AMX.
Examples
fn raw_function(&self, amx: &AMX, params: *mut types::Cell) -> AmxResult<Cell> { unsafe { let ptr = std::ptr::read(params.offset(1)); let mut addr = amx.get_address::<i32>(ptr)?; // get a pointer from amx let len = amx.string_len(addr.as_mut())?; // get string length in amx let string = amx.get_string(addr.as_mut(), len + 1)?; // convert amx string to rust String log!("got string: {}", string); std::mem::forget(addr); } Ok(0) }
pub fn raise_error(&self, error: AmxError) -> AmxResult<()>[src]
Raises an AMX error.