Geas MUD, enter the Aventure!
Geas Home | Play the Game

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2.1 Object references relative to the current object

An object can always get the object reference to itself. Use the efun this_object():

 
object this_object()
e.g.
    object ob;

    ob = this_object();

In order to find out which object called the currently running function in an object using an external call, you can use the efun 'previous_object()':

 
object previous_object(void|int step)
e.g.
    object p_ob, pp_ob;

    p_ob = previous_object();     // The object calling this function.
    pp_ob = previous_object(-2);  // The object calling the object
                                  // calling this function.

If you supply no argument or -1, the function will return the immediately previous object that called. Decrementing the argument further will return even more previous callers, i.e previous_object(-4) returns the object that called the object that called the object that called your object. If indeed the chain of calling objects was that long. When you exceed the length of the calling chain beyond the first object that made a call, the function will return 0.

As I hope you noticed, this call only checks for external calls, not internal. There is a corresponding efun that works just the same but for any type of call (internal or external) that has been made:

 
object calling_object(void|int step)

The usage is the same however.

So... how do you know if the object reference you just received is a valid object or not (i.e. 0 or something else)? Well, use the nice efun objectp() as described earlier. It returns 1 if the argument is a valid object pointer and 0 otherwise.

 
int objectp(mixed ob)
e.g.
    if (objectp(calling_object(-2)))
        write("Yes, an ob calling an ob calling this object exists!\n");
    else
        write("No such luck.\n");


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ronny Wikh on July, 8 2003 using texi2html