lua-users home
lua-l archive

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


On 1 August 2014 10:56, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> On Fri, Aug 1, 2014 at 9:02 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> > n1, n2 = string.scanb(str,"%fb%8l")
> >
> > instead of some code that I am too terrified even to attempt.
>
> +1 for this - more efficient since less Lua->C call overhead for multiple items.
>
> But then, we're getting back to struct:
>
> http://www.inf.puc-rio.br/~roberto/struct/
>
> which does this (and more)

'struct' and 'pack' do this and much more. But they are much bigger than
these four functions, and nevertheless still wanting (e.g., number of
repetitions for an item). So, the idea was to add support for the base
cases; who really needs more should use a library (either implemented in
C or in Lua, on top of these primitives.)

-- Roberto

Thanks for adding this in Roberto.
When writing parsers and serialisers for established binary formats, these functions make it so much easier.
The overhead of going via a struct/pack is undesirable; however the previous alternative was writing the functions via math operations.