lua-users home
lua-l archive

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


I too added something like this based on OP_SELF. I was planning on backing
it out as part of going to 5.1 just to have less to track when following
versions, but if it's being done often enough, it is probably worth
consideration as to:

1. What are the exact semantics desired for __methcall and the : operator.
This is the trickier part. See some discussion below.

2. What additional functions are needed? I added:

    callmethod( obj, msg, ... )
        -- invokes obj:msg( ... )

    pcallmethod
        -- invokes obj:msg( ... ) in a protected context

    bindmethod( obj, msg )
        -- returns a function that will invoke obj:msg( ... )

3. Does __methcall just return a function to invoke or does it actually take
the parameters? The former is easier to integrate with the existing OP_SELF
but might not be as nice semantically.

4. Could this be handled by adding a third parameter to __index to indicate
whether this request came from a method call context?


Some of the issues with __methcall include:

1.1 What precedence is given to __methcall v table entries?

1.2 Can __methcall be a table or does it have to be a function?

1.3 What does inheritance look like in this model? It's very simple in the
__index model.


The big benefits of __methcall seem to be:

* Easier support for safe userdata method invocation since methods can't be
pulled off of one object and used on another. I could see a case for
supporting __methcall just for userdata.

* Separate namespaces for methods and attributes.

Mark

on 11/4/04 8:05 AM, Daniel Silverstone at dsilvers@digital-scurf.org wrote:

> On Thu, 2004-11-04 at 15:30 +0000, David Given wrote:
> [snip]
>> pseudofunction like length(t) would not). But, is there a better way of
>> solving the underlying problem? Might it not be worth finally biting the
>> bullet and distinguishing between field lookups and method calls?
> [snip]
>> (BTW, would this work via a metatable operation? Could you virtualise it?)
> 
> I considered this; given that OP_SELF already exists; and created a
> __methcall metamethod.
> 
> The patch is on the page I'm using to gather the language changes I'm
> writing for Aranha...
> 
> http://wiki.digital-scurf.org/Aranha/LanguageModifications
> 
> Feel free to nab the patch and play
> 
> D.