aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-31 10:43:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-31 10:43:51 -0300
commitf645d3157372c73573dff221c5b26691cb0e7d56 (patch)
tree61adb1f332bbd8c0c0365b81cef8de47fa2ea06a /manual
parent35b4efc270db2418bc2cac6671575a45028061c3 (diff)
downloadlua-f645d3157372c73573dff221c5b26691cb0e7d56.tar.gz
lua-f645d3157372c73573dff221c5b26691cb0e7d56.tar.bz2
lua-f645d3157372c73573dff221c5b26691cb0e7d56.zip
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.)
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of19
1 files changed, 11 insertions, 8 deletions
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.
1534 1534
1535Here, to @emph{close} a value means 1535Here, to @emph{close} a value means
1536to call its @idx{__close} metamethod. 1536to call its @idx{__close} metamethod.
1537If the value is @nil, it is ignored;
1538otherwise,
1539if it does not have a @idx{__close} metamethod,
1540an error is raised.
1541When calling the metamethod, 1537When calling the metamethod,
1542the value itself is passed as the first argument 1538the value itself is passed as the first argument
1543and the error object (if any) is passed as a second argument; 1539and the error object that caused the exit (if any)
1540is passed as a second argument;
1544if there was no error, the second argument is @nil. 1541if there was no error, the second argument is @nil.
1545 1542
1543The value assigned to a to-be-closed variable
1544must have a @idx{__close} metamethod
1545or be a false value.
1546(@nil and @false are ignored as to-be-closed values.)
1547
1546If several to-be-closed variables go out of scope at the same event, 1548If several to-be-closed variables go out of scope at the same event,
1547they are closed in the reverse order that they were declared. 1549they are closed in the reverse order that they were declared.
1548 1550
@@ -2917,8 +2919,9 @@ it is left unchanged.
2917@APIEntry{void lua_close (lua_State *L);| 2919@APIEntry{void lua_close (lua_State *L);|
2918@apii{0,0,-} 2920@apii{0,0,-}
2919 2921
2920Destroys all objects in the given Lua state 2922Close all active to-be-closed variables in the main thread,
2921(calling the corresponding garbage-collection metamethods, if any) 2923release all objects in the given Lua state
2924(calling the corresponding garbage-collection metamethods, if any),
2922and frees all dynamic memory used by this state. 2925and frees all dynamic memory used by this state.
2923 2926
2924On several platforms, you may not need to call this function, 2927On 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
4186by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}. 4189by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}.
4187 4190
4188This function should not be called for an index 4191This function should not be called for an index
4189that is equal to or below an already marked to-be-closed index. 4192that is equal to or below an active to-be-closed index.
4190 4193
4191This function can raise an out-of-memory error. 4194This function can raise an out-of-memory error.
4192In that case, the value in the given index is immediately closed, 4195In that case, the value in the given index is immediately closed,