lua-users home
lua-l archive

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


The colon only refers to function calls, not the indexing operation.
It inserts the table on which it is called as first argument to the
function.

"a.call(a)" is equivalent to "a:call()".
If you would make a difference of it in the indexing operation, this
equivalence cannot be guaranteed, and from what I know its not possible.

----- Original Message ----- 
From: "Ando Sonenblick" <ando@spritec.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Sunday, August 24, 2003 9:47 PM
Subject: __index : vs . Discrimination?


> Gang, consider this:
>
> "p = {}
> t = {
>      __index = function(table, key) print("index") end
>     }
>
> setmetatable(p, t)"
>
> Now, when I execute these two following lines of lua code:
>
> "q = p.x
> p:fn()"
>
> ...both end up going through __index in an attempt to look up x and fn in
p,
> respectively.
>
> I've been trying everything, but haven't figured out a way (if it's
possible
> at all) to distinguish inside my __index function whether it is being
called
> via a . (dot) operator or a : (colon) operator.
>
> Is this possible?
>
> Thx,
> Ando
>