lua-users home
lua-l archive

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


Hi,

Think about reading a line pattern in non-blocking mode,
i.e., with 0 timeout. You don't know if the line will come
in one function call or if it will be split into several
function calls. You don't know if it will fit in the buffer
or not, so you can't accumulate it there. So passing the
partial result from the previous call into the next call
makes sure that when the call finally succeeds, you have
your entire line in one place. I think it is pretty
convenient. If there is a bug on this idea, let me know and
I will fix it.

Ah, no, that makes a lot of sense to be able to avoid string
concatenation overhead.

The concatenation overhead is still there, and the worst
case will be quadratic on the size of the string. The
overhead we are avoiding here is syntatic. This is very
convenient for small lines, which are not a big concern.
For potentially large "*a" or <n> patterns, I would not
recommend it.  Just insert everything into a table and call
table.concat later.

Regards,
Diego