Struct samp_sdk::amx::AMX [] [src]

pub struct AMX { /* fields omitted */ }

AMX struct that holds raw types::AMX pointer.

Methods

impl AMX
[src]

[src]

Converts a raw types::AMX pointer.

Shouldn't used directly in your code. AMX::new() is calling from raw natives functions.

[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
}

[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)?;

[src]

Frees all memory above input address.

[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;
}

[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);

[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

[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!.

[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),
}

[src]

Returns an index of a public by its name.

Examples

let public_index = amx.find_public("OnPlayerConnect").unwrap();

[src]

Returns an index of a native by its name.

Examples

See find_public and exec examples.

[src]

Returns a pointer to a public variable.

[src]

Gets length of a 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)
}

[src]

Raises an AMX error.

Trait Implementations

Auto Trait Implementations

impl !Send for AMX

impl !Sync for AMX