lua-users home
lua-l archive

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


in liolib.c line 291 (version 2.1.3)

read_line function

it use "fgets(p, LUAL_BUFFERSIZE, f)" to read the file  (line 297)

but use "l = strlen(p);" to get the length (line 301)

so,for u file,although u read lots of bytes from file(eg n),the strlen will return 3 for your data "FF EE 58 00 30 00...."

and the length of this read will be set 3,so u will get 3 in lua script

but for ther file,the pos goes n bytes,so n-3 bytes lost,and at last u will get only few characters.

maybe it`s a bug of lua?

2008/10/8 Matthew Wild <mwild1@gmail.com>
On Wed, Oct 8, 2008 at 12:30 PM, Brian Sanders <brian.sanders@gmail.com> wrote:
> Hmm... so if it is in either UTF-16 or UCS-2 with BOM... is there any way
> for me to use these log files with a LUA script?  I guess it is good to know
> that I did understand the LUA tutorials, it was my input file I was not
> looking closely enough at.
>

It's a hack, and there is probably a nice(r) way of doing it, but try:

logstring = logstring:sub(3):gsub("%z", "")

It will at least remove the zeros that stop it from printing, but if
you have non-latin characters then they might get messed up.

Matthew.



--
同洲 李辉
Tel:0755-26990000-7741
手机:13631656753