[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New metamethod for method lookup
- From: "Alex Davies" <alex.mania@...>
- Date: Mon, 16 Nov 2009 07:54:54 +0800
One issue I have with the idea is there is no one way to index in Lua.
Sometimes, even for function calls, you have to index from a variable in a
string []. Other times the method : call is fine. Sometimes you just want
to pass a different self, so . is applicable. So for this to work you'd
need to add a "getmethod(table, key)" function, which is a bit tacky imo,
but would work.
Mark Hamburg wrote:
* It simplifies the implementation of objects with both methods and
properties allowing method lookup > to bypass a function call. (There was
an alternate proposal a while back, I believe to allow a metatable > entry
that had to be a table and a fallback function beyond that.)
The proposal was to have a __proxy field in the metatable - on a nil result,
the index is tried again in the __proxy value (usually a table). If that
fails, the __index is called. This is an improvement in a number of ways.
1) As above, it simplifies objects with properties so that a function call
isn't required to resolve methods.
2) __index is always treated like a function, improving virtualization. No
"call it - unless it's a table in which case we'll index it" special
treatment, allowing func tables (memoized functions, class constructors,
etc) to be used as index functions.
3) Fully encompasses the existing system, so the existing behaviour can be
replicated.
Simple change to the VM too ;)
- Alex