lua-users home
lua-l archive

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


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 = "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 )


this code would read the header of a tga file.

Ignacio Castaño

Copa del Mundo de la FIFA 2002
El único lugar de Internet con vídeos de los 64 partidos. 
¡Apúntante ya! en