Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 2 | int shadow(object ob) |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 3 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 4 | DESCRIPTION |
| 5 | The current object will become a shadow of ob. This efun |
| 6 | returns 1 on success, 0 otherwise. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | The calling object must be permitted by the master object to |
| 9 | do the shadowing. In most installations, an object that |
| 10 | defines the function query_prevent_shadow() to return 1 |
| 11 | can't be shadowed, and the shadow() function will return 0 |
| 12 | instead of ob. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 13 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 14 | shadow() also fails if the calling object tries to shadow |
| 15 | a function that was defined as ``nomask'', if the program was |
| 16 | compiled with the #pragma no_shadow, or if the calling |
| 17 | object is already shadowing, is being shadowed, or has an |
| 18 | environment. Also the target ob must not be shadowing |
| 19 | something else. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 20 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 21 | If an object A shadows an object B then all call_other() to B |
| 22 | will be redirected to A. If object A has not defined the |
| 23 | function, then the call will be passed to B. There is only on |
| 24 | object that can call functions in B with call_other(), and |
| 25 | that is A. Not even object B can call_other() itself. All |
| 26 | normal (internal) function calls inside B will however remain |
| 27 | internal to B. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 29 | EXAMPLES |
| 30 | With the three objects a.c, b.c and c.c |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 31 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 32 | --- a.c --- |
| 33 | int fun() { |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 34 | debug_message(sprintf("%O [a] fun()\n", this_object())); |
| 35 | } |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 36 | |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 37 | void fun3() { |
| 38 | debug_message(sprintf("%O [a] fun3()\n", this_object())); |
| 39 | } |
| 40 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 41 | --- b.c --- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 42 | int fun() { |
| 43 | debug_message(sprintf("%O [b] fun()\n", this_object())); |
| 44 | find_object("a")->fun(); |
| 45 | } |
| 46 | void fun2() { |
| 47 | debug_message(sprintf("%O [b] fun2()\n", this_object())); |
| 48 | find_object("a")->fun3(); |
| 49 | this_object()->fun3(); |
| 50 | } |
| 51 | |
| 52 | void do_shadow(object target) { shadow(target, 1); } |
| 53 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 54 | --- c.c --- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 55 | int fun() { |
| 56 | debug_message(sprintf("%O [c] fun()\n", this_object())); |
| 57 | find_object("a")->fun(); |
| 58 | } |
| 59 | void fun3() { |
| 60 | debug_message(sprintf("%O [c] fun3()\n", this_object())); |
| 61 | } |
| 62 | void do_shadow(object target) { shadow(target, 1); } |
| 63 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 64 | code like the following |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 65 | |
| 66 | object a, b, c; |
| 67 | |
| 68 | a = load_object("a"); |
| 69 | b = load_object("b"); |
| 70 | c = load_object("c"); |
| 71 | b->do_shadow(a); |
| 72 | c->do_shadow(a); |
| 73 | debug_message("--- a->fun() ---\n"); |
| 74 | a->fun(); |
| 75 | debug_message("--- b->fun() ---\n"); |
| 76 | b->fun(); |
| 77 | debug_message("--- c->fun() ---\n"); |
| 78 | c->fun(); |
| 79 | debug_message("--- b->fun2() ---\n"); |
| 80 | b->fun2(); |
| 81 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 82 | produces this output: |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 83 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 84 | --- a->fun() --- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 85 | /c [c] fun() |
| 86 | /b [b] fun() |
| 87 | /a [a] fun() |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 88 | --- b->fun() --- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 89 | /c [c] fun() |
| 90 | /b [b] fun() |
| 91 | /a [a] fun() |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 92 | --- c->fun() --- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 93 | /c [c] fun() |
| 94 | /b [b] fun() |
| 95 | /a [a] fun() |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 96 | --- b->fun2() --- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 97 | /b [b] fun2() |
| 98 | /a [a] fun3() |
| 99 | /c [c] fun3() |
| 100 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 101 | Note that the first call in b::fun2() find c::fun3()! Reason is that |
| 102 | for calls originating from b to a the driver assumes that all |
| 103 | shadows beyond c already had their chance. The second call however |
| 104 | was to b itself, which the gamedriver recognized as being shadowed |
| 105 | by c. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 106 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 107 | HISTORY |
| 108 | Up to 3.2.1@46, destructing a shadowed object also destructs |
| 109 | all shadows. Since 3.2.1@47, shadows may survive the |
| 110 | destruction of the shadowee (unless the prepare_destruct() in |
| 111 | the master object destructs them manually). |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 112 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 113 | Since LDMud 3.2.8, programs may protect themselves from being |
| 114 | shadowed with the #pragma no_shadow. |
| 115 | |
| 116 | SEE ALSO |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 117 | query_shadowing(E), unshadow(E), query_allow_shadow(M) |