lua-users home
lua-l archive

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


> TID3 = record
> signature: array[0..2] of char;
> title, artist, album: array[0..29] of char;
> year: array[0..3] of char;
> comment: array[0..29] of char;
> genre: byte;
> end;
> 
> My first difficult is: how to represent a Lua 128 bytes structure like that.
> And how can I read the last 128 bytes of a file and attibutes it to a
> structure, probably a table, with this fields, sized with the given
> values?

function subl(s,i,l) return i+l,s:sub(i,i+l-1) end

f = io.open("foo.mp3","rb")
h = f:read(128)
f:close()
t = {}
i = 1
i,t.signature	= subl(h,i,3)
i,t.title	= subl(h,i,30)
i,t.artist	= subl(h,i,30)
i,t.album	= subl(h,i,30)
i,t.year	= subl(h,i,4)
i,t.comment	= subl(h,i,30)
i,t.genre	= subl(h,i,1)