lua-users home
lua-l archive

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

I agree with your point on Lua's string.{un,}pack not being too readable. However, I feel that your implementation leads to too many function calls. I'd much prefer (and, in FusionScript, plan to utilize) a function that generates a format string and returns a pack() and unpack() function or object to use that string.

On Fri, May 26, 2017, 16:14 François Perrad <> wrote:

2017-05-26 21:03 GMT+02:00 Aaron B. <>:
On Fri, 26 May 2017 17:32:49 +0200
François Perrad <> wrote:

>     printf("x = %d  y = %d", 10, 20);                           -- C
>     string.format("x = %d  y = %d", 10, 20)                     -- Lua 5.0
>     ("x = %d  y = %d"):format(10, 20)                           -- Lua 5.1
>     cout << "x = " << 10 << "  y = " << 20;                     -- C++
>     string.buffer():put'x = ':put(10):put'  y = ':put(20)       -- proposal

The C/Lua 5.0/Lua 5.1 way looks a lot more readable to me, compared to
the C++/proposal method.

The reason being, with the format string, in a glance I can see what
the output will look like. With the stream, I have to put all the pieces
together in my mind first.

Aaron B. <>

Well, at this time, the feedbacks seem clear : everybody is happy with minilanguages.

As seasoned C developer, I know (and I daily use) the `sprintf` formating, so I am biased.
But the pack/unpack minilanguage is not obviously readable.
And same thing with `` which uses the C `strftime` minilanguage.

An implementation based on a minilanguage doesn't allow user extension, for example, you cannot add a "%Q" option to `string.format` in pure Lua.


Ryan <>
Software Developer / System Administrator