[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Analog struct.size in Lua 5.3 string library.
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 29 Nov 2014 10:51:48 -0200
> > Can't you use #string.pack(fmt, ...), with specific dummy arguments?
>
> 0 works everywhere except c[n], which needs the exact length to match.
>
> But "hard to implement in Lua" is fair also for the dummy argument
> approach. You need to be able to generate a list `0,0,0,0,...` of at least
> the right length, punctuated by the occasional string.rep(' ',n). This
> amounts to parsing `fmt` in Lua.
I was not proposing a "generic" implementation for pack size, just a
simple way to compute the size of a supposely known format. (Anyway,
even the offical size function from the struct library does not work for
all formats...)
-- Roberto