[DGD]nill instead of error on function name typo...

Erwin Harte harte at xs4all.nl
Fri Jun 8 00:13:57 CEST 2001


On Thu, Jun 07, 2001 at 03:56:40PM -0500, Michael J. Bacon wrote:
> 
> > Redefine call_other() in the auto object, and let it check whether the
> > function exists before calling it.
> 
> 	Waaaay over my head there...
> 
> 	call_other is a driver level kfun I thought, isn't it?  How do I redefine
> it on the auto object and how do determine whether or not a function is
> defined on a given object?

Greg, could you add this one to the FAQ? :-)

----------------------------------------------------------------------
Q:
   How to redefine call_other() so that only function-calls to existing
   functions will work and non-existing functions won't fail silently.

A: 
   # include <type.h>

   static mixed
   call_other(mixed obj, string function, mixed args...)
   {
       switch (typeof(obj)) {
       case T_STRING:
           obj = find_object(obj);
           /* Fill in other bits similar to driver's all_object if necessary */
           if (!obj) {
               error("Bad argument 1 to function call_other");
           }
           break;
       case T_OBJECT:
          break;
       default:
           error("Bad argument 1 to function call_other");
       }
       switch (function) {
       case "":
       case "???":
           /* Typically used to trigger object-initialization */
           break;
       default:
           if (!function_object(function, obj)) {
               error("Function " + function + " does not exist");
           }
           break;
       }
       return ::call_other(obj, function, args...);
   }
----------------------------------------------------------------------

Erwin.
-- 
Erwin Harte <harte at xs4all.nl>

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list