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

6 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

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

3 Likes