blob: 2af7e1df4479a7e8db01c49011ee3244e632ba2f [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 void set_this_object(object|lwobject object_to_pretend_to_be)
MG Mud User88f12472016-06-24 23:31:02 +02003
Zesstra715ec202025-07-09 22:18:31 +02004DESCRIPTION
5 This is a privileged function, only to be used in the master
6 object or in the simul_efun object.
MG Mud User88f12472016-06-24 23:31:02 +02007
Zesstra715ec202025-07-09 22:18:31 +02008 It changes the result of this_object() in the using function,
9 and the result of previous_object() in functions called in
10 other objects by call_other()/apply()/funcall(). Its effect will
11 remain till there is a return of an external function call, or
12 another call of set_this_object(). While executing code in the
13 master object's program or the primary simul_efun object's
14 program, set_this_object() is granted even if this_object() is
15 altered by set_this_object(). This does not apply to functions
16 inherited from other programs.
MG Mud User88f12472016-06-24 23:31:02 +020017
Zesstra715ec202025-07-09 22:18:31 +020018 Use it with extreme care to avoid inconsistencies. After a
19 call of set_this_object(), some LPC-constructs might behave in
20 an odd manner, or even crash the system. In particular, using
21 global variables or calling local functions (except by
22 call_other) is illegal and actively prevented.
MG Mud User88f12472016-06-24 23:31:02 +020023
Zesstra715ec202025-07-09 22:18:31 +020024 Allowed are call_other(), map functions, access of local variables
25 (which might hold array pointers to a global array), simple arithmetic
26 and the assignment operators.
MG Mud User88f12472016-06-24 23:31:02 +020027
Zesstra715ec202025-07-09 22:18:31 +020028BUGS
29 It is currently not possible to directly restore the original
30 current object. So instead of writing
MG Mud User88f12472016-06-24 23:31:02 +020031
Zesstra715ec202025-07-09 22:18:31 +020032 object me = this_object();
33 set_this_object(that);
34 <some code>
35 set_this_object(me);
36 <more code>
MG Mud User88f12472016-06-24 23:31:02 +020037
Zesstra715ec202025-07-09 22:18:31 +020038 one has to use a workaround:
MG Mud User88f12472016-06-24 23:31:02 +020039
Zesstra715ec202025-07-09 22:18:31 +020040 private void doit (object that) {
41 set_this_object(that);
42 <some code>
43 }
MG Mud User88f12472016-06-24 23:31:02 +020044
Zesstra715ec202025-07-09 22:18:31 +020045 funcall(#'doit, that);
46 <more code>
MG Mud User88f12472016-06-24 23:31:02 +020047
Zesstra715ec202025-07-09 22:18:31 +020048 Some people would consider this a feature.
MG Mud User88f12472016-06-24 23:31:02 +020049
Zesstra715ec202025-07-09 22:18:31 +020050HISTORY
51 LDMud 3.2.10 actively prevents references to global variables
52 and function calls by address while set_this_object() is in
53 effect.
MG Mud User88f12472016-06-24 23:31:02 +020054
Zesstra715ec202025-07-09 22:18:31 +020055SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020056 this_object(E), set_this_player(E)