lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rici Lake wrote:

> In any event, there are few use cases for finding the argument count which
> do not involve iterating over the arguments; I would far rather have:
>
>   for i, arg in ieach(...) do process(arg) end

Hmm, could not be written with the ... operator but a table (classic
'arg' style) must be created:


  function ieach(...)
    local function f(arg, index)
      if index < arg.n then
        index = index + 1
        return index, arg[index]
      end
    end
    return f, arg, 0
  end


The above code should work with both 5.0.2 and 5.1-alpha.


cu

Michael
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDKfyaSIrOxc3jOmoRAn+UAJ9lD5Q8g0tMuY8HfiuBJq1Zmxe7EwCgoJ8L
IuK+HS0qI/uYxc6mmAX4AcA=
=bJeV
-----END PGP SIGNATURE-----