[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What's up with token filters (Re: New operators?)
- From: Rici Lake <lua@...>
- Date: Fri, 13 Apr 2007 10:08:27 -0500
Olivier Delannoy wrote:
Why : is more complex than it appears ?
a.truc(a, something) is strictly equivalent to a:truc(something)
Strictly speaking, a:truc(something) is equivalent to (in
pseudo-code since you can't write this in Lua):
{ local <gensym:1> = a; <gensym:1>["truc"](<gensym:1>, something) }
To see the difference, try this:
do local registry, i = {}, 0
setfenv(0, setmetatable(getfenv(), {
__index = function(self, key)
local i = (registry[key] or 0) + 1
registry[key] = i
return {
n = i,
truc = function(self, ...)
print(("%q %d truc%s")
:format(key, i, i == 1 and "" or "s"),
("%q %d truc%s")
:format(key, self.n, self.n == 1 and "" or "s"),
...
)
end
}
end
}))
end
a.truc(a, "hello"); a.truc(a, "world")
b:truc"hello"; b:truc"world"
- References:
- RE: New operators?, Jerome Vuarand
- Re: New operators?, Glenn Maynard
- What's up with token filters (Re: New operators?), Asko Kauppi
- Re: What's up with token filters (Re: New operators?), Glenn Maynard
- Re: What's up with token filters (Re: New operators?), David Given
- Re: What's up with token filters (Re: New operators?), Glenn Maynard
- Re: What's up with token filters (Re: New operators?), Daniel Silverstone
- Re: What's up with token filters (Re: New operators?), Greg Falcon
- Re: What's up with token filters (Re: New operators?), Olivier Delannoy
- Re: What's up with token filters (Re: New operators?), Olivier Galibert
- Re: What's up with token filters (Re: New operators?), Olivier Delannoy