-
Notifications
You must be signed in to change notification settings - Fork 19
Variant natives
native Variant:var_new(AnyTag:value, TagTag:tag_id=tagof(value));
native Variant:var_new_arr(const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native Variant:var_new_arr_2d(const AnyTag:value[][], size=sizeof(value), size2=sizeof(value[]), TagTag:tag_id=tagof(value));
native Variant:var_new_arr_3d(const AnyTag:value[][][], size=sizeof(value), size2=sizeof(value[]), size3=sizeof(value[][]), TagTag:tag_id=tagof(value));
native Variant:var_new_str(const value[]);
native Variant:var_new_str_s(ConstStringTag:value);
native Variant:var_new_var(ConstVariantTag:value);
Creates a new variant from a value. Options are: a single value, an array, a string, or another variant to clone.
native Variant:var_new_buf(size, TagTag:tag_id=0);
Creates a new array variant.
native AmxVariant:var_addr(VariantTag:var, amx_buffer_options:options=amx_buffer_default);
native ConstAmxVariant:var_addr_const(ConstVariantTag:var, amx_buffer_options:options=amx_buffer_default);
This function is called by every assignment to an AmxVariant
or ConstAmxVariant
variable. It obtains the address of the variant object, relative to the data section of the AMX machine. This makes it rejected by the amx_GetAddr
API function, and handled by the PawnPlus hook instead, which retrieves the inner data. This function is intended to be called right before a call to a native function expecting a string or array, through the tag conversion. It is unsafe to store the resulting address past the call, so its only use is directly as an argument to a native function.
From v1.4.2 onwards, the address returned by this function is identical to var_buf_addr
for array variants.
native AmxVariantBuffer:var_buf_addr(VariantTag:str, amx_buffer_options:options=amx_buffer_default);
Like var_addr
, but the resulting address is guaranteed to point to the actual character data of the string (relative to the AMX data). Useful for SA-MP native functions that do not call amx_GetAddr
to obtain the address. Automatically called when a conversion to AmxVariantBuffer
occurs. This function cannot be used for null and single-cell variants.
native Variant:var_acquire(VariantTag:var);
Increases the reference count stored in the variant object. A variant is eligible for automatic collection only if its reference count is 0. See garbage collection and resource management.
native Variant:var_release(VariantTag:var);
Decreases the reference count stored in the variant object. See garbage collection and resource management.
native var_delete(VariantTag:var);
Deletes a variant, freeing its memory. Not needed if you use var_acquire
and var_release
correctly.
native bool:var_valid(ConstVariantTag:var);
Checks if the variant hasn't been deleted.
native Variant:var_clone(ConstVariantTag:var);
Clones a variant and all the data it contains (deep copy). To create a shallow copy, use var_new_var
.
native var_get(ConstVariantTag:var, offset=0);
native var_get_arr(ConstVariantTag:var, AnyTag:value[], size=sizeof(value));
native var_get_str(ConstVariantTag:var, value[], size=sizeof(value)) = var_get_arr;
native String:var_get_str_s(ConstVariantTag:var);
native bool:var_get_safe(ConstVariantTag:var, &AnyTag:value, offset=0, TagTag:tag_id=tagof(value));
native var_get_arr_safe(ConstVariantTag:var, AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native var_get_str_safe(ConstVariantTag:var, value[], size=sizeof(value));
native String:var_get_str_safe_s(ConstVariantTag:var);
native var_get_md(ConstVariantTag:var, const offsets[], offsets_size=sizeof(offsets));
native var_get_md_arr(ConstVariantTag:var, const offsets[], AnyTag:value[], size=sizeof(value), offsets_size=sizeof(offsets));
native var_get_md_str(ConstVariantTag:var, const offsets[], value[], size=sizeof(value), offsets_size=sizeof(offsets)) = var_get_md_arr;
native String:var_get_md_str_s(ConstVariantTag:var, const offsets[], offsets_size=sizeof(offsets));
native bool:var_get_md_safe(ConstVariantTag:var, const offsets[], &AnyTag:value, offsets_size=sizeof(offsets), TagTag:tag_id=tagof(value));
native var_get_md_arr_safe(ConstVariantTag:var, const offsets[], AnyTag:value[], size=sizeof(value), offsets_size=sizeof(offsets), TagTag:tag_id=tagof(value));
native var_get_md_str_safe(ConstVariantTag:var, const offsets[], value[], size=sizeof(value), offsets_size=sizeof(offsets));
native String:var_get_md_str_safe_s(ConstVariantTag:var, const offsets[], offsets_size=sizeof(offsets));
Obtains the value stored in the variant, either as a single cell (specifying the array offset, if the variant contains an array), or an array. The _safe
versions check the tag of the output variable, failing if it is not compatible. var_get_arr
(_safe
) returns the number of elements.
native var_set_cell(VariantTag:var, offset, AnyTag:value);
native bool:var_set_cell_safe(VariantTag:var, offset, AnyTag:value, TagTag:tag_id=tagof(value));
native var_set_cells(VariantTag:var, offset, AnyTag:values[], size=sizeof(values));
native var_set_cells_safe(VariantTag:var, offset, AnyTag:values[], size=sizeof(values), TagTag:tag_id=tagof(values));
native var_set_cell_md(VariantTag:var, const offsets[], AnyTag:value, offsets_size=sizeof(offsets));
native bool:var_set_cell_md_safe(VariantTag:var, const offsets[], AnyTag:value, offsets_size=sizeof(offsets), TagTag:tag_id=tagof(value));
native var_set_cells_md(VariantTag:var, const offsets[], AnyTag:values[], offsets_size=sizeof(offsets), size=sizeof(values));
native var_set_cells_md_safe(VariantTag:var, const offsets[], AnyTag:values[], offsets_size=sizeof(offsets), size=sizeof(values), TagTag:tag_id=tagof(values));
Sets a cell or a range of cells in an array variant.
native var_tagof(ConstVariantTag:var);
Returns the tag id of the value stored in the variant.
native tag_uid:var_tag_uid(ConstVariantTag:var);
Returns the tag uid of the value stored in the variant.
native var_sizeof(ConstVariantTag:var);
native var_sizeof_md(ConstVariantTag:var, const offsets[], offsets_size=sizeof(offsets));
Returns the size of the variant in cells (1 for a cell variant).
native var_rank(ConstVariantTag:var);
Returns the rank of a variable, i.e. its dimension. Returns 0 for a cell variant, 1 for a single-dimensional array, 2 for a 2D array, 3 for a 3D array etc. Returns -1 for VAR_NULL
.
native Variant:var_add(ConstVariantTag:var1, ConstVariantTag:var2);
native Variant:var_sub(ConstVariantTag:var1, ConstVariantTag:var2);
native Variant:var_mul(ConstVariantTag:var1, ConstVariantTag:var2);
native Variant:var_div(ConstVariantTag:var1, ConstVariantTag:var2);
native Variant:var_mod(ConstVariantTag:var1, ConstVariantTag:var2);
native Variant:var_neg(ConstVariantTag:var);
native Variant:var_inc(ConstVariantTag:var);
native Variant:var_dec(ConstVariantTag:var);
native bool:var_eq(ConstVariantTag:var1, ConstVariantTag:var2);
native bool:var_neq(ConstVariantTag:var1, ConstVariantTag:var2);
native bool:var_lt(ConstVariantTag:var1, ConstVariantTag:var2);
native bool:var_gt(ConstVariantTag:var1, ConstVariantTag:var2);
native bool:var_lte(ConstVariantTag:var1, ConstVariantTag:var2);
native bool:var_gte(ConstVariantTag:var1, ConstVariantTag:var2);
native bool:var_not(ConstVariantTag:var);
Performs a binary or unary operation on the variant values based on their tags. Overloaded operators are usable as well.
native Variant:var_call_op(VariantTag:var, tag_op:tag_op, AnyTag:...);
Calls an operation on a variant according to its tag. Returns a new variant with the same tag.
native Variant:var_call_op_raw(VariantTag:var, tag_op:tag_op, AnyTag:...);
Like var_call_op
, but the tag of the variant is removed after the operation.
native Iter:var_iter(VariantTag:value, count=1);
Creates an iterator that points to a variant. The iterator can be used to modify the cells in the variant. Count can be used to specify the number of copies of the element in the iterator.