OPERATOR¶
Arrow operator
->
call by token:
ob->fun (mixed arg, ...)
call by string:
ob->"fun" (mixed arg, ...)
call by (string) expression/variable:
ob->(fun) (mixed arg, ...)
DESCRIPTION¶
The arrow operator (->) is equivalent to call_other(E). This syntax document discusses how the arrow operator relates to the efun version and gives basic examples; you should see call_other(E) for thorough documentation.
->ob->fun (mixed arg, ...)ob->"fun" (mixed arg, ...)ob->(fun) (mixed arg, ...)ob->fun(args) and ob->"fun"(args) are equivalent to call_other(ob, "fun", args). ob->(fun)(args) is equivalent to call_other(ob, fun, args) where fun is a runtime expression returning the function name.
USAGE¶
This section explores many ways to call QueryProp() in a player object with a single argument, P_SHORT. First let’s do some setup:
string str, fun;
fun = "QueryProp";
Now we’ll use these variables with the basic call_other(E):
str = (string)call_other(this_player(), "QueryProp", P_SHORT);
str = (string)call_other(this_player(), fun, P_SHORT);
And here are three equivalent calls using the arrow syntax form (with the variables from above):
str = (string)this_player()->QueryProp(P_SHORT);
str = (string)this_player()->"QueryProp"(P_SHORT);
str = (string)this_player()->(fun)(P_SHORT);
You can also use the arrow form to call a function on each object in an array, so the following statement calls QueryProp in all interactive users and stores the result in an array of strings:
string *s;
s = (string *)users()->QueryProp(P_SHORT);
HISTORY¶
- changed (3.2.8) –
- the forms
x->"y"()andx->(y)()are now recognized; - the form
x->y()no longer clashes with a local variable also called “y”; - a simul_efun
call_other()also catches->()calls.
- the forms
- changed (3.5.0) – split documentation for the arrow
->syntax from documentation forcall_other(E)