Re: __len vs __index
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: __len vs __index
- From: "Soni L." <fakedme@...>
- Date: 2016年8月25日 06:07:41 -0300
On 25/08/16 01:56 AM, Dirk Laurie wrote:
2016年08月25日 0:16 GMT+02:00 Soni L. <fakedme@gmail.com>:
Why doesn't # respect __index? Is it because the behaviour of # is
implementation-defined and thus it shouldn't leak through __index?
Would it be a big deal for # to leak through __index?
Can we have both __index-friendly # and __len override?
Consider the following code:
; a = setmetatable({1,2,3},{__index = function() return 0/0 end})
; print(#a)
3
What should an index-friendly # return instead?
Never.
That is, it should never return.
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.