lua-users home
lua-l archive

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

on 9/23/05 5:17 PM, Eric Jacobs at 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