Iter metamethod ( __iter ) documentation is missing

In May of last year, the iterator metamethod (__iter) was implemented (as noted in this post). However, it seems there is nothing yet written in the docs about it. This should be listed with the other metamethods

This should most likely also be mentioned in the for loops documentation.

Thanks!

Page URL: https://create.roblox.com/docs/scripting/luau/metatables

7 Likes

(for reference)

__iter: <A, B>(A) -> ((B, nextIndex: any) -> ...any, B?)
local mt = {
  __iter = function(self)
    return next, self.x
  }
}

local t = setmetatable({x = {1, 2, 3, 4, 5}}, mt)
for i, v in t do
  print(i, v)
end
3 Likes

Thanks for the report! We’ll follow up when we have an update for you.

4 Likes

Thanks for reporting @Neutron_Flow! The improvements came in somewhat piecemeal, with one more minor addition coming in a day or two, but the core pieces are in place and released at this point. Special thanks to metatablecat for all the help over in the open source repository. :pray:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.