[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.concat - why so complex?
- From: Gavin Wraith <gavin@...>
- Date: Tue, 06 Apr 2010 13:52:44 +0100
In message <5EC08AEC9A25D746ABB7341DCE1E7A6090B2A2@mx.ellipsbv.local> you 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.
You are presuming that Lua strings are stored in arrays, as a consecutive
sequence of bytes, as in C. They are not. The reason why is very
interesting, but I leave to those who are more expert to explain.
Both methods of storage have their own advantages and disadvantages,
but the tradeoff chosen for Lua is an important aspect of what makes
Lua Lua, I believe. You cannot talk of the "location" of a Lua string
in the same way that you can for C.
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/