I don't know what I do wrong. Basically the code looks like this:
local t = setmetatable({}, {__pairs = function (self)
print "Message from __pairs()"
return function ()
...
end
end})
for k, v in pairs(t) do ... end
The same for __ipairs(). Overloaded metamethods aren't called at all - no console output, no custom iteration at all. Instead I get the result as if I iterate through a table without metatable. What's wrong?
You most likely use Lua 5.1 (or its derivative), which doesn't have support for these metamethods, as these were introduced in Lua 5.2. I've tested in Lua 5.2-5.4 and confirmed that your code works there (the method is called).