MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 2 | void set_this_object(object|lwobject object_to_pretend_to_be) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 3 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 4 | DESCRIPTION |
| 5 | This is a privileged function, only to be used in the master |
| 6 | object or in the simul_efun object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 18 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 23 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 24 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 28 | BUGS |
| 29 | It is currently not possible to directly restore the original |
| 30 | current object. So instead of writing |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 31 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 32 | object me = this_object(); |
| 33 | set_this_object(that); |
| 34 | <some code> |
| 35 | set_this_object(me); |
| 36 | <more code> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 37 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 38 | one has to use a workaround: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 39 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 40 | private void doit (object that) { |
| 41 | set_this_object(that); |
| 42 | <some code> |
| 43 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 44 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 45 | funcall(#'doit, that); |
| 46 | <more code> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 47 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 48 | Some people would consider this a feature. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 49 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 50 | HISTORY |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 54 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 55 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 56 | this_object(E), set_this_player(E) |