lua-users home
lua-l archive

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


On Sep 10, 2011, at 12:19 PM, Luiz Henrique de Figueiredo wrote:

>> To make matters more confusing for the new-to-Lua programmer, people often implement methods using the __index entry in metatables, possibly going so far as to make __index point at the metatable itself (a horrendous semantic security hole if one worries about such things).
> 
> That's what I do. Why is it so bad?

It makes all of your metatable entries readable including making the identity of the metatable available by looking up the value of __index. [ setmetatable( myObj, yourObj.__index ) ].

Now, a lot of code doesn't need to worry about what is or isn't exposed, and this idiom is perfectly reasonable in such contexts, but I think it's also important for people to know what the pitfalls are and the chief one is that this idiom makes visible a lot more than one might at first think.

Mark