diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-05-08 17:50:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-05-08 17:50:10 -0300 |
commit | 262dc5729a28b2bad0b6413d4eab2290d14395cf (patch) | |
tree | c92cbf6c6d5d88bc352dd71f7f27be4dd44cf16f /manual | |
parent | 9d985db7bb09c92b5b3fa660fffe5907d01e6a02 (diff) | |
download | lua-262dc5729a28b2bad0b6413d4eab2290d14395cf.tar.gz lua-262dc5729a28b2bad0b6413d4eab2290d14395cf.tar.bz2 lua-262dc5729a28b2bad0b6413d4eab2290d14395cf.zip |
Details
Corrections in comments and manual. Added note in the manual about
local variables in the REPL.
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/manual/manual.of b/manual/manual.of index 7df32fcf..5aea2623 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -289,7 +289,7 @@ Whenever there is an error, | |||
289 | an @def{error object} | 289 | an @def{error object} |
290 | is propagated with information about the error. | 290 | is propagated with information about the error. |
291 | Lua itself only generates errors whose error object is a string, | 291 | Lua itself only generates errors whose error object is a string, |
292 | but programs may generate errors with | 292 | but programs can generate errors with |
293 | any value as the error object. | 293 | any value as the error object. |
294 | It is up to the Lua program or its host to handle such error objects. | 294 | It is up to the Lua program or its host to handle such error objects. |
295 | For historical reasons, | 295 | For historical reasons, |
@@ -298,7 +298,7 @@ even though it does not have to be a string. | |||
298 | 298 | ||
299 | 299 | ||
300 | When you use @Lid{xpcall} (or @Lid{lua_pcall}, in C) | 300 | When you use @Lid{xpcall} (or @Lid{lua_pcall}, in C) |
301 | you may give a @def{message handler} | 301 | you can give a @def{message handler} |
302 | to be called in case of errors. | 302 | to be called in case of errors. |
303 | This function is called with the original error object | 303 | This function is called with the original error object |
304 | and returns a new error object. | 304 | and returns a new error object. |
@@ -343,7 +343,7 @@ which is then called a @def{metamethod}. | |||
343 | In the previous example, the key is the string @St{__add} | 343 | In the previous example, the key is the string @St{__add} |
344 | and the metamethod is the function that performs the addition. | 344 | and the metamethod is the function that performs the addition. |
345 | Unless stated otherwise, | 345 | Unless stated otherwise, |
346 | a metamethod may in fact be any @x{callable value}, | 346 | a metamethod can in fact be any @x{callable value}, |
347 | which is either a function or a value with a @idx{__call} metamethod. | 347 | which is either a function or a value with a @idx{__call} metamethod. |
348 | 348 | ||
349 | You can query the metatable of any value | 349 | You can query the metatable of any value |
@@ -1421,7 +1421,7 @@ labels in Lua are considered statements too: | |||
1421 | 1421 | ||
1422 | A label is visible in the entire block where it is defined, | 1422 | A label is visible in the entire block where it is defined, |
1423 | except inside nested functions. | 1423 | except inside nested functions. |
1424 | A goto may jump to any visible label as long as it does not | 1424 | A goto can jump to any visible label as long as it does not |
1425 | enter into the scope of a local variable. | 1425 | enter into the scope of a local variable. |
1426 | A label should not be declared | 1426 | A label should not be declared |
1427 | where a label with the same name is visible, | 1427 | where a label with the same name is visible, |
@@ -4549,7 +4549,7 @@ corresponding Lua value is removed from the stack @see{constchar}. | |||
4549 | 4549 | ||
4550 | This function can raise memory errors only | 4550 | This function can raise memory errors only |
4551 | when converting a number to a string | 4551 | when converting a number to a string |
4552 | (as then it may have to create a new string). | 4552 | (as then it may create a new string). |
4553 | 4553 | ||
4554 | } | 4554 | } |
4555 | 4555 | ||
@@ -6113,8 +6113,8 @@ The metatable is created by the I/O library | |||
6113 | 6113 | ||
6114 | This userdata must start with the structure @id{luaL_Stream}; | 6114 | This userdata must start with the structure @id{luaL_Stream}; |
6115 | it can contain other data after this initial structure. | 6115 | it can contain other data after this initial structure. |
6116 | The field @id{f} points to the corresponding C stream | 6116 | The field @id{f} points to the corresponding C stream, |
6117 | (or it can be @id{NULL} to indicate an incompletely created handle). | 6117 | or it is @id{NULL} to indicate an incompletely created handle. |
6118 | The field @id{closef} points to a Lua function | 6118 | The field @id{closef} points to a Lua function |
6119 | that will be called to close the stream | 6119 | that will be called to close the stream |
6120 | when the handle is closed or collected; | 6120 | when the handle is closed or collected; |
@@ -9239,11 +9239,25 @@ Lua repeatedly prompts and waits for a line. | |||
9239 | After reading a line, | 9239 | After reading a line, |
9240 | Lua first try to interpret the line as an expression. | 9240 | Lua first try to interpret the line as an expression. |
9241 | If it succeeds, it prints its value. | 9241 | If it succeeds, it prints its value. |
9242 | Otherwise, it interprets the line as a statement. | 9242 | Otherwise, it interprets the line as a chunk. |
9243 | If you write an incomplete statement, | 9243 | If you write an incomplete chunk, |
9244 | the interpreter waits for its completion | 9244 | the interpreter waits for its completion |
9245 | by issuing a different prompt. | 9245 | by issuing a different prompt. |
9246 | 9246 | ||
9247 | Note that, as each complete line is read as a new chunk, | ||
9248 | local variables do not outlive lines: | ||
9249 | @verbatim{ | ||
9250 | > x = 20 | ||
9251 | > local x = 10; print(x) --> 10 | ||
9252 | > print(x) --> 20 -- global 'x' | ||
9253 | > do -- incomplete line | ||
9254 | >> local x = 10; print(x) -- '>>' prompts for line completion | ||
9255 | >> print(x) | ||
9256 | >> end -- line completed; Lua will run it as a single chunk | ||
9257 | --> 10 | ||
9258 | --> 10 | ||
9259 | } | ||
9260 | |||
9247 | If the global variable @defid{_PROMPT} contains a string, | 9261 | If the global variable @defid{_PROMPT} contains a string, |
9248 | then its value is used as the prompt. | 9262 | then its value is used as the prompt. |
9249 | Similarly, if the global variable @defid{_PROMPT2} contains a string, | 9263 | Similarly, if the global variable @defid{_PROMPT2} contains a string, |