aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-01-04 13:09:47 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-01-04 13:09:47 -0200
commit4ace93ca6502dd1da38d5c06fa099d229e791ba8 (patch)
tree34f95ef56aecb56ae1db5e8b843b6e9bd2cbae51 /manual
parentc6f7181e910b6b2ff1346b5486a31be87b1da5af (diff)
downloadlua-4ace93ca6502dd1da38d5c06fa099d229e791ba8.tar.gz
lua-4ace93ca6502dd1da38d5c06fa099d229e791ba8.tar.bz2
lua-4ace93ca6502dd1da38d5c06fa099d229e791ba8.zip
No more to-be-closed functions
To-be-closed variables must contain objects with '__toclose' metamethods (or nil). Functions were removed for several reasons: * Functions interact badly with sandboxes. If a sandbox raises an error to interrupt a script, a to-be-closed function still can hijack control and continue running arbitrary sandboxed code. * Functions interact badly with coroutines. If a coroutine yields and is never resumed again, its to-be-closed functions will never run. To-be-closed objects, on the other hand, will still be closed, provided they have appropriate finalizers. * If you really need a function, it is easy to create a dummy object to run that function in its '__toclose' metamethod. This comit also adds closing of variables in case of panic.
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of34
1 files changed, 14 insertions, 20 deletions
diff --git a/manual/manual.of b/manual/manual.of
index d64f0f1a..b9ab1ebe 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -1536,33 +1536,29 @@ goes out of scope, including normal block termination,
1536exiting its block by @Rw{break}/@Rw{goto}/@Rw{return}, 1536exiting its block by @Rw{break}/@Rw{goto}/@Rw{return},
1537or exiting by an error. 1537or exiting by an error.
1538 1538
1539To \emph{close} a value has the following meaning here: 1539Here, to \emph{close} a value means
1540If the value of the variable when it goes out of scope is a function, 1540to call its @idx{__close} metamethod.
1541that function is called; 1541If the value is @nil, it is ignored;
1542otherwise, if the value has a @idx{__close} metamethod, 1542otherwise,
1543that metamethod is called; 1543if it does not have a @idx{__close} metamethod,
1544otherwise, if the value is @nil, nothing is done; 1544an error is raised.
1545otherwise, an error is raised. 1545When calling the metamethod,
1546In the function case, 1546the value itself is passed as the first argument
1547if the scope is being closed by an error, 1547and the error object (if any) is passed as a second argument;
1548the error object is passed as an argument to the function; 1548if there was no error, the second argument is @nil.
1549if there is no error, the function gets @nil.
1550In the metamethod case,
1551the value itself always is passed as an argument to the metamethod.
1552 1549
1553If several to-be-closed variables go out of scope at the same event, 1550If several to-be-closed variables go out of scope at the same event,
1554they are closed in the reverse order that they were declared. 1551they are closed in the reverse order that they were declared.
1555If there is any error while running a closing function, 1552If there is any error while running a closing method,
1556that error is handled like an error in the regular code 1553that error is handled like an error in the regular code
1557where the variable was defined; 1554where the variable was defined;
1558in particular, 1555in particular,
1559the other pending closing functions will still be called. 1556the other pending closing methods will still be called.
1560 1557
1561If a coroutine yields inside a block and is never resumed again, 1558If a coroutine yields inside a block and is never resumed again,
1562the variables visible at that block will never go out of scope, 1559the variables visible at that block will never go out of scope,
1563and therefore they will not be closed. 1560and therefore they will not be closed.
1564Similarly, if a script is interrupted by an unprotected error, 1561(You should use finalizers to handle this case.)
1565its to-be-closed variables will not be closed.
1566 1562
1567} 1563}
1568 1564
@@ -3002,7 +2998,7 @@ and therefore never returns
3002} 2998}
3003 2999
3004@APIEntry{int lua_gc (lua_State *L, int what, int data);| 3000@APIEntry{int lua_gc (lua_State *L, int what, int data);|
3005@apii{0,0,v} 3001@apii{0,0,-}
3006 3002
3007Controls the garbage collector. 3003Controls the garbage collector.
3008 3004
@@ -3056,8 +3052,6 @@ returns a boolean that tells whether the collector is running
3056For more details about these options, 3052For more details about these options,
3057see @Lid{collectgarbage}. 3053see @Lid{collectgarbage}.
3058 3054
3059This function may raise errors when calling finalizers.
3060
3061} 3055}
3062 3056
3063@APIEntry{lua_Alloc lua_getallocf (lua_State *L, void **ud);| 3057@APIEntry{lua_Alloc lua_getallocf (lua_State *L, void **ud);|