[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: idea: __iter generic-for metamethod
- From: "Stuart P. Bentley" <stuart@...>
- Date: Mon, 24 May 2010 17:41:35 -0700
Correcting a couple mistakes:
A for statement like
for var_1, ···, var_n in explist do block end
is equivalent to the code:
do
local f, s, var = explist
--proposed addition
if type(f)~= "function" and not metatable(f).__call then
local meta_f = metatable(f).__iter
if not meta_f and type(f)=="table" then meta_f = pairs end
if meta_f then f, s, var = meta_f(explist) end
end
while true do
local var_1, ···, var_n = f(s, var)
var = var_1
if var == nil then break end
block
end
end