MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | SYNOPSIS |
| 2 | unknown call_direct (object ob, string fun, mixed arg, ...) |
| 3 | unknown call_direct (object *ob, string fun, mixed arg, ...) |
| 4 | |
| 5 | DESCRIPTION |
| 6 | Call a member function <fun> in another object <ob> with an |
| 7 | the argument(s) <arg...>. Result is the value returned from |
| 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 | |
| 13 | Optionally the driver can be configured to accept an array of |
| 14 | objects as <ob>: the function is called with the same |
| 15 | arguments in all the given objects. The single results are |
| 16 | collected in an array and yield the final result. Array |
| 17 | elements can be objects or the names of existing objects; |
| 18 | destructed objects and 0s will yield a '0' as result, but |
| 19 | don't cause an error. |
| 20 | |
| 21 | If the array-calling mode is available, the macro |
| 22 | __LPC_ARRAY_CALLS__ is defined. |
| 23 | |
| 24 | The object(s) can be given directly or via a string (i.e. its |
| 25 | object_name). If it is given by a string and the object does not |
| 26 | exist yet, it will be loaded. |
| 27 | |
| 28 | ob->fun(args) and "ob_name"->fun(args) is equivalent to |
| 29 | call_other(ob, "fun", args). Nowadays the ob_name string can |
| 30 | also be a variable. |
| 31 | |
| 32 | ob->fun(args) and ob->"fun"(args) are equivalent to |
| 33 | call_other(ob, "fun", args). ob->(fun)(args) are equivalent |
| 34 | to call_other(ob, fun, args) where fun is a runtime expression |
| 35 | returning the function name. |
| 36 | |
| 37 | If ob::fun does not define a publicly accessible function, the |
| 38 | call_other() will return 0, which is indistinguishable from |
| 39 | a function returning 0. |
| 40 | |
| 41 | "publicly accessible" means "public" when calling other objects, |
| 42 | and "public" or "static" when calling this_object(). "private" |
| 43 | and "protected" function can never be called with call_other(). |
| 44 | |
| 45 | The return type of call_other() is 'any' be default. However, |
| 46 | if your LPC code uses #pragma strict_types, the return type is |
| 47 | 'unknown', and the result of call_other() must be casted to |
| 48 | the appropriate type before you can use it for anything. |
| 49 | |
| 50 | EXAMPLES |
| 51 | // All the following statements call the lfun QueryProp() |
| 52 | // in the current player with the argument P_SHORT. |
| 53 | string str, fun; |
| 54 | |
| 55 | str = (string)call_direct(this_player(), "QueryProp", P_SHORT); |
| 56 | fun = "QueryProp"; |
| 57 | str = (string)call_direct(this_player(), fun, P_SHORT); |
| 58 | |
| 59 | You have to do explicit type casting because of the unknown |
| 60 | return type, if you have set #pragma strict_types. |
| 61 | |
| 62 | // This statement calls the lfun short() in all interactive users |
| 63 | // and stores the collected results in a variable. |
| 64 | string * s; |
| 65 | |
| 66 | s = (string *)call_direct(users(), "short"); |
| 67 | |
| 68 | |
| 69 | HISTORY |
| 70 | Introduced in LDMud 3.3.113 with the H_DEFAULT_METHOD hook. |
| 71 | LDMud 3.2.10 made the call on arrays of objects configurable. |
| 72 | |
| 73 | SEE ALSO |
| 74 | call_other(E), call_direct_resolved(E), create(A), pragma(LPC), |
| 75 | extern_call(E), function_exists(E), functions(LPC) |