lua-users home
lua-l archive

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


Hi,

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

Hi:

On Fri, Feb 21, 2014 at 11:59 PM, Sean Conner <sean@conman.org> 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:
hellohellohellohellohello
 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
n=1;
for line in io.input():lines('*L') do
   print(string.format("%d: '%s'",n,line))
   n=n+1
end
folarte@paqueton:~/tmp$ (for a in  1 2 3  ; do echo -ne
"hello\0world\n" ; done) | lua lines.lua
1: 'hellohellohello'
folarte@paqueton:~/tmp$


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
 http://exactcode.com | http://exactscan.com | http://ocrkit.com | http://t2-project.org | http://rene.rebe.de