blob: 493b16d0232b88fcdfad00a95dee17abb3e7fb62 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 unknown call_direct(object ob, string fun, mixed arg, ...)
3 unknown call_direct(object *ob, string fun, mixed arg, ...)
MG Mud User88f12472016-06-24 23:31:02 +02004
5DESCRIPTION
Zesstra715ec202025-07-09 22:18:31 +02006 Call a member function <fun> in another object <ob> with
7 argument(s) <arg...>. Result is the value returned from
MG Mud User88f12472016-06-24 23:31:02 +02008 the called function (or 0 for non-existing or void functions).
9
10 This efun is a twin to call_other(), with the difference
11 being that call_direct() never calls a default method.
12
Zesstra715ec202025-07-09 22:18:31 +020013 Additionally the efun accepts an array of objects as <ob>: the
14 function is called with the same arguments in all the given objects.
15 The single results are collected in an array and yield the final
16 result. Array elements can be objects or the names of existing
17 objects; destructed objects and 0s will yield a '0' as result, but
MG Mud User88f12472016-06-24 23:31:02 +020018 don't cause an error.
19
MG Mud User88f12472016-06-24 23:31:02 +020020 The object(s) can be given directly or via a string (i.e. its
21 object_name). If it is given by a string and the object does not
22 exist yet, it will be loaded.
23
24 ob->fun(args) and "ob_name"->fun(args) is equivalent to
25 call_other(ob, "fun", args). Nowadays the ob_name string can
26 also be a variable.
27
28 ob->fun(args) and ob->"fun"(args) are equivalent to
29 call_other(ob, "fun", args). ob->(fun)(args) are equivalent
30 to call_other(ob, fun, args) where fun is a runtime expression
31 returning the function name.
32
33 If ob::fun does not define a publicly accessible function, the
34 call_other() will return 0, which is indistinguishable from
35 a function returning 0.
36
37 "publicly accessible" means "public" when calling other objects,
38 and "public" or "static" when calling this_object(). "private"
39 and "protected" function can never be called with call_other().
40
41 The return type of call_other() is 'any' be default. However,
42 if your LPC code uses #pragma strict_types, the return type is
43 'unknown', and the result of call_other() must be casted to
44 the appropriate type before you can use it for anything.
45
Zesstra715ec202025-07-09 22:18:31 +020046
MG Mud User88f12472016-06-24 23:31:02 +020047EXAMPLES
48 // All the following statements call the lfun QueryProp()
49 // in the current player with the argument P_SHORT.
50 string str, fun;
51
52 str = (string)call_direct(this_player(), "QueryProp", P_SHORT);
53 fun = "QueryProp";
54 str = (string)call_direct(this_player(), fun, P_SHORT);
55
56 You have to do explicit type casting because of the unknown
57 return type, if you have set #pragma strict_types.
58
59 // This statement calls the lfun short() in all interactive users
60 // and stores the collected results in a variable.
Zesstra715ec202025-07-09 22:18:31 +020061 string *s;
MG Mud User88f12472016-06-24 23:31:02 +020062
63 s = (string *)call_direct(users(), "short");
64
65
66HISTORY
67 Introduced in LDMud 3.3.113 with the H_DEFAULT_METHOD hook.
68 LDMud 3.2.10 made the call on arrays of objects configurable.
Zesstra715ec202025-07-09 22:18:31 +020069 LDMud 3.5.0 made the call on arrays of objects non-optional.
MG Mud User88f12472016-06-24 23:31:02 +020070
71SEE ALSO
Zesstra715ec202025-07-09 22:18:31 +020072 call_other(E), call_strict(E), call_direct_strict(E),
73 call_resolved(E), call_direct_resolved(E), create(A), pragma(LPC),
74 extern_call(E), function_exists(E), functions(LPC), map_objects(E)