lua-users home
lua-l archive

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


Hi,

I just noticed there aren't any functions for reading/writting binary files
in the lua standard library, I would like to suggest the addition of them.
Something like:

fh:readb( "pattern", [num] )
fh:writeb( "pattern", ... )

where pattern would be something like: "ub", "sd", "df" for unsigned byte,
signed dword and double float.

this way it would be really easy to manipulate binary files, for example:

>>
fh = io.open( "test.tga", "rb" )

id_length, colormap_type, image_type = fh:readb( "ub", 3 )
colormap_index, colormap_length = fh:readb( "uw", 2 )
colormap_size = fh:readb( "ub" )
x_origin, y_origin, width, height   = fh:readb( "uw", 4 )
pixel_size, attributes = fh:readb( "ub", 2 )

fh:close()
<<

this code would read the header of a tga file.



Ignacio Castaño
castanyo@yahoo.es

_______________________________________________________________
Copa del Mundo de la FIFA 2002
El único lugar de Internet con vídeos de los 64 partidos. 
¡Apúntante ya! en http://fifaworldcup.yahoo.com/fc/es/