[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New metamethod for method lookup
- From: Mark Hamburg <mark@...>
- Date: Sun, 15 Nov 2009 18:12:13 -0800
On Nov 15, 2009, at 3:54 PM, Alex Davies wrote:
> One issue I have with the idea is there is no one way to index in Lua. Sometimes, even for function calls, you have to index from a variable in a string []. Other times the method : call is fine. Sometimes you just want to pass a different self, so . is applicable. So for this to work you'd need to add a "getmethod(table, key)" function, which is a bit tacky imo, but would work.
I called that out though, I think that part of the motivation for doing this actually argues against support for calling a method with a different self, so one wants:
mcall( obj, mkey, ... ) or obj:[ mkey ]( ... )
The latter has the benefit of being able to compile to the same VM code and doesn't require a function call. It's also probably more efficient than the current
obj[ mkey ]( obj, ... )
One also wants mbind( obj, mkey ) which returns a closure to invoke the method on the object. This could be sugared to obj:mkey though implementing it is more than just an isolated tweak to the compiler.
Thanks for digging up the info on __proxy. This solves the properties v methods problem and does so without particularly complicating the semantics, but it does not provide the other benefits of __methindex with respect to things like making sure that methods are always accessed as methods.
Mark