|
While meta methods for pairs/ipairs might indeed be overkill, I disagree that this is always the case. Take tostring() for example. Would you advocate removing __tostring()? I would argue this is a bad idea. Sure, I can write some kind of tostring() over-ride, or create one for each type of object, but that doesnt help in large projects where I might not have control of (or even access to) all the code using tostring() to generate output. The fact is, in larger projects, polymorphic/generic functions are indeed very useful, and metamethods are one way to create these. Arguing that pairs() should not have a meta method because “it’s just a Lua function” doesnt seem to me much of an argument. You are better arguing that ipairs() is DEFINED as iterating over all positive numeric indices in order until a nil is returned, which IS a valid argument against __ipairs meta method (which could break this contract). —Tim |