[DGD] Undefined function hook

Mikael Lind mikkelin at gmail.com
Mon Jul 9 11:13:13 CEST 2007


Hello,

Programming languages such as Python and Ruby have hooks for undefined
functions allowing the called object to intercept the call and handle
it with a fallback.

In DGD, this kind of functionality can be provided by overriding
call_other() in the system auto object:

static mixed call_other(mixed obj, string func, mixed args...)
{
    if (typeof(obj) == T_STRING) {
        /* find or compile named object */
    }
    return function_object(func, obj)
        ? ::call_other(obj, func, args...)
        : ::call_other(obj, "call_missing", func, args);
}

Now you can finally do:

room->find_orc_having_two_scars_on_left_leg()

Implementing the proper call_missing() function in the room is an
exercise left to the reader.

Can anyone find other or better uses for this hook? What are the
security implications? How are they best handled?

Regards,
Mikael



More information about the DGD mailing list