lua-users home
lua-l archive

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


> 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