[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Object binding comments wanted
- From: Mark Hamburg <mhamburg@...>
- Date: Sun, 25 Sep 2005 11:07:24 -0700
on 9/23/05 5:17 PM, Eric Jacobs at eric@theeric.com wrote:
> I have a situation similar to this. I've grown fond of the following technique
> to call object methods. I think it's a big win once you get used to its
> syntax:
>
> obj[intf.method]()
>
> Here, the intf.method can be a userdata that points directly at your
> underlying object system's method descriptor structure. When the __index
> metamethod gets the userdata, all it has to do is prepare the arguments
> and then do the method dispatch just as a call in your native implementation
> would do. You don't have to do a string lookup at call-time (although this
> isn't terrible in Lua because strings are automatically interned), plus
> you have full immunity to namespace collision problems among interfaces.
Does this rely on the __index metamethod generating a custom closure for
each call (possibly cached) to make the value of obj available?
I actually rather like this as a way to avoid namespace collisions on
methods, but it perhaps needs syntactic support in the form of something
like:
obj:[intf.method]()
Mark