blob: bf8d1568056006ee15c0f70df7174d62d5f9c1e5 [file] [log] [blame]
Zesstrad59c3892019-11-28 20:53:39 +01001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 int shadow(object ob)
Zesstrad59c3892019-11-28 20:53:39 +01003
Zesstra715ec202025-07-09 22:18:31 +02004DESCRIPTION
5 The current object will become a shadow of ob. This efun
6 returns 1 on success, 0 otherwise.
Zesstrad59c3892019-11-28 20:53:39 +01007
Zesstra715ec202025-07-09 22:18:31 +02008 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.
Zesstrad59c3892019-11-28 20:53:39 +010013
Zesstra715ec202025-07-09 22:18:31 +020014 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.
Zesstrad59c3892019-11-28 20:53:39 +010020
Zesstra715ec202025-07-09 22:18:31 +020021 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.
Zesstrad59c3892019-11-28 20:53:39 +010028
Zesstra715ec202025-07-09 22:18:31 +020029EXAMPLES
30 With the three objects a.c, b.c and c.c
Zesstrad59c3892019-11-28 20:53:39 +010031
Zesstra715ec202025-07-09 22:18:31 +020032 --- a.c ---
33 int fun() {
Zesstrad59c3892019-11-28 20:53:39 +010034 debug_message(sprintf("%O [a] fun()\n", this_object()));
35 }
Zesstra715ec202025-07-09 22:18:31 +020036
Zesstrad59c3892019-11-28 20:53:39 +010037 void fun3() {
38 debug_message(sprintf("%O [a] fun3()\n", this_object()));
39 }
40
Zesstra715ec202025-07-09 22:18:31 +020041 --- b.c ---
Zesstrad59c3892019-11-28 20:53:39 +010042 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
Zesstra715ec202025-07-09 22:18:31 +020054 --- c.c ---
Zesstrad59c3892019-11-28 20:53:39 +010055 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
Zesstra715ec202025-07-09 22:18:31 +020064 code like the following
Zesstrad59c3892019-11-28 20:53:39 +010065
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
Zesstra715ec202025-07-09 22:18:31 +020082 produces this output:
Zesstrad59c3892019-11-28 20:53:39 +010083
Zesstra715ec202025-07-09 22:18:31 +020084 --- a->fun() ---
Zesstrad59c3892019-11-28 20:53:39 +010085 /c [c] fun()
86 /b [b] fun()
87 /a [a] fun()
Zesstra715ec202025-07-09 22:18:31 +020088 --- b->fun() ---
Zesstrad59c3892019-11-28 20:53:39 +010089 /c [c] fun()
90 /b [b] fun()
91 /a [a] fun()
Zesstra715ec202025-07-09 22:18:31 +020092 --- c->fun() ---
Zesstrad59c3892019-11-28 20:53:39 +010093 /c [c] fun()
94 /b [b] fun()
95 /a [a] fun()
Zesstra715ec202025-07-09 22:18:31 +020096 --- b->fun2() ---
Zesstrad59c3892019-11-28 20:53:39 +010097 /b [b] fun2()
98 /a [a] fun3()
99 /c [c] fun3()
100
Zesstra715ec202025-07-09 22:18:31 +0200101 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.
Zesstrad59c3892019-11-28 20:53:39 +0100106
Zesstra715ec202025-07-09 22:18:31 +0200107HISTORY
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).
Zesstrad59c3892019-11-28 20:53:39 +0100112
Zesstra715ec202025-07-09 22:18:31 +0200113 Since LDMud 3.2.8, programs may protect themselves from being
114 shadowed with the #pragma no_shadow.
115
116SEE ALSO
Zesstrad59c3892019-11-28 20:53:39 +0100117 query_shadowing(E), unshadow(E), query_allow_shadow(M)