blob: bf28d5cfc21cec5c8cd3a8d4fc60a70707811461 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra5481d492021-04-08 20:07:06 +02002 object|lwobject previous_object()
3 object|lwobject previous_object(int i)
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005DESCRIPTION
6 Returns an object pointer to the object that did a call (call_other(),
7 funcall(), etc) to the current object, if any. If that object is
8 destructed, the function returns 0.
MG Mud User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010 If the optional arg is given, the call_other()s are followed
11 back i times (i.e. previous_object(1) returns the caller of
12 the caller): 0 <= i < caller_stack_depth(). If <i> is less than 0, the
13 first previous object is returned.
MG Mud User88f12472016-06-24 23:31:02 +020014
Zesstra715ec202025-07-09 22:18:31 +020015 There is an important special case: in functions called by
16 the gamedriver in reaction to some external event (e.g. commands
17 added by add_action), previous_object() will return this_object(),
18 but previous_object(0) will return 0.
MG Mud User88f12472016-06-24 23:31:02 +020019
Zesstra715ec202025-07-09 22:18:31 +020020EXAMPLES
21 int security() {
22 object|lwobject prev;
23 if (!(prev=previous_object()));
24 else if (getuid(prev) != getuid(this_object()));
25 else if (geteuid(prev) != geteuid(this_object()));
26 else return 1;
27 return 0;
MG Mud User88f12472016-06-24 23:31:02 +020028 }
Zesstra715ec202025-07-09 22:18:31 +020029 void highly_sensible_func() {
30 if (!security())
Zesstrad59c3892019-11-28 20:53:39 +010031 return;
MG Mud User88f12472016-06-24 23:31:02 +020032 ...
33 }
34
Zesstra715ec202025-07-09 22:18:31 +020035 This example shows how we can check if the last call to a
36 function of the current object is secure or if we should abort
37 execution.
MG Mud User88f12472016-06-24 23:31:02 +020038
Zesstra715ec202025-07-09 22:18:31 +020039BUGS
40 Values of i < 0 are treated as if i == 0 was passed - this is
41 historic.
MG Mud User88f12472016-06-24 23:31:02 +020042
Zesstra715ec202025-07-09 22:18:31 +020043SEE ALSO
44 call_other(E), this_object(E), this_player(E),
45 caller_stack(E), caller_stack_depth(E), extern_call(E)