Skip to content

Expression natives

IS4 edited this page Oct 5, 2021 · 14 revisions

Operations

expr_acquire

native Expression:expr_acquire(Expression:expr);

Increases the reference count stored inside the expression object.

expr_release

native Expression:expr_release(Expression:expr);

Decreases the reference count stored inside the expression object.

expr_delete

native expr_delete(Expression:expr);

Instantly deletes an expression, making it unreachable from code. The actual object may not be deleted however, if other expressions reference it.

expr_valid

native bool:expr_valid(Expression:expr);

Returns true if the argument is a valid reference to an expression object.

expr_type

native expr_type(Expression:expr);

Returns a number that uniquely identifies the type of the expression. The result is not guaranteed to be consistent across platforms, versions, or unique instances of the plugin.

expr_type_str

native expr_type_str(Expression:expr, type[], size=sizeof(type));
native String:expr_type_str_s(Expression:expr);

Returns a string representation of the type of the expression. The result is not guaranteed to be consistent across platforms, versions, or unique instances of the plugin.

Construction

expr_parse

native Expression:expr_parse(const string[], parser_options:options=parser_all);
native Expression:expr_parse_s(ConstStringTag:string, parser_options:options=parser_all);

Constructs a new expression from its string representation. More information about the parser here.

expr_literal

native Expression:expr_literal(const name[]);

Obtains the expression corresponding to a literal value recognized by the parser.

expr_intrinsic

native Expression:expr_intrinsic(const name[], parser_options:options=parser_all);

Creates a new expression corresponding to an intrinsic function recognized by the parser. Options can be provided which limit the capabilities of the function when called.

Attempting to obtain the value of the function results in an error.

expr_empty

native Expression:expr_empty(Expression:...);

Creates an empty expression with no value. The variable arguments allow storing any number of expressions captured by this expression, but not used in any way. The inner expressions can serve to prolong lifetime of other objects that the resulting expressions depends upon.

expr_void

native Expression:expr_void(Expression:expr);

Creates an expression with value which, when executed, also executes expr but discards any result.

expr_weak

native Expression:expr_weak(Expression:expr);

Creates a new weakly linked expression, delegating all operations to expr. expr is not protected from deletion.

expr_weak_set

native Expression:expr_weak_set(Expression:weak, Expression:target);

Sets the target of a weakly linked expression. This is a potentially dangerous operation, since doing so may change existing expressions or introduce unbounded recursion.

expr_const

