[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string[], doesn't exist?
- From: Sam Roberts <sroberts@...>
- Date: Wed, 21 Jun 2006 10:42:49 -0700
On Wed, Jun 21, 2006 at 01:37:01PM -0300, Luiz Henrique de Figueiredo wrote:
> > why does [] not apply to strings?
>
> It does, but it does not do what you want. But try this:
Thanks, that works as I hoped [] might, and is very educational.
It still leaves my wondering _why_, since indexing a string by a number
seems to effectively do nothing. Is the desire to do this considered to
be an end-user decision, when building their lua application?
> s="lua"
> print(s[2])
--> nil
What does it do? Playing around, it looks like I can do
> = s["len"]
function: 0x806be90
> = string.len
function: 0x806be90
So, it looks like
getmetatable("").__index == string
for strings, but is nil for other builtins:
> = getmetatable(5)
nil
> = getmetatable{}
nil
> = getmetatable(io.input())
table: 0x806aae0
> = io
table: 0x806ad78
>
Its not clear to me what the function of this is, why this is useful.
Thanks for your patience,
Sam
- References:
- Bitwsie operators in Lua, mike krimerman
- Re: Bitwsie operators in Lua, Gavin Wraith
- Re: Bitwsie operators in Lua, Sam Roberts
- Re: Bitwsie operators in Lua, Andy Stark
- Re: Bitwsie operators in Lua, Doug Rogers
- Re: Bitwsie operators in Lua, Andy Stark
- Re: Bitwsie operators in Lua, Roberto Ierusalimschy
- string[], doesn't exist?, Sam Roberts
- Re: string[], doesn't exist?, Luiz Henrique de Figueiredo