MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 2 | object|lwobject previous_object() |
| 3 | object|lwobject previous_object(int i) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 5 | DESCRIPTION |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 10 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 14 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 15 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 19 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 20 | EXAMPLES |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 28 | } |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 29 | void highly_sensible_func() { |
| 30 | if (!security()) |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 31 | return; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 32 | ... |
| 33 | } |
| 34 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 35 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 38 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 39 | BUGS |
| 40 | Values of i < 0 are treated as if i == 0 was passed - this is |
| 41 | historic. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 42 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 43 | SEE ALSO |
| 44 | call_other(E), this_object(E), this_player(E), |
| 45 | caller_stack(E), caller_stack_depth(E), extern_call(E) |