lua-users home
lua-l archive

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


----- Luis Carvalho <lexcarvalho@gmail.com> wrote:
> > I'm reading some files in an existing binary format, which include 4-byte
> > floating-point numbers. I have the file's contents loaded into a string. I
> > need a function which will parse one floating-point number from the string,
> > given the index of the first byte. Does Lua's library provide this? Or
> > should I throw something together with the bitop library? 
> 
> Take a look at Roberto's struct library,
> 
> http://www.inf.puc-rio.br/~roberto/struct/
> 
> or LHF's lpack,
> 
> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/
> 
> Using the former:
> 
> $ lua -lstruct -e 'print(struct.unpack("f", struct.pack("f", math.pi), 1))'
> 3.1415927410126	5
> 
> Cheers,
> Luis
> 
> -- 
> Computers are useless. They can only give you answers.
>                 -- Pablo Picasso
> 
> -- 
> Luis Carvalho (Kozure)
> lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'

lpack looks perfect, thanks!