[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __close: presence and time of evaluation
- From: Xavier Wang <weasley.wx@...>
- Date: Thu, 10 Oct 2019 01:22:20 +0800
Roberto Ierusalimschy <roberto@inf.puc-rio.br> 于2019年10月7日周一 下午10:28写道:
>
> > Regardless, the current behavior with respect to the presence and time of
> > evaluation of __close seems unnecessarily complicated. Can you explain what
> > is gained by having to check the validity of __close twice? [...]
>
> In our (short) experience, the check in the initialization detects
> several mistakes in the code and gives clearer error messages.
>
> -- Roberto
>
After a simple try it seems that when __close changed to nil, the
runtime error still has good information:
> local a <close> = setmetatable({}, {__close = true}); getmetatable(a).__close = nil
stdin:1: attempt to close non-closable variable 'a'
stack traceback:
stdin:1: in main chunk
[C]: in ?
But if remaining __close as boolean, the error message looks messy:
> local a <close> = setmetatable({}, {__close = true})
stdin:1: attempt to call a boolean value
stack traceback:
stdin:1: in main chunk
[C]: in ?
Is there any reasons for not mention the name of to-be-closed variable
when the __close metamethod is not callable?
--
regards,
Xavier Wang.