-
Notifications
You must be signed in to change notification settings - Fork 0
interop functions
These functions are located in the interop
package.
Looks for a native function exported to Pawn scripts by its name. If the function is found, it is returned as a callable Lua function. Using the native
table is prefered over this.
Passing true
as fast
switches to an alternate calling mode for the function, which does not include advanced marshalling options that requires allocation of additional structures. This disables the possibility of using strings, tables and buffers when calling the function.
This table can be used to retrieve and cache Pawn functions based on their name. When an element with a specific key is requested, getnative
is called to retrieve the native function, and it also stores the result in the table so that the lookup is quicker next time it is used. The default values for the parameters of getnative
can be changed with nativeopts
.
interop.native.SendClientMessageToAll(-1, "Hello world!)
Returns a function which, when called, calls func
passing the original arguments to vacall
unchanged, and the new arguments are copied to the AMX heap and transformed to their offsets (if primitive). The results from func
are returned, followed with the values from the heap converted back to Lua based on their original types.
This is the prefered way of calling Pawn native functions which are variadic or have reference parameters at the end.
local x, y, z = interop.vacall(interop.native.GetPlayerPos, interop.asnone, playerid)(0.0, 0.0, 0.0)
Terminates the current public function with an error representing the Pawn sleep
instruction. If value
is a function, it is called to obtain the sleep argument, or if it is a primitive value, it is used as the argument. A continuation function cont
will be registered and stored in the AMX machine. When the host tries to resume the code, the continuation will be called.
Changes the arguments the loader function for the native
table uses for native function lookup. The meaning of the arguments is the same as for getnative
.
Converts each argument in the argument list into a light userdata that mimics how arguments are marshalled when calling a native function. Only simple types are supported (numbers, booleans and light userdata), nil
is ignored in trailing position.
Return an iterator function that goes through all native functions known to the script (both cached and yet uncached) and returns the name of each function and the index of its batch (plugins usually register functions in batches, thus the same batch index can be used to group similar functions together).
The order of the returned functions is unspecified. The generic for
can be used to easily iterate the result:
for name, batch in interop.natives() do
print(name, batch)
end
Returns the number of natives that are returned from natives()
.
This table is browsed every time a public function is looked for. If a function is found in this table, it gets assigned an index which is reported back to AMX.
Creates a new buffer with size
cells. If zero
is true (it is by default), the contents are zeroed.
Converts all arguments passed to this function to buffers, and returns them. The buffers are independent, with their contents are determined based on the marshalling of values between Lua and Pawn.
Same as tobuffer
, but the buffer is read-only.
Creates a buffer pointing to range of cells inside a specific buffer. start
is 1-based; the buffer is read-only if const
is true.
Creates a single cell buffer holding all arguments, and returns spans to it specifying the range of each argument in the buffer.
A special buffer representing the heap of the AMX machine used by the package. Its size might change depending on the allocations.
Like newbuffer
, but the allocated memory is located inside the AMX heap. A span to the newly allocated section is returned.
Frees the memory after mem
in the AMX heap. mem
can be a buffer pointing to the heap, or a light userdata specifying the offset in the heap. Returns true
if successful, false
otherwise.
Like tobuffer
, but the memory is taken from the AMX heap.
Stores all arguments into the AMX heap and returns their offsets (as light userdata).
These functions expect a light userdata parameter obtained as a result of calling a native function, or as an argument to a public function.
Doesn't return any value.
Returns nil
. The number of returned values makes a difference in functions like vacall
, bind
, or map
.
The value is interpreted as a 32-bit signed integer.
The value is interpreted as a 32-bit unsigned integer.
The value is interpreted as a boolean value, returning true
for a non-zero value.
The value is interpreted as a 32-bit float.
The value is interpreted as a byte-offset into a cell array. It is divided by 4 and added to 1 to form a Lua index.
The value is interpreted as an opaque handle to a resource. nil
is returned for 0, and other values are returned unchanged.
The value is interpreted as an offset to the AMX memory. If valid, the memory block is converted to a string. nil
is returned for an invalid offset.
The value is interpreted as an offset to the AMX memory. A new buffer is created to hold the cells that correspond to a string in the memory.
Notes for GCA-compliant code
asstring
and asbuffer
use amx_GetAddr
and amx_StrLen
to find the pointer and length of the block in memory. It is possible to extend the AMX memory space by hooking the corresponding functions.
Returns a Pawn string located in the specified buffer.
Stores a Pawn string into the specified buffer.
Converts a string to an unpacked cell string and stores it in a buffer. The null character is stored as 0xFFFF00
.
Converts the arguments to their AMX tag codes. If the argument is a string, it will be used as the tag name for the tag. If it is another value, the resulting name will be "Float" for a floating-point number or "bool" for a boolean. If the argument is a table, it must contain elements with the same tag.
Converts each tag code in the arguments to its name. The result can be used for comparisons and conditional conversions.