[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: newbie question - strings and arrays
- From: David Given <dg@...>
- Date: Thu, 13 Oct 2005 13:19:49 +0100
On Thursday 13 October 2005 13:04, Jose Marin wrote:
> Thinking on a more esay to use than a fast solution,
> how hard would be to create a "String" class in Lua,
> with the operator [] overloaded?
With Lua 5.1, I believe that the 'string' table is the default metatable for
strings. So:
function string:__index(s, i)
if (type(i) == "number") then
return string.substr(s, i, i)
end
return nil
end
...might do what you want. (Untested. Never used Lua 5.1.)
--
+- David Given --McQ-+ "USER'S MANUAL VERSION 1.0: The information
| dg@cowlark.com | presented in this publication has been carefully
| (dg@tao-group.com) | for reliability." --- anonymous computer hardware
+- www.cowlark.com --+ manual
Attachment:
pgpx0iSRnzNZM.pgp
Description: PGP signature