lua-users home
lua-l archive

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

>Eg., we can just manually tinsert the strings to a given table, and call a
>function to collate them in a resulting string.

A "concat" function is planned to be added to the standard string library.
It would receive a table and perhaps an optional string separator, to be added
between the strings in the table. Of course, "concat" would be implemented
using lua_concat (which can concat several strings at once), perhaps using
the buffer functions in lauxlib.

>The drawback of this solution is that you can call the collate function with
>any table, including one with tables or functions in it, or hashes, which is
>inappropriate. The behavior in this case is to be defined: either just
>ignore the incorrect entries, or make the function fails and returns nil.

The behavior in this case would be same as in ordinary Lua concat expressions,
ie, tag methods would be called if set.

>Of course, in all cases, the programmer must remember to use these functions
>instead of the more intuitive .. operator. But this is mostly useful in
>loops (so my examples are stupid ;-), so knowing when to use it can be quite

Since 4.0, the .. operator is already quite efficient, in that a..b..c..d..e
is built in a single pass.