native Expression:expr_const(AnyTag:value, TagTag:tag_id=tagof(value));
native Expression:expr_const_arr(const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native Expression:expr_const_str(const value[]);
native Expression:expr_const_str_s(ConstStringTag:value);
native Expression:expr_const_var(VariantTag:value);

Creates a new constant expression whose value never changes.

expr_true

native Expression:expr_true();

Creates a new boolean expression that always resolves to true.

expr_false

native Expression:expr_false();

Creates a new boolean expression that always resolves to false.

expr_handle

native Expression:expr_handle(HandleTag:handle);

Creates a new expression whose value is equal to that of handle, but the handle is referenced inside the expression and its lifetime is prolonged for the duration of the expression.

expr_arr

native Expression:expr_arr(Expression:...);

Creates a new array construction expression from its arguments. All arguments must have the same tag in order to create an array. If this expression is operated in a way that doesn't require an actual array to be produced, no array construction may happen and thus no error could be produced when incompatible values are encountered.

expr_arg

native Expression:expr_arg(index);

Creates a new argument expression for an external argument at index. Arguments are provided to the expression by its caller, depending on the context.

expr_arg_pack

native Expression:expr_arg_pack(begin, end=-1);

Creates a new argument pack expression for a range of arguments starting at begin and ending at end (inclusive). If end is unspecified, the result corresponds to the whole range of arguments starting at begin. If end is specified, all arguments must be provided. In the other case, the argument at begin must be provided or begin must be equal to the total number of provided arguments (e.g. if 3 arguments are provided, begin can be 3 but not 4 or more).

expr_bind

native Expression:expr_bind(Expression:expr, Expression:...);

Creates a bind expression which, when executed, provides its initial arguments to the inner expression.

expr_nested

native Expression:expr_nested(Expression:expr);

Creates a nested expression which limits the possible operations on expr to only obtaining its single value.

expr_env

native Expression:expr_env();

Creates a new expression which, when indexed, obtains a value in the expression environment.

expr_set_env

native Expression:expr_set_env(Expression:expr, Map:env=INVALID_MAP, bool:env_readonly=false);

Creates a new expression which changes the environment used for operations in expr. The lifetime of env is not prolonged by the expression. Setting env_readonly to true makes the environment (new or original if new is unset) non-modifiable. If env is not set and env_readonly is false, no environment will be used for the inner expression.

expr_global

native Expression:expr_global(const name[]);

Creates a new expression representing a variable in the expression environment (i.e. the environment map indexed with a string).

expr_set_amx

native Expression:expr_set_amx(Expression:expr, Amx:amx);

Creates a new expression which sets the AMX instance used in the inner expression. The instance must be valid when the expression is executed.

expr_comma

native Expression:expr_comma(Expression:left, Expression:right);

Joins two expressions together via the comma operator. When executed, both expressions are executed in order, and their results are returned (or the last result is returned if a single value is expected). If another operation is performed on the expression (like call or assignment), the behaviour depends on whether the right operand is guaranteed to return a value or not. If it is guaranteed to return no value, the operation is propagated to the left operand (producing the result) and the right operand is simply executed; in other other case, the left operand is executed and the operation is propagated to the right operand.

expr_assign

native Expression:expr_assign(Expression:left, Expression:right);

Creates a new assignment expression.

expr_try

native Expression:expr_try(Expression:main, Expression:fallback);

Creates a new try/catch expression. On execution, it invokes main, but results to fallback if the expression produces an error. The error may come from the expression itself but also from the way it is used. For example, -try[]catch[0] attempts to obtain the value of an empty expression (inside try[]) which fails, but the error comes from the inner expression, so it is caught. Another example is try[a]catch[b] = 0 which assigns to b if a cannot be assigned.

expr_symbol

native Expression:expr_symbol(Symbol:symbol);

Creates a new expression from a given debug symbol. The symbol can be both a variable or a function, but in case of a local variable, it must be located in the current stack frame. The expression is bound to the current AMX instance.

Attempting to obtain the value of a non-variable symbol results in an error.

expr_native

native Expression:expr_native(const function[]);

Creates a new expression corresponding to a native function. The function will be executed in the AMX instance provided in the execution of the expression.

Attempting to obtain the value of the function results in an error.

expr_public

native Expression:expr_public(const function[]);

Creates a new expression corresponding to a public function. The function will be executed in the AMX instance provided in the execution of the expression.

Attempting to obtain the value of the function results in an error.

expr_pubvar

native Expression:expr_pubvar(const name[]);

Creates a new expression corresponding to a public variable.

expr_call

native Expression:expr_call(Expression:func, Expression:...);

Creates a new call expression from a function expression and its arguments. The result of expr_symbol, expr_native, expr_public, and expr_intrinsic can be used as the function expression. A valid Expression: value can also be called.

expr_index

native Expression:expr_index(Expression:arr, Expression:...);

Creates a new indexing expression from an array expression and a list of indices.

expr_quote

native Expression:expr_quote(Expression:expr);

Creates a new quote expression which, upon execution, wraps its operand in an Expression: value.

expr_dequote

native Expression:expr_dequote(Expression:expr);

Creates a new dequote expression which, upon execution, accepts an Expression: value and delegates all own operations to it.

expr_extract

native Expression:expr_extract(Expression:expr);

Creates a new expression that obtains the value stored in a Variant:, Handle:, or String: reference.

expr_variant

native Expression:expr_variant(Expression:value);

Creates a new expression that produces a new Variant: instance from a value.

expr_string

native Expression:expr_string(Expression:value);

Creates a new expression that produces a new String: instance from a value.

Operators

native Expression:expr_add(Expression:left, Expression:right);
native Expression:expr_sub(Expression:left, Expression:right);
native Expression:expr_mul(Expression:left, Expression:right);
native Expression:expr_div(Expression:left, Expression:right);
native Expression:expr_mod(Expression:left, Expression:right);
native Expression:expr_bit_and(Expression:left, Expression:right);
native Expression:expr_bit_or(Expression:left, Expression:right);
native Expression:expr_bit_xor(Expression:left, Expression:right);
native Expression:expr_rs(Expression:left, Expression:right);
native Expression:expr_ls(Expression:left, Expression:right);
native Expression:expr_neg(Expression:expr);
native Expression:expr_inc(Expression:expr);
native Expression:expr_dec(Expression:expr);
native Expression:expr_bit_not(Expression:expr);

native Expression:expr_eq(Expression:left, Expression:right);
native Expression:expr_neq(Expression:left, Expression:right);
native Expression:expr_lt(Expression:left, Expression:right);
native Expression:expr_gt(Expression:left, Expression:right);
native Expression:expr_lte(Expression:left, Expression:right);
native Expression:expr_gte(Expression:left, Expression:right);
native Expression:expr_not(Expression:expr);

native Expression:expr_and(Expression:left, Expression:right);
native Expression:expr_or(Expression:left, Expression:right);

Creates a new unary or binary operation expression. The behaviour is analogous to variant operations and Pawn.

expr_cond

native Expression:expr_cond(Expression:cond, Expression:on_true, Expression:on_false);

Creates a new conditional expression. When executed, cond is invoked and its result determines which expression is used for providing the value of the expression.

expr_range

native Expression:expr_range(Expression:begin, Expression:end);

Creates a new expression which returns a range of numbers starting at begin and ending at end. The numbers must be integers and can be ascending or descending.

expr_select

native Expression:expr_select(Expression:list, Expression:func);

Creates a new select expression which executes list and processes all values returned with func (where $arg0 is the current result).

expr_where

native Expression:expr_where(Expression:list, Expression:cond);

Creates a new where expression which executes list and removes all its results that do not match cond (where $arg0 is the current result).

expr_cast

native Expression:expr_cast(Expression:expr, TagTag:tag_id);

Creates a new cast expression. The value of the result will be identical to expr, but with a new tag.

expr_tagof

native Expression:expr_tagof(Expression:expr);

Creates a new tagof expression. The result of the expression is a single cell corresponding to the tag id of the operand.

The tag can be obtained without actually executing the expression if the structure of the expression provides enough information to accurately deduce it. The resulting value should be equal to the actual tag of the value produced if the expression executes with no errors and returns a value. For example, expr_cast always provides the correct tag.

expr_sizeof

native Expression:expr_sizeof(Expression:expr, Expression:...);

Creates a new sizeof expression from a list of indices. The result of the expression is a single cell corresponding to the size of the operand.

The size can be obtained without actually executing the expression if the structure of the expression provides enough information to accurately deduce it. The resulting value should be equal to the actual size of the value produced if the expression executes with no errors and returns a value. For example, expr_arr can provide its size when the number of values the array is constructed from is known beforehand.

expr_rankof

native Expression:expr_rankof(Expression:expr);

Creates a new rankof expression. The result of the expression is a single cell corresponding to the rank (number of dimensions) of the operand.

The rank can be obtained without actually executing the expression if the structure of the expression provides enough information to accurately deduce it. The resulting value should be equal to the actual rank of the value produced if the expression executes with no errors and returns a value. For example, expr_arr always returns 1 because multidimensional arrays are not supported.

expr_addressof

native Expression:expr_addressof(Expression:expr);

Creates a new addressof expression. When executed, the value of expr is stored as a temporary value on the AMX heap and its address is returned.

expr_nameof

native Expression:expr_nameof(Expression:expr);

Creates a new nameof expression. When executed, the expression returns the string representation of expr.

expr_get

native expr_get(Expression:expr, offset=0);
native expr_get_arr(Expression:expr, AnyTag:value[], size=sizeof(value));
native expr_get_str(Expression:expr, value[], size=sizeof(value)) = expr_get_arr;
native String:expr_get_str_s(Expression:expr);
native Variant:expr_get_var(Expression:expr);
native bool:expr_get_safe(Expression:expr, &AnyTag:value, offset=0, TagTag:tag_id=tagof(value));
native expr_get_arr_safe(Expression:expr, AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native expr_get_str_safe(Expression:expr, value[], size=sizeof(value));
native String:expr_get_str_safe_s(Expression:expr);

Executes the expression and returns its value. An error may be raised if the expression is semantically incorrect.

expr_set

native expr_set(Expression:expr, AnyTag:value, TagTag:tag_id=tagof(value));
native expr_set_arr(Expression:expr, const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native expr_set_str(Expression:expr, const value[]);
native expr_set_str_s(Expression:expr, ConstStringTag:value);
native expr_set_var(Expression:expr, ConstVariantTag:value);

Executes the expression, and if the result corresponds to a storage location, sets its value. An error may be raised if the expression is semantically incorrect.

expr_func

stock Expression:expr_func({F@_@, F@_@i, F@_@ii, F@_@iii, F@_@iiii, F@_@iiiii, F@_@iiiiii, F@_@iiiiiii, F@_@iiiiiiii, F@_@iiiiiiiii}:func, tag_id=tagof(func))

If y_functional is included, creates a new expression that corresponds to the inline function/lambda func. When the expression is called, func is invoked.

Clone this wiki locally