blob: 4cfadddb287bb47feaea63dac800bc59d431ea3e [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstrad59c3892019-11-28 20:53:39 +01002 unknown call_other(object ob, string fun, mixed arg, ...)
3 unknown call_other(object *ob, string fun, mixed arg, ...)
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005 ob->fun (mixed arg, ...)
6 ob->"fun" (mixed arg, ...)
7 ob->(fun) (mixed arg, ...)
MG Mud User88f12472016-06-24 23:31:02 +02008
Zesstra715ec202025-07-09 22:18:31 +02009DESCRIPTION
10 Call a member function <fun> in another object <ob> with an
11 the argument(s) <arg...>. Result is the value returned from
12 the called function (or 0 for non-existing or void functions).
MG Mud User88f12472016-06-24 23:31:02 +020013
Zesstra715ec202025-07-09 22:18:31 +020014 Additionally the efun accepts an array of objects as <ob>: the
15 function is called with the same arguments in all the given objects.
16 The single results are collected in an array and yield the final
17 result. Array elements can be objects or the names of existing
18 objects; destructed objects and 0s will yield a '0' as result, but
19 don't cause an error.
MG Mud User88f12472016-06-24 23:31:02 +020020
Zesstra715ec202025-07-09 22:18:31 +020021 The object(s) can be given directly or via a string (i.e. its
22 object_name). If it is given by a string and the object does not
23 exist yet, it will be loaded.
MG Mud User88f12472016-06-24 23:31:02 +020024
Zesstra715ec202025-07-09 22:18:31 +020025 ob->fun(args) and "ob_name"->fun(args) is equivalent to
26 call_other(ob, "fun", args). Nowadays the ob_name string can
27 also be a variable.
MG Mud User88f12472016-06-24 23:31:02 +020028
Zesstra715ec202025-07-09 22:18:31 +020029 ob->fun(args) and ob->"fun"(args) are equivalent to
30 call_other(ob, "fun", args). ob->(fun)(args) are equivalent
31 to call_other(ob, fun, args) where fun is a runtime expression
32 returning the function name.
MG Mud User88f12472016-06-24 23:31:02 +020033
Zesstra715ec202025-07-09 22:18:31 +020034 If ob::fun does not define a publicly accessible function, the
35 efun will call the H_DEFAULT_METHOD hook if set. If the hook
36 is not set or can't resolve the call either, call_other()
37 will return 0, which is indistinguishable from a function returning 0.
MG Mud User88f12472016-06-24 23:31:02 +020038
Zesstra715ec202025-07-09 22:18:31 +020039 Calls to the master object never use the H_DEFAULT_METHOD hook.
40 To force non-default calls, the efun call_direct() can be used.
MG Mud User88f12472016-06-24 23:31:02 +020041
Zesstra715ec202025-07-09 22:18:31 +020042 "publicly accessible" means "public" when calling other objects,
43 and "public" or "static" when calling this_object(). "private"
44 and "protected" function can never be called with call_other().
MG Mud User88f12472016-06-24 23:31:02 +020045
Zesstra715ec202025-07-09 22:18:31 +020046 The return type of call_other() is 'any' by default. However,
47 if your LPC code uses #pragma strict_types, the return type is
48 'unknown', and the result of call_other() must be casted to
49 the appropriate type before you can use it for anything.
MG Mud User88f12472016-06-24 23:31:02 +020050
Zesstra715ec202025-07-09 22:18:31 +020051EXAMPLES
52 // All the following statements call the lfun QueryProp()
53 // in the current player with the argument P_SHORT.
54 string str, fun;
MG Mud User88f12472016-06-24 23:31:02 +020055
Zesstra715ec202025-07-09 22:18:31 +020056 str = (string)call_other(this_player(), "QueryProp", P_SHORT);
57 fun = "QueryProp";
58 str = (string)call_other(this_player(), fun, P_SHORT);
MG Mud User88f12472016-06-24 23:31:02 +020059
Zesstra715ec202025-07-09 22:18:31 +020060 str = (string)this_player()->QueryProp(P_SHORT);
61 str = (string)this_player()->"QueryProp"(P_SHORT);
62 fun = "QueryProp";
63 str = (string)this_player()->(fun)(P_SHORT);
MG Mud User88f12472016-06-24 23:31:02 +020064
Zesstra715ec202025-07-09 22:18:31 +020065 You have to do explicit type casting because of the unknown
66 return type, if you have set #pragma strict_types.
MG Mud User88f12472016-06-24 23:31:02 +020067
Zesstra715ec202025-07-09 22:18:31 +020068 // This statement calls the lfun short() in all interactive users
69 // and stores the collected results in a variable.
70 string *s;
MG Mud User88f12472016-06-24 23:31:02 +020071
Zesstra715ec202025-07-09 22:18:31 +020072 s = (string *)users()->short();
73
74 !Compat: call_other("/users/luser/thing", "???", 0);
75 Compat: call_other("users/luser/thing", "???", 0);
76
77 This looks a bit weird but it was used very often to just load
78 the object by calling a not existing function like "???".
79 Fortunately nowadays there is an efun load_object() for this
80 purpose.
81
82HISTORY
83 In LDMud 3.2.8 the following improvements were made:
84 - the forms x->"y"() and x->(y)() are recognized;
85 - the form x->y() no longer clashes with a local variable also
86 called "y";
87 - a simul_efun call_other() also catches ->() calls.
88 - call_other can be applied on arrays of objects.
89 LDMud 3.2.10 made the call on arrays of objects configurable.
90 LDMud 3.3.113 introduced the H_DEFAULT_METHOD hook.
91 LDMud 3.5.0 made the call on arrays of objects non-optional.
92
93SEE ALSO
94 call_direct(E), call_strict(E), call_direct_strict(E),
95 call_resolved(E), call_direct_resolved(E), create(A), pragma(LPC),
96 extern_call(E), function_exists(E), functions(LPC), map_objects(E)