lua-users home
lua-l archive

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


> It could be an interesting addition to have a capture system in the struct pack/unpack functions, similar to captures in the pattern matching functions.
> If one wants to read a C structure, but only needs some values from the structure. Sure, you can:
>   - read all the data structure and get the values you need from the return values, but so you have to deal with potentially a lot of return values or create a temporary table.
>   - look for the offset of the values you want to read, and read one by one, but it is more work and you have to deal with data size and alignement in computing the offset.
> And it is clean.
> Actually I don't see a need for that from my side now, but it seems easy to implement (at first sight, I am not a professional of programming and have not tried), fits naturally with the mechanism and it is easy to find some applications.
> What do you think about this?

It seems too complex for little gain. I do not think it is too dificult
to compute offsets when needed (you can use 'pack' itself to do the
hard work, including alignments) or simply ignore the extra results.
(BTW, Wireshark already implements that, but in reverse (things inside
parentheses are skipped), which hints that the meaning of such
construction is not very intuitive...)

-- Roberto