From f645d3157372c73573dff221c5b26691cb0e7d56 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 31 Jul 2019 10:43:51 -0300 Subject: 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.) --- manual/manual.of | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'manual') diff --git a/manual/manual.of b/manual/manual.of index 1646f113..8eebe9cb 100644 --- a/manual/manual.of +++ b/manual/manual.of @@ -1534,15 +1534,17 @@ or exiting by an error. Here, to @emph{close} a value means to call its @idx{__close} metamethod. -If the value is @nil, it is ignored; -otherwise, -if it does not have a @idx{__close} metamethod, -an error is raised. When calling the metamethod, the value itself is passed as the first argument -and the error object (if any) is passed as a second argument; +and the error object that caused the exit (if any) +is passed as a second argument; if there was no error, the second argument is @nil. +The value assigned to a to-be-closed variable +must have a @idx{__close} metamethod +or be a false value. +(@nil and @false are ignored as to-be-closed values.) + If several to-be-closed variables go out of scope at the same event, they are closed in the reverse order that they were declared. @@ -2917,8 +2919,9 @@ it is left unchanged. @APIEntry{void lua_close (lua_State *L);| @apii{0,0,-} -Destroys all objects in the given Lua state -(calling the corresponding garbage-collection metamethods, if any) +Close all active to-be-closed variables in the main thread, +release all objects in the given Lua state +(calling the corresponding garbage-collection metamethods, if any), and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, @@ -4186,7 +4189,7 @@ An index marked as to-be-closed should not be removed from the stack by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}. This function should not be called for an index -that is equal to or below an already marked to-be-closed index. +that is equal to or below an active to-be-closed index. This function can raise an out-of-memory error. In that case, the value in the given index is immediately closed, -- cgit v1.2.3-55-g6feb