lua-users home
lua-l archive

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

> I woud propose something like:
> [...]

ANSI C says that about text files:

  Data read in from a text stream will necessarily compare equal to
  the data that were earlier written out to that stream only if: the
  data consist only of printing characters and the control characters
  horizontal tab and new-line; no new-line character is immediately
  preceded by space characters; and the last character is a new-line

So, there is no garanties that a text file with embedded zeros will be
read correctly, no matter how we implement it.

> One of the strengths of C is the speed at what it can read a char and
> act on it ( or not act ). getc() is normally very fast. lual_addchar
> is very fast, for what I've seen in lualib.h.  The speed loss should
> not be noticeable, and IMO not worrth the extra complexity in the
> current readline function. [...]

Just for the record: In my machine, the following program,

  local count = 0
  for l in io.lines() do
    count = count + #l

reading the Bible, takes ~0.07s with the current implementation and
~0.14s with this proposal.

-- Roberto