-- @runtimes lua54 luajit --- 演示:无状态迭代器返回三个值:函数、状态、控制变量。 local M = {} local function iter(state, control) control = control + 1 if control > state then return nil end return control, control * control end --- @return table { values = table } function M.run(log) log = log or print local values = {} for i, square in iter, 3, 0 do values[#values + 1] = { i, square } end log(("count=%d last=%d"):format(#values, values[#values][2])) return { values = values } end if not ... then M.run() end return M