一个可以返回多值的迭代器

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

function list_iter_time(t, time)
	local index = 0
	local size = #t
	return function()
		local result = {}
		--- bug local loop =  (size - index) % time and time
                local loop = size - index >= time and time or size % time
		if index + loop <= size then
			for i = 0, loop do
				table.insert(result, t[index + i + 1])
			end
			index = index + loop
		end
		return unpack(result)
	end
end

--sample
for val1, val2, val3 in list_iter_time({1, 2, 3, 4, 5, 6, 7, 8}, 3) do
	print(val1, val2, val3)
end