lua-users home
lua-l archive

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


On Feb 22, 2014, at 19:47 , Francisco Olarte wrote:


On Fri, Feb 21, 2014 at 11:59 PM, Sean Conner <> wrote:
 I think it's more an investigation of "how do other languages handle
this?" than trying to look for worse.
 C, using fgets(), would print:
 but only because of the way C treats NUL in strings.

At least C would get the line count half right, but:

folarte@paqueton:~/tmp$ cat lines.lua
for line in io.input():lines('*L') do
   print(string.format("%d: '%s'",n,line))
folarte@paqueton:~/tmp$ (for a in  1 2 3  ; do echo -ne
"hello\0world\n" ; done) | lua lines.lua
1: 'hellohellohello'

Btw, beating the unfortunate dead horse even more: this is a nice
additional catch: which I may consider as a real real bug. Lua should
really output 3 lines, like in the "trivial" C example.

While working on the source I already had the "feeling" the function
should only continue reading on a full buffer, not using the current
"if last char is not \n" check, but could not imagine a case it fails.
Thank you for this example!

(I wish we could just simple fix this 2 bugs, … :-/)

 ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin | | | |