[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: metatable transmission
- From: Mark Hamburg <mark@...>
- Date: Tue, 22 Dec 2009 16:52:15 -0800
On Dec 22, 2009, at 9:37 AM, steve donovan wrote:
> On Tue, Dec 22, 2009 at 7:11 PM, Mark Hamburg <email@example.com> wrote:
>> (I'm less fond of the trick of having the __index entry in the metatable point back to the metatable. As far as I can see, all this does is save one table in the system and it does so at the expense of making all of the metamethods available for __index access.)
> I see the point (an extra table is nothing here) but why should one
> want to prevent the metamethods from being accessed from the object?
It's basically an encapsulation hole. Now, as I noted in my earlier message there's a lot of "encapsulation by convention" but it doesn't seem like one necessarily wants to encourage it.
For example, if __index points back to the metatable then obj.__index.__index gives you write access to the metatable by which you can then whack not just one object but all objects with that metatable.