__close must be set on initialization

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

__close must be set on initialization

In one of the last commits:

> To-be-closed variables must be closed on initialization
> When initializing a to-be-closed variable, check whether it has a
> '__close' metamethod (or is a false value) and raise an error if
> if it hasn't. This produces more accurate error messages. (The
> check before closing still need to be done: in the C API, the value
> is not constant; and the object may lose its '__close' metamethod
> during the block.)

- A to-close variable calls the __close methamethod at end of its scope.
- It implies <const>.
- But the metamethod must be present at initialization time.
- And the metamethod must be present at the end of the scope too.
- But they may be different, since you can change it in the block.
- ... ?

There are a bit too many special cases and
exceptions for my taste. I think that (at least) the check on the assignment is an unecessary mental overhead. Unless the
plan is to make metatables of <const> tables unmodifiable... (or to make all the content of a <const> table unmodifieable recursively)

Side node: <toclose> was renamed to <close> (and made postfix). I renew the
proposal to use a less common name. Among those came out in the mailing list I
prefer <bound> or <bind>. I would also add a similar one: <tied>.