diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-31 10:43:51 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-31 10:43:51 -0300 |
commit | f645d3157372c73573dff221c5b26691cb0e7d56 (patch) | |
tree | 61adb1f332bbd8c0c0365b81cef8de47fa2ea06a /manual | |
parent | 35b4efc270db2418bc2cac6671575a45028061c3 (diff) | |
download | lua-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.of | 19 |
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 | ||
1535 | Here, to @emph{close} a value means | 1535 | Here, to @emph{close} a value means |
1536 | to call its @idx{__close} metamethod. | 1536 | to call its @idx{__close} metamethod. |
1537 | If the value is @nil, it is ignored; | ||
1538 | otherwise, | ||
1539 | if it does not have a @idx{__close} metamethod, | ||
1540 | an error is raised. | ||
1541 | When calling the metamethod, | 1537 | When calling the metamethod, |
1542 | the value itself is passed as the first argument | 1538 | the value itself is passed as the first argument |
1543 | and the error object (if any) is passed as a second argument; | 1539 | and the error object that caused the exit (if any) |
1540 | is passed as a second argument; | ||
1544 | if there was no error, the second argument is @nil. | 1541 | if there was no error, the second argument is @nil. |
1545 | 1542 | ||
1543 | The value assigned to a to-be-closed variable | ||
1544 | must have a @idx{__close} metamethod | ||
1545 | or be a false value. | ||
1546 | (@nil and @false are ignored as to-be-closed values.) | ||
1547 | |||
1546 | If several to-be-closed variables go out of scope at the same event, | 1548 | If several to-be-closed variables go out of scope at the same event, |
1547 | they are closed in the reverse order that they were declared. | 1549 | they 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 | ||
2920 | Destroys all objects in the given Lua state | 2922 | Close all active to-be-closed variables in the main thread, |
2921 | (calling the corresponding garbage-collection metamethods, if any) | 2923 | release all objects in the given Lua state |
2924 | (calling the corresponding garbage-collection metamethods, if any), | ||
2922 | and frees all dynamic memory used by this state. | 2925 | and frees all dynamic memory used by this state. |
2923 | 2926 | ||
2924 | On several platforms, you may not need to call this function, | 2927 | 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 | |||
4186 | by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}. | 4189 | by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}. |
4187 | 4190 | ||
4188 | This function should not be called for an index | 4191 | This function should not be called for an index |
4189 | that is equal to or below an already marked to-be-closed index. | 4192 | that is equal to or below an active to-be-closed index. |
4190 | 4193 | ||
4191 | This function can raise an out-of-memory error. | 4194 | This function can raise an out-of-memory error. |
4192 | In that case, the value in the given index is immediately closed, | 4195 | In that case, the value in the given index is immediately closed, |