lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I¹ve studied but not implemented something like this. You essentially need
the following information available:

    the class for the object
    the class defining the current method
    the name of the method in question

Given that and a linearization of the classes, you can find the next method.
With some fancier data structures, you can do so efficiently.

So, would you be willing to write:

    self:call_next( ThisClass, "methodName", < params > )

This assumes that the class for self can be derived either from self or that
it gets baked into the implementation of call_next.

If you are prepared to play with function environments, you can actually get
this down to:

    next( self, < params > )

Doing so involves modifying the function environment for the methods in
ThisClass so that they have appropriate definitions of next.

Note, however, that there isn't a way in Lua to duplicate a function and
give it a new environment which makes playing with function environments a
little bit risky.

Mark

on 7/4/05 9:15 AM, Martin Kendall at martinkendall@email.com wrote:

> All,
> 
> 
> 
> I am looking at extending the multiple inheritance example in ³Programming In
> Lua² (ch. 16.3).   I would like to support method chaining, i.e. at the point
> marked by a call to ³next² , the next shadowed method on a ³next-path² is
> searched and, when it is found, it is mixed into the execution of the current
> method (i.e. executed in the same scope and then execution of the original
> method continues). This is a more generic version of a call to super() in a
> Java constructor.  The idea for this is taken from XOTCL
> http://media.wu-wien.ac.at/.
> 
> 
> 
> My initial though is to have a root Object that handles the message ³next² (I
> would be aiming for the ³next-path² to be predictable (breadth first search),
> but any thoughts from more experienced lua programmers would be appreciated.
> 
> 
> 
> Regards,
> 
> 
> 
> Martin 
>