Amx Functions

From SA-MP Wiki

Jump to: navigation, search
Image:32px-Circle-style-warning.png

Important
Note

This article isnt finished! You can contribute to it by copy/pasting the following functions from the PAWN implementers guide (Section: "The abstract machine" -> "Function Reference"): amx_Register, amx_GetAddr, amx_StrLen, amx_GetString, amx_StrParam, amx_SetString, amx_PushString, amx_PushArray, amx_Push, amx_Exec, and amx_Release!



Contents

Amx Functions

amx_Allot

Reserve heap space in the abstract machine

Parameters:
(AMX *amx, int cells, cell *amx_addr, cell **phys_addr)
amxThe abstract machine.
cellsThe number of cells to reserve.
amx_addrThe address of the allocated cell as the pawn program (that runs in the abstract machine) can access it.
phys_addrThe address of the cell for C/C++ programs to access..


Return Values:

An error code or AMX_ERR_NONE


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:
([cell] c)
cThe value to cast from “cell” type to “float”.


Return Values:

The same bit pattern, but now as a floating point type


amx_Exec

Run code

Parameters:
(AMX *amx, long *retval, int index)
amxThe abstract machine from which to call a function.
retvalWill hold the return value of the called function upon

return. This parameter may be NULL if you are not

interested in the return value.
indexAn 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:

An error code or AMX_ERR_NONE


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


Parameters:
(AMX *amx, char *funcname, int *index)
amxThe abstract machine from which to call a function.
funcnameThe name of the public function to find.
indexUpon return, this parameter holds the index of the requested public function.


Return Values:

An error code or AMX_ERR_NONE


amx_ftoc

Cast “float” to “cell”

Parameters:
([float] f)
fThe value to cast from “float” type to “cell”.


Return Values:

The same bit pattern, but now as a “cell” type


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.

Personal tools
Navigation
Toolbox