[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __index returns truncated to one, why?
- From: Peng Zhicheng <pengzhicheng1986@...>
- Date: Sun, 13 Apr 2014 11:22:02 +0800
On 04/12/2014 05:07 PM, duz wrote:
On 12.04.2014 10:10, Dirk Laurie wrote:
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.
This does not apply to userdata, which is what I use.
I use metatables mostly like this:
Step 1: Do some useful stuff in c/c++.
Step 2: Represent it in Lua via Userdata+Metamethods.
Step 3: Use it in fairly small scripts.
If matters get too complex, go back to 1.
I always need __index.
Artificially limiting its capabilities is wrong. For me.
I do bindings too.
in case my binded userdata is some kind of container type, like vector, hashtable,
associative array, or even list when needed, then the current semantic of
__index metamethod is _right_ for me.
if the userdata is not container like but object like, I would merely use the __index
metamethod to retrieve data fields and class methods for that object. and it
is still _right_.
I don't see any limitations here,
maybe you have other use cases which I didn't see.
This sounds like you've been carried away and hit your head
trying all sorts of strange things that would never occur to me.