lua-users home
lua-l archive

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


On Wed, Dec 16, 2009 at 3:29 PM, Hans Hagen <pragma@wxs.nl> wrote:
> The following is valid lua
>
> a = "text"
> b = a[3]

Yes, given that there is no index operator for strings it seems odd
that we don't get an error. The reason is that strings have a
metatable with __index pointing to the string table; looking up [3] on
s leads to string[3] which gives the nil as you've noticed.

If you're prepared to modify the metatable of all strings, then you
can define a[3] in this case to be a:sub(3,3)

steve d.