[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: __methcall
- From: Mark Hamburg <mhamburg@...>
- Date: Thu, 04 Nov 2004 09:43:12 -0800
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( ... )
-- 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
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.
on 11/4/04 8:05 AM, Daniel Silverstone at email@example.com wrote:
> On Thu, 2004-11-04 at 15:30 +0000, David Given wrote:
>> 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?
>> (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...
> Feel free to nab the patch and play