|
Am 23.03.2018 um 09:41 schröbte Sergey Zakharchenko:
Dirk,If __pairs is invoked wth a second argument equal to the special value false, the caller is not interested in values (only in keys), so the returned iterator may returned any value, including nil, or no value at all, for them.You can already write "for k in pairs(tbl,false) do ... end".Sure I can. However, certain kinds of (heavily meta) tables may have a high cost of value retrieval, which this proposal aims to eliminate.
When using the `pairs` function, I expect getting pairs. An iterator factory for keys only would better be called `keys()`. Implementation-wise it could look for a `__keys` metamethod for those performance critical cases and fall back to the `pairs` protocol but dropping the second value.
Philipp