[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.concat - why so complex?
- From: Peter Cawley <lua@...>
- Date: Tue, 6 Apr 2010 15:49:35 +0100
On Tue, Apr 6, 2010 at 3:33 PM, Alex Davies <alex.mania@iinet.net.au> wrote:
>> My naive solution would be simple: Iterate over the array, add the string
>> length of its members, add the required storage for any supplied
>> separator,
>> allocate the target string to the right, and memcpy() the array members
>> (and
>> any separators) over to their final location.
>
> Whilst simple, it falls down when presented with __concat metamethods or
> numbers.
As table.concat does not accept things with __concat metamethods, they
do not need to be considered. Likewise, numbers need no special
treatment as lua_isstring / lua_tolstring automatically convert
numbers to strings.