lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I think you'd need to have a 'pairs' analog which returned a 'next' analog that was a callable object but not a function to break it - I cannot think of a reasonable usage case for that. My caveat may be over-cautious!


Right -- of course.  So with the patch on we can't use function objects as iterators.  i.e., this breaks:

local function mypairs(t)
local function __call(self,...)
return next(...)
end
return setmetatable({"wrong table"},{__call=__call}), t
end

local t={1,2,3}

for k,v in mypairs(t) do
   console(k,v)
end

I actually think that's a fairly serious point against the patch.  It's true that it's not a case that would come up often, but, it's a difficult error case to understand.  Some kind of implicit pairs call is a useful shorthand, but I think I'd prefer it as a parser patch.   'for k : t' ==> 'for k in pairs(t)' would feel simpler and cleaner.

-Sven