diff options
Diffstat (limited to 'manual/manual.of')
-rw-r--r-- | manual/manual.of | 179 |
1 files changed, 43 insertions, 136 deletions
diff --git a/manual/manual.of b/manual/manual.of index ad120f5e..3eab69fa 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}. |
@@ -2736,7 +2730,8 @@ For such errors, Lua does not call the @x{message handler}. | |||
2736 | 2730 | ||
2737 | @item{@defid{LUA_ERRERR}| error while running the @x{message handler}.} | 2731 | @item{@defid{LUA_ERRERR}| error while running the @x{message handler}.} |
2738 | 2732 | ||
2739 | @item{@defid{LUA_ERRSYNTAX}| syntax error during precompilation.} | 2733 | @item{@defid{LUA_ERRSYNTAX}| syntax error during precompilation |
2734 | or format error in a binary chunk.} | ||
2740 | 2735 | ||
2741 | @item{@defid{LUA_YIELD}| the thread (coroutine) yields.} | 2736 | @item{@defid{LUA_YIELD}| the thread (coroutine) yields.} |
2742 | 2737 | ||
@@ -3652,6 +3647,18 @@ and loads it accordingly (see program @idx{luac}). | |||
3652 | The string @id{mode} works as in function @Lid{load}, | 3647 | The string @id{mode} works as in function @Lid{load}, |
3653 | with the addition that | 3648 | with the addition that |
3654 | a @id{NULL} value is equivalent to the string @St{bt}. | 3649 | a @id{NULL} value is equivalent to the string @St{bt}. |
3650 | Moreover, it may have a @Char{B} instead of a @Char{b}, | ||
3651 | meaning a @emphx{fixed buffer} with the binary dump. | ||
3652 | |||
3653 | A fixed buffer means that the address returned by the reader function | ||
3654 | should contain the chunk until everything created by the chunk has | ||
3655 | been collected. | ||
3656 | (In general, a fixed buffer would keep the chunk | ||
3657 | as its contents until the end of the program, | ||
3658 | for instance with the chunk in ROM.) | ||
3659 | Moreover, for a fixed buffer, | ||
3660 | the reader function should return the entire chunk in the first read. | ||
3661 | (As an example, @Lid{luaL_loadbufferx} does that.) | ||
3655 | 3662 | ||
3656 | @id{lua_load} uses the stack internally, | 3663 | @id{lua_load} uses the stack internally, |
3657 | so the reader function must always leave the stack | 3664 | so the reader function must always leave the stack |
@@ -3671,7 +3678,8 @@ Other upvalues are initialized with @nil. | |||
3671 | 3678 | ||
3672 | } | 3679 | } |
3673 | 3680 | ||
3674 | @APIEntry{lua_State *lua_newstate (lua_Alloc f, void *ud);| | 3681 | @APIEntry{lua_State *lua_newstate (lua_Alloc f, void *ud, |
3682 | unsigned int seed);| | ||
3675 | @apii{0,0,-} | 3683 | @apii{0,0,-} |
3676 | 3684 | ||
3677 | Creates a new independent state and returns its main thread. | 3685 | Creates a new independent state and returns its main thread. |
@@ -3682,6 +3690,8 @@ Lua will do all memory allocation for this state | |||
3682 | through this function @seeF{lua_Alloc}. | 3690 | through this function @seeF{lua_Alloc}. |
3683 | The second argument, @id{ud}, is an opaque pointer that Lua | 3691 | The second argument, @id{ud}, is an opaque pointer that Lua |
3684 | passes to the allocator in every call. | 3692 | passes to the allocator in every call. |
3693 | The third argument, @id{seed}, is a seed for the hashing of | ||
3694 | strings when they are used as table keys. | ||
3685 | 3695 | ||
3686 | } | 3696 | } |
3687 | 3697 | ||
@@ -5691,6 +5701,8 @@ This function returns the same results as @Lid{lua_load}. | |||
5691 | @id{name} is the chunk name, | 5701 | @id{name} is the chunk name, |
5692 | used for debug information and error messages. | 5702 | used for debug information and error messages. |
5693 | The string @id{mode} works as in the function @Lid{lua_load}. | 5703 | The string @id{mode} works as in the function @Lid{lua_load}. |
5704 | In particular, this function supports mode @Char{B} for | ||
5705 | fixed buffers. | ||
5694 | 5706 | ||
5695 | } | 5707 | } |
5696 | 5708 | ||
@@ -5737,6 +5749,16 @@ it does not run it. | |||
5737 | 5749 | ||
5738 | } | 5750 | } |
5739 | 5751 | ||
5752 | @APIEntry{unsigned int luaL_makeseed (lua_State *L);| | ||
5753 | @apii{0,0,-} | ||
5754 | |||
5755 | Returns a value with a weak attempt for randomness. | ||
5756 | (It produces that value based on the current date and time | ||
5757 | and the address of an internal variable, | ||
5758 | in case the machine has Address Space Layout Randomization.) | ||
5759 | |||
5760 | } | ||
5761 | |||
5740 | 5762 | ||
5741 | @APIEntry{void luaL_newlib (lua_State *L, const luaL_Reg l[]);| | 5763 | @APIEntry{void luaL_newlib (lua_State *L, const luaL_Reg l[]);| |
5742 | @apii{0,1,m} | 5764 | @apii{0,1,m} |
@@ -6909,9 +6931,9 @@ including if necessary a path and an extension. | |||
6909 | (which may depend on the @N{C compiler} and linker used). | 6931 | (which may depend on the @N{C compiler} and linker used). |
6910 | 6932 | ||
6911 | This functionality is not supported by @N{ISO C}. | 6933 | This functionality is not supported by @N{ISO C}. |
6912 | As such, it is only available on some platforms | 6934 | As such, @id{loadlib} is only available on some platforms: |
6913 | (Windows, Linux, Mac OS X, Solaris, BSD, | 6935 | Linux, Windows, Mac OS X, Solaris, BSD, |
6914 | plus other Unix systems that support the @id{dlfcn} standard). | 6936 | plus other Unix systems that support the @id{dlfcn} standard. |
6915 | 6937 | ||
6916 | This function is inherently insecure, | 6938 | This function is inherently insecure, |
6917 | as it allows Lua to call any function in any readable dynamic | 6939 | as it allows Lua to call any function in any readable dynamic |
@@ -8109,7 +8131,7 @@ different sequences of results each time the program runs. | |||
8109 | 8131 | ||
8110 | When called with at least one argument, | 8132 | When called with at least one argument, |
8111 | the integer parameters @id{x} and @id{y} are | 8133 | the integer parameters @id{x} and @id{y} are |
8112 | joined into a 128-bit @emphx{seed} that | 8134 | joined into a @emphx{seed} that |
8113 | is used to reinitialize the pseudo-random generator; | 8135 | is used to reinitialize the pseudo-random generator; |
8114 | equal seeds produce equal sequences of numbers. | 8136 | equal seeds produce equal sequences of numbers. |
8115 | The default for @id{y} is zero. | 8137 | The default for @id{y} is zero. |
@@ -9132,7 +9154,7 @@ is a more portable solution. | |||
9132 | @simplesect{ | 9154 | @simplesect{ |
9133 | 9155 | ||
9134 | Here we list the incompatibilities that you may find when moving a program | 9156 | Here we list the incompatibilities that you may find when moving a program |
9135 | from @N{Lua 5.3} to @N{Lua 5.4}. | 9157 | from @N{Lua 5.4} to @N{Lua 5.5}. |
9136 | 9158 | ||
9137 | You can avoid some incompatibilities by compiling Lua with | 9159 | You can avoid some incompatibilities by compiling Lua with |
9138 | appropriate options (see file @id{luaconf.h}). | 9160 | appropriate options (see file @id{luaconf.h}). |
@@ -9169,51 +9191,9 @@ change between versions. | |||
9169 | @itemize{ | 9191 | @itemize{ |
9170 | 9192 | ||
9171 | @item{ | 9193 | @item{ |
9172 | The coercion of strings to numbers in | 9194 | The control variable in @Rw{for} loops are read only. |
9173 | arithmetic and bitwise operations | 9195 | If you need to change it, |
9174 | has been removed from the core language. | 9196 | declare a local variable with the same name in the loop body. |
9175 | The string library does a similar job | ||
9176 | for arithmetic (but not for bitwise) operations | ||
9177 | using the string metamethods. | ||
9178 | However, unlike in previous versions, | ||
9179 | the new implementation preserves the implicit type of the numeral | ||
9180 | in the string. | ||
9181 | For instance, the result of @T{"1" + "2"} now is an integer, | ||
9182 | not a float. | ||
9183 | } | ||
9184 | |||
9185 | @item{ | ||
9186 | Literal decimal integer constants that overflow are read as floats, | ||
9187 | instead of wrapping around. | ||
9188 | You can use hexadecimal notation for such constants if you | ||
9189 | want the old behavior | ||
9190 | (reading them as integers with wrap around). | ||
9191 | } | ||
9192 | |||
9193 | @item{ | ||
9194 | The use of the @idx{__lt} metamethod to emulate @idx{__le} | ||
9195 | has been removed. | ||
9196 | When needed, this metamethod must be explicitly defined. | ||
9197 | } | ||
9198 | |||
9199 | @item{ | ||
9200 | The semantics of the numerical @Rw{for} loop | ||
9201 | over integers changed in some details. | ||
9202 | In particular, the control variable never wraps around. | ||
9203 | } | ||
9204 | |||
9205 | @item{ | ||
9206 | A label for a @Rw{goto} cannot be declared where a label with the same | ||
9207 | name is visible, even if this other label is declared in an enclosing | ||
9208 | block. | ||
9209 | } | ||
9210 | |||
9211 | @item{ | ||
9212 | When finalizing an object, | ||
9213 | Lua does not ignore @idx{__gc} metamethods that are not functions. | ||
9214 | Any value will be called, if present. | ||
9215 | (Non-callable values will generate a warning, | ||
9216 | like any other error when calling a finalizer.) | ||
9217 | } | 9197 | } |
9218 | 9198 | ||
9219 | } | 9199 | } |
@@ -9224,39 +9204,6 @@ like any other error when calling a finalizer.) | |||
9224 | @itemize{ | 9204 | @itemize{ |
9225 | 9205 | ||
9226 | @item{ | 9206 | @item{ |
9227 | The function @Lid{print} does not call @Lid{tostring} | ||
9228 | to format its arguments; | ||
9229 | instead, it has this functionality hardwired. | ||
9230 | You should use @idx{__tostring} to modify how values are printed. | ||
9231 | } | ||
9232 | |||
9233 | @item{ | ||
9234 | The pseudo-random number generator used by the function @Lid{math.random} | ||
9235 | now starts with a somewhat random seed. | ||
9236 | Moreover, it uses a different algorithm. | ||
9237 | } | ||
9238 | |||
9239 | @item{ | ||
9240 | By default, the decoding functions in the @Lid{utf8} library | ||
9241 | do not accept surrogates as valid code points. | ||
9242 | An extra parameter in these functions makes them more permissive. | ||
9243 | } | ||
9244 | |||
9245 | @item{ | ||
9246 | The options @St{setpause} and @St{setstepmul} | ||
9247 | of the function @Lid{collectgarbage} are deprecated. | ||
9248 | You should use the new option @St{incremental} to set them. | ||
9249 | } | ||
9250 | |||
9251 | @item{ | ||
9252 | The function @Lid{io.lines} now returns four values, | ||
9253 | instead of just one. | ||
9254 | That can be a problem when it is used as the sole | ||
9255 | argument to another function that has optional parameters, | ||
9256 | such as in @T{load(io.lines(filename, "L"))}. | ||
9257 | To fix that issue, | ||
9258 | you can wrap the call into parentheses, | ||
9259 | to adjust its number of results to one. | ||
9260 | } | 9207 | } |
9261 | 9208 | ||
9262 | } | 9209 | } |
@@ -9268,46 +9215,6 @@ to adjust its number of results to one. | |||
9268 | @itemize{ | 9215 | @itemize{ |
9269 | 9216 | ||
9270 | @item{ | 9217 | @item{ |
9271 | Full userdata now has an arbitrary number of associated user values. | ||
9272 | Therefore, the functions @id{lua_newuserdata}, | ||
9273 | @id{lua_setuservalue}, and @id{lua_getuservalue} were | ||
9274 | replaced by @Lid{lua_newuserdatauv}, | ||
9275 | @Lid{lua_setiuservalue}, and @Lid{lua_getiuservalue}, | ||
9276 | which have an extra argument. | ||
9277 | |||
9278 | For compatibility, the old names still work as macros assuming | ||
9279 | one single user value. | ||
9280 | Note, however, that userdata with zero user values | ||
9281 | are more efficient memory-wise. | ||
9282 | } | ||
9283 | |||
9284 | @item{ | ||
9285 | The function @Lid{lua_resume} has an extra parameter. | ||
9286 | This out parameter returns the number of values on | ||
9287 | the top of the stack that were yielded or returned by the coroutine. | ||
9288 | (In previous versions, | ||
9289 | those values were the entire stack.) | ||
9290 | } | ||
9291 | |||
9292 | @item{ | ||
9293 | The function @Lid{lua_version} returns the version number, | ||
9294 | instead of an address of the version number. | ||
9295 | The Lua core should work correctly with libraries using their | ||
9296 | own static copies of the same core, | ||
9297 | so there is no need to check whether they are using the same | ||
9298 | address space. | ||
9299 | } | ||
9300 | |||
9301 | @item{ | ||
9302 | The constant @id{LUA_ERRGCMM} was removed. | ||
9303 | Errors in finalizers are never propagated; | ||
9304 | instead, they generate a warning. | ||
9305 | } | ||
9306 | |||
9307 | @item{ | ||
9308 | The options @idx{LUA_GCSETPAUSE} and @idx{LUA_GCSETSTEPMUL} | ||
9309 | of the function @Lid{lua_gc} are deprecated. | ||
9310 | You should use the new option @id{LUA_GCINC} to set them. | ||
9311 | } | 9218 | } |
9312 | 9219 | ||
9313 | } | 9220 | } |