[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: String indexing again
- From: steve donovan <steve.j.donovan@...>
- Date: Mon, 20 Dec 2010 10:44:04 +0200
On Mon, Dec 20, 2010 at 10:01 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> I suppose that is the portable way. OK, I'll shut up on this topic
> now.
As a last gasp, it's not difficult to write a custom type that does
provide index access to string 'characters' (modulo UTF-8 etc [1])
http://gist.github.com/748160
You use it like this:
sa = StringAccessor 'hello'
for c in sa:iter() do -- (see [2])
print(c)
end
print(sa[1],sa[3])
print('end',sa[-1])
steve d.
[1] This kind of pattern would be useful for wrapping strings so that
one could properly extract non-ASCII characters....
[2] With Lua 5.2, ipairs can be overriden as well, making string
accessors more 'table-like'