Amx Functions
From SA-MP Wiki
Contents |
Amx Functions
amx_Allot
Reserve heap space in the abstract machine
Parameters:amx | The abstract machine. |
cells | The number of cells to reserve. |
amx_addr | The address of the allocated cell as the pawn program (that runs in the abstract machine) can access it. |
phys_addr | The address of the cell for C/C++ programs to access.. |
Return Values:
Note:
In earlier releases of pawn, arrays and strings had to be passed to a script after explicitly allocating memory for it on the amx stack. In the current release, this functionality has been largely replaced by the functions amx_PushArray and amx_PushString. A pawn function can only access memory inside its abstract ma- chine. If a parameter is to be passed “by reference” to a pawn function, one must pass the address of that parameter to amx_Exec. In addition, that address itself must be within the address range of the abstract machine too. An added complexity is that the abstract machine uses addresses that are relative to the data section of the abstract machine, and the host program uses address relative to the environment that the operating system gives it. amx_Allot allocates memory cells inside the abstract machine and it returns two addresses. The amx_addr parameter is the address of the variable relative to the “data section” of the abstract machine; this is the value you should pass to amx_Exec (via amx_Push). Pa- rameter phys_addr holds the address relative to the host program’s address space. So a C/C++ program can use this address and write into the allocated memory. After amx_Exec returns, you may inspect the memory block (the pawn function called by amx_Exec may have written into it) and finally release it by calling amx_Release.
amx_ctof
Cast “cell” to “float”
Parameters:c | The value to cast from “cell” type to “float”. |
Return Values:
amx_Exec
Run code
Parameters:amx | The abstract machine from which to call a function. |
retval | Will hold the return value of the called function upon
return. This parameter may be NULL if you are not interested in the return value. |
index | An index into the “public function table”; it indicates
the function to execute. See amx_FindPublic formore information. Use AMX_EXEC_MAIN to start executing at the main function, and AMX_EXEC_CONT to continue execution from a “sleep state”. |
Return Values:
Note:
This function runs the script, starting at the indicated function. It calls the callback function for any native function call that the code in the amx makes. amx_Exec assumes that all native functions are correctly initialized with amx_Register.
amx_FindPublic
Return the index of a public function
amx | The abstract machine from which to call a function. |
funcname | The name of the public function to find. |
index | Upon return, this parameter holds the index of the requested public function. |
Return Values:
amx_ftoc
Cast “float” to “cell”
Parameters:f | The value to cast from “float” type to “cell”. |
Return Values:
Note:
This macro casts a “float” type into a “cell” type without changing the bit pattern. A normal type cast in C/C++ changes the memory representation of the expression so that its numeric value in integer format is the integral (truncated) value of the original rational value. The pawn parser and abstract machine store floating point values in a cell —when storing a floating point value in a cell, the bit pattern must not be changed.