[DGD] Overriding kfuns
bart at wotf.org
bart at wotf.org
Wed Feb 8 23:41:50 CET 2017
A related behavior which might not be obvious at first glance is how this
works for inherited code.
Lets assume objects a and b, where a inherits b.
Lets stick to your example, and have object a define an lfun for explode().
Lets also assume you have code (your member function) in object b which uses
explode()
Now, when b gets compiled, dgd does not know anything about an explode() lfun
in a, and any reference to explode() in b will use the kfun (or an explode()
afun if it exists). Object a can as a consequence mask explode() but it will
only affect code in object a and anything inheriting a, but it can't override
explode() used by the code it inherits.
If b however would define an lfun explode(), a can mask that lfun, and the
function in a will be called when code in b uses explode()
iirc efuns on a classic lpmud driver have similar behavior, but it has been
some 15 years since I last touched one of those.
Bart.
On Wed, 8 Feb 2017 16:05:52 -0600, Blain wrote
> Ok, that's a difference from what I'm used to. Good to know.
>
> On Feb 8, 2017 4:04 PM, <bart at wotf.org> wrote:
>
> > If explode() wasn't a kfun, you'd get an undefined function error
> > according to
> > the rules of DGD's lpc dialect. When compiling the code for the member()
> > lfun,
> > it simply doesn't know yet about the later explode() lfun, unless you
> > provide
> > a prototype.
> >
> > Now, explode is a kfun, so when it gets referenced in member(), dgd still
> > doesn't know about your lfun, but it does know about the kfun, so you get
> > no
> > error.
> >
> > Now, the bytecode to call an lfun is different from the bytecode to call a
> > kfun, and member() has been compiled to use bytecode for calling the kfun
> > so
> > it will never look at your lfun at all.
> >
> > As an aside, functions defined in the auto object have similar properties
> > (and
> > iirc calling an afun also uses different bytecode)
> >
> > So for all I can tell, its a combination of the language rules and the
> > design
> > of dgd.
> >
> > Bart.
> >
> > On Wed, 8 Feb 2017 14:36:47 -0600, Blain wrote
> > > Quick question.
> > >
> > > lfun: member()
> > > lfun: explode()
> > >
> > > My lfun member() was using the kfun explode() instead of my lfun
> > > explode() further down in the object until I added a prototype for
> > > explode() at the top of the file. Is this by design?
> > ____________________________________________
> > > https://mail.dworkin.nl/mailman/listinfo/dgd
> >
> >
> > --
> > http://www.flickr.com/photos/mrobjective/
> > http://www.om-d.org/
> >
> > ____________________________________________
> > https://mail.dworkin.nl/mailman/listinfo/dgd
> ____________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd
--
http://www.flickr.com/photos/mrobjective/
http://www.om-d.org/
More information about the DGD
mailing list