lua-users home
lua-l archive

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


Luis Carvalho 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

Binary data published by RSS is literally read using struct and the
result is eg.
http://daedalearth.files.wordpress.com/2010/04/channel_tlt_tb_anom_v03_2_201003.png?w=480&h=360

Apart from plotting, all Lua. Pipe control of gnuplot. Local data in
sqlite3 using lsqlite

Ain't neat, horrible hack but it works. The data for that was FTP
download using luasocket too.