-
Notifications
You must be signed in to change notification settings - Fork 11
Arrays
Eva edited this page Mar 14, 2018
·
1 revision
For example, we have next native:
native SetNulls(array[], size = sizeof(array));
To use this array we should do next things:
define_native!(set_nulls, array_ptr: ref Cell, size: usize);
fn set_nulls(&self, amx: &AMX, array_ptr: &mut Cell, size: usize) {
let array: &mut [u32] = get_array!(amx, array_ptr, size);
for i in 0..array.len() {
array[i] = 0;
}
}
We have a public public GimmeArray(array[], size)
to pass an array in the public you should do this:
fn some_function(&self, amx: &mut AMX) {
let data = vec![0, 1, 2, 3, 4, 5];
// use the raw function
amx.push(array.len());
let addr = amx.push_array(&data);
amx.exec(index);
amx.release(addr);
// or use `exec_public` macro
exec_public!(amx, "GimmeArray"; data => array, data.len());