lua-users home
lua-l archive

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

2013/7/16 Robert Virding <>:
> While operators for bit-fields are very useful I think a better way is a syntax which allows you describe/build the whole bitstring in one go. We have this in Erlang and it makes building/pulling apart protocol packets very much easier and clearer. Some simple examples of the top of my head:
> 64-bit IEEE floating point:
> <<Sign:1,Exponent:11,Mantissa:52>>
> IP datagram:
> <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16,
>       ID:16, Flgs:3, FragOff:13,
>       TTL:8, Proto:8, HdrChkSum:16,
>       SrcIP:32, DestIP:32, RestDgram/binary>>
> The second one is a bit longer than 32 bits. :-) I think you get the idea. We can also use the same syntax for pulling apart the binary/bitstring. This really is powerful and simplifies a lot of things and I think that something similar would be useful for Lua if you seriously intend to work with bitfields.

There are already plenty of libraries that simplify parsing such
binary structures, some using the Lua flexible syntax as a kind of DSL
to describe them. I don't see how another set of syntactic constructs
could make it any easier or clearer. Can you elaborate on that claim?