lua-users home
lua-l archive

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


On Sat, Mar 22, 2014 at 11:49 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> string.format uses a little language for constructing strings out of
>> numbers and other strings, primarily in variable-length decimal encoding. I
>> think a very similar language could be designed for constructing strings
>> out of numbers and other strings in the domain of fixed-size binary
>> encoding.
>>
>> Aside from symmetry, my motivation is premature optimization. string.pack
>> written in Lua would have the same problems as string.format written in
>> Lua: as formatting is executed, short strings will be created, pushed on a
>> Lua-side concat table, then turned into garbage. Easier and faster to do
>> this at the C level where string building is cheaper.
>
> You still can use external libraries for that (e.g., struct and lpack).
> We thought that this basic functionallity was a good trade-off beween
> usefuleness and simplicity for the standard library. (Thanks to
> Daurnimator for the suggestion.)
>
> -- Roberto
>

This is sort of the reason why I wish Lua's core had a library
specifically for buffers, something where you can create userdata
buffers and fill it with lua values rawly, and then convert it into a
immutable, pooled Lua string if you wish.  (I know there are modules
for this, I just wish there were a core facility for doing so -- but
you could also just make bindings to the Lua C API and then write a
module over that.  I'm not sure which path I like more.)