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