[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.concat and metamethods
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 26 Jul 2012 12:22:33 +0200
I append a patch that makes table.concat respect the __concat
metamethod. It corrects a bug in the version posted on 2012/6/27
and also behaves like Lua always has, rather than how it said in the
manual it does. The difference is significant when a table contains only
one item and that item is not a string, as described below.
2012/6/28 Dirk Laurie <dirk.laurie@gmail.com>:
>
> BTW the manual is not quite correct — that expression reduces to
> table[1] when #table==1, which may be a number, whereas
> table.concat always returns a string. The official Lua source code
> actually evaluates the equivalent of
>
> ""..table[i]..sep..table[i+1] ··· sep..table[j]
>
> by a method applicable only to table entries for which lua_isstring is
> true.
For the combination of this feature with a particular definition of __concat
for strings, see the earlier posts in the thread.
For the license-conscious: this is public-domain code.
Dirk
Attachment:
tconcat.patch
Description: Binary data