diff options
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 162 |
1 files changed, 27 insertions, 135 deletions
diff --git a/manual/manual.of b/manual/manual.of index f8d8ddd4..1e219f9a 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -1467,7 +1467,7 @@ It has the following syntax: | |||
1467 | exp @bnfter{,} exp @bnfopt{@bnfter{,} exp} @Rw{do} block @Rw{end}} | 1467 | exp @bnfter{,} exp @bnfopt{@bnfter{,} exp} @Rw{do} block @Rw{end}} |
1468 | } | 1468 | } |
1469 | The given identifier (@bnfNter{Name}) defines the control variable, | 1469 | The given identifier (@bnfNter{Name}) defines the control variable, |
1470 | which is a new variable local to the loop body (@emph{block}). | 1470 | which is a new read-only variable local to the loop body (@emph{block}). |
1471 | 1471 | ||
1472 | The loop starts by evaluating once the three control expressions. | 1472 | The loop starts by evaluating once the three control expressions. |
1473 | Their values are called respectively | 1473 | Their values are called respectively |
@@ -1499,11 +1499,6 @@ For integer loops, | |||
1499 | the control variable never wraps around; | 1499 | the control variable never wraps around; |
1500 | instead, the loop ends in case of an overflow. | 1500 | instead, the loop ends in case of an overflow. |
1501 | 1501 | ||
1502 | You should not change the value of the control variable | ||
1503 | during the loop. | ||
1504 | If you need its value after the loop, | ||
1505 | assign it to another variable before exiting the loop. | ||
1506 | |||
1507 | } | 1502 | } |
1508 | 1503 | ||
1509 | @sect4{@title{The generic @Rw{for} loop} | 1504 | @sect4{@title{The generic @Rw{for} loop} |
@@ -1526,7 +1521,8 @@ for @rep{var_1}, @Cdots, @rep{var_n} in @rep{explist} do @rep{body} end | |||
1526 | works as follows. | 1521 | works as follows. |
1527 | 1522 | ||
1528 | The names @rep{var_i} declare loop variables local to the loop body. | 1523 | The names @rep{var_i} declare loop variables local to the loop body. |
1529 | The first of these variables is the @emph{control variable}. | 1524 | The first of these variables is the @emph{control variable}, |
1525 | which is a read-only variable. | ||
1530 | 1526 | ||
1531 | The loop starts by evaluating @rep{explist} | 1527 | The loop starts by evaluating @rep{explist} |
1532 | to produce four values: | 1528 | to produce four values: |
@@ -1550,9 +1546,6 @@ to-be-closed variable @see{to-be-closed}, | |||
1550 | which can be used to release resources when the loop ends. | 1546 | which can be used to release resources when the loop ends. |
1551 | Otherwise, it does not interfere with the loop. | 1547 | Otherwise, it does not interfere with the loop. |
1552 | 1548 | ||
1553 | You should not change the value of the control variable | ||
1554 | during the loop. | ||
1555 | |||
1556 | } | 1549 | } |
1557 | 1550 | ||
1558 | } | 1551 | } |
@@ -1586,7 +1579,8 @@ Each variable name may be postfixed by an attribute | |||
1586 | @producname{attrib}@producbody{@bnfopt{@bnfter{<} @bnfNter{Name} @bnfter{>}}} | 1579 | @producname{attrib}@producbody{@bnfopt{@bnfter{<} @bnfNter{Name} @bnfter{>}}} |
1587 | } | 1580 | } |
1588 | There are two possible attributes: | 1581 | There are two possible attributes: |
1589 | @id{const}, which declares a @x{constant variable}, | 1582 | @id{const}, which declares a @emph{constant} or @emph{read-only} variable, |
1583 | @index{constant variable} | ||
1590 | that is, a variable that cannot be assigned to | 1584 | that is, a variable that cannot be assigned to |
1591 | after its initialization; | 1585 | after its initialization; |
1592 | and @id{close}, which declares a to-be-closed variable @see{to-be-closed}. | 1586 | and @id{close}, which declares a to-be-closed variable @see{to-be-closed}. |
@@ -3671,7 +3665,8 @@ Other upvalues are initialized with @nil. | |||
3671 | 3665 | ||
3672 | } | 3666 | } |
3673 | 3667 | ||
3674 | @APIEntry{lua_State *lua_newstate (lua_Alloc f, void *ud);| | 3668 | @APIEntry{lua_State *lua_newstate (lua_Alloc f, void *ud, |
3669 | unsigned int seed);| | ||
3675 | @apii{0,0,-} | 3670 | @apii{0,0,-} |
3676 | 3671 | ||
3677 | Creates a new independent state and returns its main thread. | 3672 | Creates a new independent state and returns its main thread. |
@@ -3682,6 +3677,8 @@ Lua will do all memory allocation for this state | |||
3682 | through this function @seeF{lua_Alloc}. | 3677 | through this function @seeF{lua_Alloc}. |
3683 | The second argument, @id{ud}, is an opaque pointer that Lua | 3678 | The second argument, @id{ud}, is an opaque pointer that Lua |
3684 | passes to the allocator in every call. | 3679 | passes to the allocator in every call. |
3680 | The third argument, @id{seed}, is a seed for the hashing of | ||
3681 | strings when they are used as table keys. | ||
3685 | 3682 | ||
3686 | } | 3683 | } |
3687 | 3684 | ||
@@ -5737,6 +5734,16 @@ it does not run it. | |||
5737 | 5734 | ||
5738 | } | 5735 | } |
5739 | 5736 | ||
5737 | @APIEntry{unsigned int luaL_makeseed (lua_State *L);| | ||
5738 | @apii{0,0,-} | ||
5739 | |||
5740 | Returns a value with a weak attempt for randomness. | ||
5741 | (It produces that value based on the current date and time | ||
5742 | and the address of an internal variable, | ||
5743 | in case the machine has Address Space Layout Randomization.) | ||
5744 | |||
5745 | } | ||
5746 | |||
5740 | 5747 | ||
5741 | @APIEntry{void luaL_newlib (lua_State *L, const luaL_Reg l[]);| | 5748 | @APIEntry{void luaL_newlib (lua_State *L, const luaL_Reg l[]);| |
5742 | @apii{0,1,m} | 5749 | @apii{0,1,m} |
@@ -6909,9 +6916,9 @@ including if necessary a path and an extension. | |||
6909 | (which may depend on the @N{C compiler} and linker used). | 6916 | (which may depend on the @N{C compiler} and linker used). |
6910 | 6917 | ||
6911 | This functionality is not supported by @N{ISO C}. | 6918 | This functionality is not supported by @N{ISO C}. |
6912 | As such, it is only available on some platforms | 6919 | As such, @id{loadlib} is only available on some platforms: |
6913 | (Windows, Linux, Mac OS X, Solaris, BSD, | 6920 | Linux, Windows, Mac OS X, Solaris, BSD, |
6914 | plus other Unix systems that support the @id{dlfcn} standard). | 6921 | plus other Unix systems that support the @id{dlfcn} standard. |
6915 | 6922 | ||
6916 | This function is inherently insecure, | 6923 | This function is inherently insecure, |
6917 | as it allows Lua to call any function in any readable dynamic | 6924 | as it allows Lua to call any function in any readable dynamic |
@@ -8109,7 +8116,7 @@ different sequences of results each time the program runs. | |||
8109 | 8116 | ||
8110 | When called with at least one argument, | 8117 | When called with at least one argument, |
8111 | the integer parameters @id{x} and @id{y} are | 8118 | the integer parameters @id{x} and @id{y} are |
8112 | joined into a 128-bit @emphx{seed} that | 8119 | joined into a @emphx{seed} that |
8113 | is used to reinitialize the pseudo-random generator; | 8120 | is used to reinitialize the pseudo-random generator; |
8114 | equal seeds produce equal sequences of numbers. | 8121 | equal seeds produce equal sequences of numbers. |
8115 | The default for @id{y} is zero. | 8122 | The default for @id{y} is zero. |
@@ -9128,7 +9135,7 @@ is a more portable solution. | |||
9128 | @simplesect{ | 9135 | @simplesect{ |
9129 | 9136 | ||
9130 | Here we list the incompatibilities that you may find when moving a program | 9137 | Here we list the incompatibilities that you may find when moving a program |
9131 | from @N{Lua 5.3} to @N{Lua 5.4}. | 9138 | from @N{Lua 5.4} to @N{Lua 5.5}. |
9132 | 9139 | ||
9133 | You can avoid some incompatibilities by compiling Lua with | 9140 | You can avoid some incompatibilities by compiling Lua with |
9134 | appropriate options (see file @id{luaconf.h}). | 9141 | appropriate options (see file @id{luaconf.h}). |
@@ -9165,51 +9172,9 @@ change between versions. | |||
9165 | @itemize{ | 9172 | @itemize{ |
9166 | 9173 | ||
9167 | @item{ | 9174 | @item{ |
9168 | The coercion of strings to numbers in | 9175 | The control variable in @Rw{for} loops are read only. |
9169 | arithmetic and bitwise operations | 9176 | If you need to change it, |
9170 | has been removed from the core language. | 9177 | declare a local variable with the same name in the loop body. |
9171 | The string library does a similar job | ||
9172 | for arithmetic (but not for bitwise) operations | ||
9173 | using the string metamethods. | ||
9174 | However, unlike in previous versions, | ||
9175 | the new implementation preserves the implicit type of the numeral | ||
9176 | in the string. | ||
9177 | For instance, the result of @T{"1" + "2"} now is an integer, | ||
9178 | not a float. | ||
9179 | } | ||
9180 | |||
9181 | @item{ | ||
9182 | Literal decimal integer constants that overflow are read as floats, | ||
9183 | instead of wrapping around. | ||
9184 | You can use hexadecimal notation for such constants if you | ||
9185 | want the old behavior | ||
9186 | (reading them as integers with wrap around). | ||
9187 | } | ||
9188 | |||
9189 | @item{ | ||
9190 | The use of the @idx{__lt} metamethod to emulate @idx{__le} | ||
9191 | has been removed. | ||
9192 | When needed, this metamethod must be explicitly defined. | ||
9193 | } | ||
9194 | |||
9195 | @item{ | ||
9196 | The semantics of the numerical @Rw{for} loop | ||
9197 | over integers changed in some details. | ||
9198 | In particular, the control variable never wraps around. | ||
9199 | } | ||
9200 | |||
9201 | @item{ | ||
9202 | A label for a @Rw{goto} cannot be declared where a label with the same | ||
9203 | name is visible, even if this other label is declared in an enclosing | ||
9204 | block. | ||
9205 | } | ||
9206 | |||
9207 | @item{ | ||
9208 | When finalizing an object, | ||
9209 | Lua does not ignore @idx{__gc} metamethods that are not functions. | ||
9210 | Any value will be called, if present. | ||
9211 | (Non-callable values will generate a warning, | ||
9212 | like any other error when calling a finalizer.) | ||
9213 | } | 9178 | } |
9214 | 9179 | ||
9215 | } | 9180 | } |
@@ -9220,39 +9185,6 @@ like any other error when calling a finalizer.) | |||
9220 | @itemize{ | 9185 | @itemize{ |
9221 | 9186 | ||
9222 | @item{ | 9187 | @item{ |
9223 | The function @Lid{print} does not call @Lid{tostring} | ||
9224 | to format its arguments; | ||
9225 | instead, it has this functionality hardwired. | ||
9226 | You should use @idx{__tostring} to modify how values are printed. | ||
9227 | } | ||
9228 | |||
9229 | @item{ | ||
9230 | The pseudo-random number generator used by the function @Lid{math.random} | ||
9231 | now starts with a somewhat random seed. | ||
9232 | Moreover, it uses a different algorithm. | ||
9233 | } | ||
9234 | |||
9235 | @item{ | ||
9236 | By default, the decoding functions in the @Lid{utf8} library | ||
9237 | do not accept surrogates as valid code points. | ||
9238 | An extra parameter in these functions makes them more permissive. | ||
9239 | } | ||
9240 | |||
9241 | @item{ | ||
9242 | The options @St{setpause} and @St{setstepmul} | ||
9243 | of the function @Lid{collectgarbage} are deprecated. | ||
9244 | You should use the new option @St{incremental} to set them. | ||
9245 | } | ||
9246 | |||
9247 | @item{ | ||
9248 | The function @Lid{io.lines} now returns four values, | ||
9249 | instead of just one. | ||
9250 | That can be a problem when it is used as the sole | ||
9251 | argument to another function that has optional parameters, | ||
9252 | such as in @T{load(io.lines(filename, "L"))}. | ||
9253 | To fix that issue, | ||
9254 | you can wrap the call into parentheses, | ||
9255 | to adjust its number of results to one. | ||
9256 | } | 9188 | } |
9257 | 9189 | ||
9258 | } | 9190 | } |
@@ -9264,46 +9196,6 @@ to adjust its number of results to one. | |||
9264 | @itemize{ | 9196 | @itemize{ |
9265 | 9197 | ||
9266 | @item{ | 9198 | @item{ |
9267 | Full userdata now has an arbitrary number of associated user values. | ||
9268 | Therefore, the functions @id{lua_newuserdata}, | ||
9269 | @id{lua_setuservalue}, and @id{lua_getuservalue} were | ||
9270 | replaced by @Lid{lua_newuserdatauv}, | ||
9271 | @Lid{lua_setiuservalue}, and @Lid{lua_getiuservalue}, | ||
9272 | which have an extra argument. | ||
9273 | |||
9274 | For compatibility, the old names still work as macros assuming | ||
9275 | one single user value. | ||
9276 | Note, however, that userdata with zero user values | ||
9277 | are more efficient memory-wise. | ||
9278 | } | ||
9279 | |||
9280 | @item{ | ||
9281 | The function @Lid{lua_resume} has an extra parameter. | ||
9282 | This out parameter returns the number of values on | ||
9283 | the top of the stack that were yielded or returned by the coroutine. | ||
9284 | (In previous versions, | ||
9285 | those values were the entire stack.) | ||
9286 | } | ||
9287 | |||
9288 | @item{ | ||
9289 | The function @Lid{lua_version} returns the version number, | ||
9290 | instead of an address of the version number. | ||
9291 | The Lua core should work correctly with libraries using their | ||
9292 | own static copies of the same core, | ||
9293 | so there is no need to check whether they are using the same | ||
9294 | address space. | ||
9295 | } | ||
9296 | |||
9297 | @item{ | ||
9298 | The constant @id{LUA_ERRGCMM} was removed. | ||
9299 | Errors in finalizers are never propagated; | ||
9300 | instead, they generate a warning. | ||
9301 | } | ||
9302 | |||
9303 | @item{ | ||
9304 | The options @idx{LUA_GCSETPAUSE} and @idx{LUA_GCSETSTEPMUL} | ||
9305 | of the function @Lid{lua_gc} are deprecated. | ||
9306 | You should use the new option @id{LUA_GCINC} to set them. | ||
9307 | } | 9199 | } |
9308 | 9200 | ||
9309 | } | 9201 | } |