MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | SYNOPSIS |
| 2 | #include <sys/driver_hooks.h> |
| 3 | |
| 4 | set_driver_hook(H_MODIFY_COMMAND, value) |
| 5 | |
| 6 | <value> being: |
| 7 | |
| 8 | int|string <closure>(string cmd, object player) |
| 9 | int|string <name>(string cmd) |
| 10 | <mapping> |
| 11 | |
| 12 | DESCRIPTION |
| 13 | Optional hook to modify commands (both entered or given by a |
| 14 | call to command()) before the parser sees them (this includes |
| 15 | special commands like 'status'). |
| 16 | |
| 17 | Hook setting can be any closure, the name of the function to |
| 18 | call in the object, or a mapping. |
| 19 | |
| 20 | For interactives this hook is used only if the interactive |
| 21 | object has no command modifier already set by the efun |
| 22 | set_modify_command(). |
| 23 | |
| 24 | If the hook is a closure, it is called with the entered |
| 25 | command as first, and the command giving player as second |
| 26 | argument. Lambda closures are bound to the command giving player, |
| 27 | unbound-lambda closures remain unbound. |
| 28 | |
| 29 | If the hook is a string, it is used as the name of an lfun |
| 30 | in the command giving player, which is called with the command |
| 31 | as argument. |
| 32 | |
| 33 | If the hook is a mapping, it is queried with the given command |
| 34 | as index, and the data retrieved is used as new command |
| 35 | (defaults to 0 if no data is stored for a given command). If |
| 36 | an entry is a closure instead of a string, it is called as |
| 37 | |
| 38 | int|string <closure>(string cmd, object player) |
| 39 | |
| 40 | and the result from the call is used as 'the' command. |
| 41 | |
| 42 | The result is treated equal in all three cases: |
| 43 | - If the result is a string, it is the new command to execute |
| 44 | instead of the given one. Note that it is not possible to |
| 45 | make several commands from one this way! |
| 46 | - If the result is a non-zero number, the given command is to |
| 47 | be ignored. In case of the closure/lfun setting this may |
| 48 | mean that the closure/lfun already executed it. |
| 49 | - If the result is 0, the originally given command is to be |
| 50 | used. |
| 51 | |
| 52 | It is possible for the hook to change the command giver |
| 53 | (this_player()) for the execution of the command. This means that |
| 54 | even though the commands are execute for the original commandgiver, |
| 55 | this_player() will return the changed commandgiver. |
| 56 | |
| 57 | HISTORY |
| 58 | |
| 59 | SEE ALSO |
| 60 | hooks(C), command(H), modify_command_fname(H), notify_fail(H), |
| 61 | send_notify_fail(H) |