diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-12 15:45:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-12 15:45:39 -0300 |
commit | d9e0f64a5de699a620771af299ea22f522c72f19 (patch) | |
tree | e851892b8c725d47374a53a42a4e161a49c5ef9f | |
parent | ab66652b3270b95222dea134b5e47bb3afc434cc (diff) | |
download | lua-d9e0f64a5de699a620771af299ea22f522c72f19.tar.gz lua-d9e0f64a5de699a620771af299ea22f522c72f19.tar.bz2 lua-d9e0f64a5de699a620771af299ea22f522c72f19.zip |
Small changes in the manual
-rw-r--r-- | manual/manual.of | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/manual/manual.of b/manual/manual.of index b34e1e9c..b698672a 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -2222,10 +2222,10 @@ f(3, 4, 5) a=3, b=4 | |||
2222 | f(r(), 10) a=1, b=10 | 2222 | f(r(), 10) a=1, b=10 |
2223 | f(r()) a=1, b=2 | 2223 | f(r()) a=1, b=2 |
2224 | 2224 | ||
2225 | g(3) a=3, b=nil, ... --> (nothing) | 2225 | g(3) a=3, b=nil, ... -> (nothing) |
2226 | g(3, 4) a=3, b=4, ... --> (nothing) | 2226 | g(3, 4) a=3, b=4, ... -> (nothing) |
2227 | g(3, 4, 5, 8) a=3, b=4, ... --> 5 8 | 2227 | g(3, 4, 5, 8) a=3, b=4, ... -> 5 8 |
2228 | g(5, r()) a=5, b=1, ... --> 2 3 | 2228 | g(5, r()) a=5, b=1, ... -> 2 3 |
2229 | } | 2229 | } |
2230 | 2230 | ||
2231 | Results are returned using the @Rw{return} statement @see{control}. | 2231 | Results are returned using the @Rw{return} statement @see{control}. |
@@ -7477,25 +7477,25 @@ then there is no replacement | |||
7477 | Here are some examples: | 7477 | Here are some examples: |
7478 | @verbatim{ | 7478 | @verbatim{ |
7479 | x = string.gsub("hello world", "(%w+)", "%1 %1") | 7479 | x = string.gsub("hello world", "(%w+)", "%1 %1") |
7480 | --> x="hello hello world world" | 7480 | -- x="hello hello world world" |
7481 | 7481 | ||
7482 | x = string.gsub("hello world", "%w+", "%0 %0", 1) | 7482 | x = string.gsub("hello world", "%w+", "%0 %0", 1) |
7483 | --> x="hello hello world" | 7483 | -- x="hello hello world" |
7484 | 7484 | ||
7485 | x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1") | 7485 | x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1") |
7486 | --> x="world hello Lua from" | 7486 | -- x="world hello Lua from" |
7487 | 7487 | ||
7488 | x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv) | 7488 | x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv) |
7489 | --> x="home = /home/roberto, user = roberto" | 7489 | -- x="home = /home/roberto, user = roberto" |
7490 | 7490 | ||
7491 | x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s) | 7491 | x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s) |
7492 | return load(s)() | 7492 | return load(s)() |
7493 | end) | 7493 | end) |
7494 | --> x="4+5 = 9" | 7494 | -- x="4+5 = 9" |
7495 | 7495 | ||
7496 | local t = {name="lua", version="5.4"} | 7496 | local t = {name="lua", version="5.4"} |
7497 | x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t) | 7497 | x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t) |
7498 | --> x="lua-5.4.tar.gz" | 7498 | -- x="lua-5.4.tar.gz" |
7499 | } | 7499 | } |
7500 | 7500 | ||
7501 | } | 7501 | } |
@@ -9299,15 +9299,21 @@ the interpreter waits for its completion | |||
9299 | by issuing a different prompt. | 9299 | by issuing a different prompt. |
9300 | 9300 | ||
9301 | Note that, as each complete line is read as a new chunk, | 9301 | Note that, as each complete line is read as a new chunk, |
9302 | local variables do not outlive lines: | 9302 | local variables do not outlive lines. |
9303 | To steer clear of confusion, | ||
9304 | the interpreter gives a warning if a line starts with the | ||
9305 | reserved word @Rw{local}: | ||
9303 | @verbatim{ | 9306 | @verbatim{ |
9304 | > x = 20 | 9307 | > x = 20 -- global 'x' |
9305 | > local x = 10; print(x) --> 10 | 9308 | > local x = 10; print(x) |
9306 | > print(x) --> 20 -- global 'x' | 9309 | --> warning: locals do not survive across lines in interactive mode |
9307 | > do -- incomplete line | 9310 | --> 10 |
9311 | > print(x) -- back to global 'x' | ||
9312 | --> 20 | ||
9313 | > do -- incomplete chunk | ||
9308 | >> local x = 10; print(x) -- '>>' prompts for line completion | 9314 | >> local x = 10; print(x) -- '>>' prompts for line completion |
9309 | >> print(x) | 9315 | >> print(x) |
9310 | >> end -- line completed; Lua will run it as a single chunk | 9316 | >> end -- chunk completed |
9311 | --> 10 | 9317 | --> 10 |
9312 | --> 10 | 9318 | --> 10 |
9313 | } | 9319 | } |