MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 2 | unknown call_direct(object ob, string fun, mixed arg, ...) |
| 3 | unknown call_direct(object *ob, string fun, mixed arg, ...) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 4 | |
| 5 | DESCRIPTION |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 6 | Call a member function <fun> in another object <ob> with |
| 7 | argument(s) <arg...>. Result is the value returned from |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 8 | 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 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 13 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 18 | don't cause an error. |
| 19 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 20 | 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 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 46 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 47 | EXAMPLES |
| 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. |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 61 | string *s; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 62 | |
| 63 | s = (string *)call_direct(users(), "short"); |
| 64 | |
| 65 | |
| 66 | HISTORY |
| 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. |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 69 | LDMud 3.5.0 made the call on arrays of objects non-optional. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 70 | |
| 71 | SEE ALSO |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 72 | 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) |