[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Guessing the expected result type from an __index function
- From: Philipp Janda <siffiejoe@...>
- Date: Mon, 13 May 2013 11:38:01 +0200
Am 13.05.2013 11:01 schröbte Jean-Luc Jumpertz:
Le 13 mai 2013 à 09:38, Jerome Vuarand <firstname.lastname@example.org> 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, so it's not entirely
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
local v = matrix[ 1, 2 ]