aboutsummaryrefslogtreecommitdiff
path: root/manual/manual.of
diff options
context:
space:
mode:
Diffstat (limited to 'manual/manual.of')
-rw-r--r--manual/manual.of179
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}
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}.
@@ -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
2734or 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}).
3652The string @id{mode} works as in function @Lid{load}, 3647The string @id{mode} works as in function @Lid{load},
3653with the addition that 3648with the addition that
3654a @id{NULL} value is equivalent to the string @St{bt}. 3649a @id{NULL} value is equivalent to the string @St{bt}.
3650Moreover, it may have a @Char{B} instead of a @Char{b},
3651meaning a @emphx{fixed buffer} with the binary dump.
3652
3653A fixed buffer means that the address returned by the reader function
3654should contain the chunk until everything created by the chunk has
3655been collected.
3656(In general, a fixed buffer would keep the chunk
3657as its contents until the end of the program,
3658for instance with the chunk in ROM.)
3659Moreover, for a fixed buffer,
3660the 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,
3657so the reader function must always leave the stack 3664so 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
3677Creates a new independent state and returns its main thread. 3685Creates a new independent state and returns its main thread.
@@ -3682,6 +3690,8 @@ Lua will do all memory allocation for this state
3682through this function @seeF{lua_Alloc}. 3690through this function @seeF{lua_Alloc}.
3683The second argument, @id{ud}, is an opaque pointer that Lua 3691The second argument, @id{ud}, is an opaque pointer that Lua
3684passes to the allocator in every call. 3692passes to the allocator in every call.
3693The third argument, @id{seed}, is a seed for the hashing of
3694strings 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,
5692used for debug information and error messages. 5702used for debug information and error messages.
5693The string @id{mode} works as in the function @Lid{lua_load}. 5703The string @id{mode} works as in the function @Lid{lua_load}.
5704In particular, this function supports mode @Char{B} for
5705fixed 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
5755Returns a value with a weak attempt for randomness.
5756(It produces that value based on the current date and time
5757and the address of an internal variable,
5758in 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
6911This functionality is not supported by @N{ISO C}. 6933This functionality is not supported by @N{ISO C}.
6912As such, it is only available on some platforms 6934As such, @id{loadlib} is only available on some platforms:
6913(Windows, Linux, Mac OS X, Solaris, BSD, 6935Linux, Windows, Mac OS X, Solaris, BSD,
6914plus other Unix systems that support the @id{dlfcn} standard). 6936plus other Unix systems that support the @id{dlfcn} standard.
6915 6937
6916This function is inherently insecure, 6938This function is inherently insecure,
6917as it allows Lua to call any function in any readable dynamic 6939as 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
8110When called with at least one argument, 8132When called with at least one argument,
8111the integer parameters @id{x} and @id{y} are 8133the integer parameters @id{x} and @id{y} are
8112joined into a 128-bit @emphx{seed} that 8134joined into a @emphx{seed} that
8113is used to reinitialize the pseudo-random generator; 8135is used to reinitialize the pseudo-random generator;
8114equal seeds produce equal sequences of numbers. 8136equal seeds produce equal sequences of numbers.
8115The default for @id{y} is zero. 8137The default for @id{y} is zero.
@@ -9132,7 +9154,7 @@ is a more portable solution.
9132@simplesect{ 9154@simplesect{
9133 9155
9134Here we list the incompatibilities that you may find when moving a program 9156Here we list the incompatibilities that you may find when moving a program
9135from @N{Lua 5.3} to @N{Lua 5.4}. 9157from @N{Lua 5.4} to @N{Lua 5.5}.
9136 9158
9137You can avoid some incompatibilities by compiling Lua with 9159You can avoid some incompatibilities by compiling Lua with
9138appropriate options (see file @id{luaconf.h}). 9160appropriate options (see file @id{luaconf.h}).
@@ -9169,51 +9191,9 @@ change between versions.
9169@itemize{ 9191@itemize{
9170 9192
9171@item{ 9193@item{
9172The coercion of strings to numbers in 9194The control variable in @Rw{for} loops are read only.
9173arithmetic and bitwise operations 9195If you need to change it,
9174has been removed from the core language. 9196declare 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} 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{
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} 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{
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} 9218}
9312 9219
9313} 9220}