[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 11:01:55 -0700
On Wed, Jun 21, 2006 at 01:45:38PM -0400, Diego Nehab wrote:
> >>= s["len"]
> >function: 0x806be90
> >>= string.len
> >function: 0x806be90
>
> So you can call "foo":len() and get string.len("foo")...
Ok, I think I start to see. So unwrapping the layers of syntactic pastry:
"foo":len()
is
"foo".len("foo")
is
"foo"["len"]("foo")
is
getmetatable("foo")["__index"]["len"]("foo")
Wouldn't it be useful to do for numbers, too?
> = math.floor(1.1)
1
> n = 1.1
> n:floor()
stdin:1: attempt to index global 'n' (a number value)
> v = { __index = math }
> setmetatable(n, v)
stdin:1: bad argument #1 to 'setmetatable' (table expected, got number)
getmetatable() works on any object, but setmetatable() only works on
tables?
Sam
- References:
- 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
- Re: string[], doesn't exist?, Sam Roberts
- Re: string[], doesn't exist?, Diego Nehab