lua-users home
lua-l archive

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

> but is there a simpler way than this to read the lines from a file:
> [...]

I think a good solution would be something like

  function lines (filename)
    local f = assert(, "r"))
    return function ()
      return f:read() or (assert(f:close()) and nil)

so that we could use it without any other "preparation":

  for line in lines(file) do ... end

But I'm not sure whether such function belongs to the `io' lib or to
some extension library.

-- Roberto