|
Am 13.05.2013 11:01 schröbte Jean-Luc Jumpertz:
Le 13 mai 2013 à 09:38, Jerome Vuarand <jerome.vuarand@gmail.com> a écrit :You don't always know at index time how the returned value will be used. Consider for example: local obj = get_one_of_your_objects() local save = obj.save [...] With your hack, it's no longer possible to call the method in that way (which I admit is very unusual).I am aware of this theoretical case. But it doesn't make much sense in general in an object-oriented code to extract a method function at some point and apply it later to an arbitrary object. And this is even more true when it concerns a bridge to an external compiled language. So I really don't consider this as an issue.
I've used something like this before[1][2], so it's not entirely theoretical.
[1]: http://lua-users.org/lists/lua-l/2010-02/msg00570.html[2]: https://github.com/siffiejoe/lua-prototype/blob/master/src/prototype.lua#L100
First-class functions are not nearly as useful if you can't get at the function values ...
And it would be much better if some type of hint about the foreseeable usage of a field could be passed as an extra parameter to the index metamethod in a future version of Lua. This would allow the index metamethod to return different (but related) data for a same key depending of the field expected usage.
I'd rather see extra parameters to the __index metamethod for the following case:
local v = matrix[ 1, 2 ] Philipp