Re: __index returns truncated to one, why?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: __index returns truncated to one, why?
- From: Dirk Laurie <dirk.laurie@...>
- Date: 2014年4月12日 10:10:06 +0200
2014年04月12日 5:02 GMT+02:00 Peng Zhicheng <pengzhicheng1986@gmail.com>:
> the `metamethod' mechanism in Lua is FALLBACK, not OVERRIDE.
> the __index metamethod is fallback for non-existance keys.
...
> metamethods are not C++'s overloaded.operators.
This can't be stressed often enough. It is often misunderstood by
newbies. I can remember how long it took me to grok this. Not
only table indexing, also the "clever" things you can do with
debug.setmetatable, e.g. __concat for numbers (metamethod
not called because they are coerced to strings), __add for strings
(metamethod called only when they can't be coerced to numbers).
Maybe we should acquire the habit of changing the name when doing
the local caching.
local setfallback = setmetamethod