@@ -82,7 +82,8 @@ whose main property is to be different from any other value;
8282it often represents the absence of a useful value.
8383The type @emph{boolean} has two values, @false and @true.
8484Both @nil and @false make a condition false;
85- any other value makes it true.
85+ they are collectively called @def{false values}.
86+ Any other value makes a condition true.
8687
8788The type @emph{number} represents both
8889integer numbers and real (floating-point) numbers,
@@ -278,9 +279,9 @@ so, an error inside the message handler
278279will call the message handler again.
279280If this loop goes on for too long,
280281Lua breaks it and returns an appropriate message.
281- ( The message handler is called only for regular runtime errors.
282+ The message handler is called only for regular runtime errors.
282283It is not called for memory-allocation errors
283- nor for errors while running finalizers.)
284+ nor for errors while running finalizers or other message handlers.
284285
285286Lua also offers a system of @emph{warnings} @seeF{warn}.
286287Unlike errors, warnings do not interfere
@@ -467,7 +468,7 @@ Behavior similar to the less than operation.
467468The indexing access operation @T{table[key]}.
468469This event happens when @id{table} is not a table or
469470when @id{key} is not present in @id{table}.
470- The metamethod is looked up in @id{table}.
471+ The metamethod is looked up in the metatable of @id{table}.
471472
472473Despite the name,
473474the metamethod for this event can be either a function or a table.
@@ -528,7 +529,7 @@ the interpreter also respects the following keys in metatables:
528529and @idx{__name}.
529530(The entry @idx{__name},
530531when it contains a string,
531- is used by some error-reporting functions to build error messages.)
532+ may be used by @Lid{tostring} and in error messages.)
532533
533534For the unary operators (negation, length, and bitwise NOT),
534535the metamethod is computed and called with a dummy second operand,
@@ -638,7 +639,7 @@ In generational mode,
638639the collector does frequent @emph{minor} collections,
639640which traverses only objects recently created.
640641If after a minor collection the use of memory is still above a limit,
641- the collector does a @emph{major} collection,
642+ the collector does a stop-the-world @emph{major} collection,
642643which traverses all objects.
643644The generational mode uses two parameters:
644645the @def{minor multiplier} and the @def{the major multiplier}.
@@ -943,7 +944,7 @@ Lua is a @x{free-form} language.
943944It ignores spaces and comments between lexical elements (@x{tokens}),
944945except as delimiters between two tokens.
945946In source code,
946- Lua recognizes as spaces the standard ASCII white-space
947+ Lua recognizes as spaces the standard ASCII whitespace
947948characters space, form feed, newline,
948949carriage return, horizontal tab, and vertical tab.
949950
@@ -998,7 +999,7 @@ and @Char{\'} (apostrophe [single quote]).
998999A backslash followed by a line break
9991000results in a newline in the string.
10001001The escape sequence @Char{\z} skips the following span
1001- of white-space characters,
1002+ of whitespace characters,
10021003including line breaks;
10031004it is particularly useful to break and indent a long literal string
10041005into multiple lines without adding the newlines and spaces
@@ -1769,7 +1770,7 @@ Otherwise, the conversion fails.
17691770Several places in Lua coerce strings to numbers when necessary.
17701771A string is converted to an integer or a float
17711772following its syntax and the rules of the Lua lexer.
1772- (The string may have also leading and trailing spaces and a sign.)
1773+ (The string may have also leading and trailing whitespaces and a sign.)
17731774All conversions from strings to numbers
17741775accept both a dot and the current locale mark
17751776as the radix character.
@@ -2182,7 +2183,7 @@ function r() return 1,2,3 end
21822183Then, we have the following mapping from arguments to parameters and
21832184to the vararg expression:
21842185@verbatim{
2185- CALL PARAMETERS
2186+ CALL PARAMETERS
21862187
21872188f(3) a=3, b=nil
21882189f(3, 4) a=3, b=4
@@ -2802,17 +2803,21 @@ Sets a new panic function and returns the old one @see{C-error}.
28022803@apii{nargs+1,nresults,e}
28032804
28042805Calls a function.
2806+ Like regular Lua calls,
2807+ @id{lua_call} respects the @idx{__call} metamethod.
2808+ So, here the word @Q{function}
2809+ means any callable value.
28052810
28062811To do a call you must use the following protocol:
2807- first, the value to be called is pushed onto the stack;
2812+ first, the function to be called is pushed onto the stack;
28082813then, the arguments to the call are pushed
28092814in direct order;
28102815that is, the first argument is pushed first.
28112816Finally you call @Lid{lua_call};
28122817@id{nargs} is the number of arguments that you pushed onto the stack.
28132818When the function returns,
28142819all arguments and the function value are popped
2815- and the function results are pushed onto the stack.
2820+ and the call results are pushed onto the stack.
28162821The number of results is adjusted to @id{nresults},
28172822unless @id{nresults} is @defid{LUA_MULTRET}.
28182823In this case, all results from the function are pushed;
@@ -2824,8 +2829,6 @@ so that after the call the last result is on the top of the stack.
28242829
28252830Any error while calling and running the function is propagated upwards
28262831(with a @id{longjmp}).
2827- Like regular Lua calls,
2828- this function respects the @idx{__call} metamethod.
28292832
28302833The following example shows how the host program can do the
28312834equivalent to this Lua code:
@@ -3971,7 +3974,8 @@ leaves the error object on the top of the stack,
39713974Starts and resumes a coroutine in the given thread @id{L}.
39723975
39733976To start a coroutine,
3974- you push onto the thread stack the main function plus any arguments;
3977+ you push the main function plus any arguments
3978+ onto the empty stack of the thread.
39753979then you call @Lid{lua_resume},
39763980with @id{nargs} being the number of arguments.
39773981This call returns when the coroutine suspends or finishes its execution.
@@ -3988,8 +3992,9 @@ or an error code in case of errors @seeC{lua_pcall}.
39883992In case of errors,
39893993the error object is on the top of the stack.
39903994
3991- To resume a coroutine, you clear its stack,
3992- push only the values to be passed as results from @id{yield},
3995+ To resume a coroutine,
3996+ you remove the @id{*nresults} yielded values from its stack,
3997+ push the values to be passed as results from @id{yield},
39933998and then call @Lid{lua_resume}.
39943999
39954000The parameter @id{from} represents the coroutine that is resuming @id{L}.
@@ -4152,7 +4157,7 @@ and returns the total size of the string,
41524157that is, its length plus one.
41534158The conversion can result in an integer or a float,
41544159according to the lexical conventions of Lua @see{lexical}.
4155- The string may have leading and trailing spaces and a sign.
4160+ The string may have leading and trailing whitespaces and a sign.
41564161If the string is not a valid numeral,
41574162returns 0 and pushes nothing.
41584163(Note that the result can be used as a boolean,
@@ -5791,7 +5796,7 @@ The field @id{closef} points to a Lua function
57915796that will be called to close the stream
57925797when the handle is closed or collected;
57935798this function receives the file handle as its sole argument and
5794- must return either @ true, in case of success,
5799+ must return either a true value , in case of success,
57955800or a false value plus an error message, in case of error.
57965801Once Lua calls this field,
57975802it changes the field value to @id{NULL}
@@ -5914,12 +5919,12 @@ to its expected parameters.
59145919For instance, a function documented as @T{foo(arg)}
59155920should not be called without an argument.
59165921
5917- The notation @fail means a return value representing
5918- some kind of failure or the absence of a better value to return .
5919- Currently, @fail is equal to @nil,
5922+ The notation @fail means a false value representing
5923+ some kind of failure.
5924+ ( Currently, @fail is equal to @nil,
59205925but that may change in future versions.
59215926The recommendation is to always test the success of these functions
5922- with @T{(not status)}, instead of @T{(status == nil)}.
5927+ with @T{(not status)}, instead of @T{(status == nil)}.)
59235928
59245929
59255930Currently, Lua has the following standard libraries:
@@ -6338,19 +6343,25 @@ the function returns @fail.
63386343}
63396344
63406345@LibEntry{tostring (v)|
6346+
63416347Receives a value of any type and
63426348converts it to a string in a human-readable format.
6343- (For complete control of how numbers are converted,
6344- use @Lid{string.format}.)
63456349
63466350If the metatable of @id{v} has a @idx{__tostring} field,
63476351then @id{tostring} calls the corresponding value
63486352with @id{v} as argument,
63496353and uses the result of the call as its result.
6354+ Otherwise, if the metatable of @id{v} has a @idx{__name} field
6355+ with a string value,
6356+ @id{tostring} may use that string in its final result.
6357+
6358+ For complete control of how numbers are converted,
6359+ use @Lid{string.format}.
63506360
63516361}
63526362
63536363@LibEntry{type (v)|
6364+
63546365Returns the type of its only argument, coded as a string.
63556366The possible results of this function are
63566367@St{nil} (a string, not the value @nil),
@@ -6599,7 +6610,8 @@ Default is @Char{-}.}
65996610
66006611@LibEntry{package.cpath|
66016612
6602- The path used by @Lid{require} to search for a @N{C loader}.
6613+ A string with the path used by @Lid{require}
6614+ to search for a @N{C loader}.
66036615
66046616Lua initializes the @N{C path} @Lid{package.cpath} in the same way
66056617it initializes the Lua path @Lid{package.path},
@@ -6656,7 +6668,8 @@ plus other Unix systems that support the @id{dlfcn} standard).
66566668
66576669@LibEntry{package.path|
66586670
6659- The path used by @Lid{require} to search for a Lua loader.
6671+ A string with the path used by @Lid{require}
6672+ to search for a Lua loader.
66606673
66616674At start-up, Lua initializes this variable with
66626675the value of the environment variable @defid{LUA_PATH_5_4} or
@@ -7397,7 +7410,7 @@ coded as an unsigned integer with @id{n} bytes
73977410@item{@T{X@rep{op}}|an empty item that aligns
73987411according to option @id{op}
73997412(which is otherwise ignored)}
7400- @item{@Char{ }|(empty space) ignored}
7413+ @item{@Char{ }|(space) ignored}
74017414}
74027415(A @St{[@rep{n}]} means an optional integral numeral.)
74037416Except for padding, spaces, and configurations
@@ -8106,7 +8119,7 @@ The available formats are
81068119@item{@St{n}|
81078120reads a numeral and returns it as a float or an integer,
81088121following the lexical conventions of Lua.
8109- (The numeral may have leading spaces and a sign.)
8122+ (The numeral may have leading whitespaces and a sign.)
81108123This format always reads the longest input sequence that
81118124is a valid prefix for a numeral;
81128125if that prefix does not form a valid numeral
@@ -8594,7 +8607,7 @@ This function has the following restrictions:
85948607@item{@id{limit} cannot be less than the amount of C stack in use.}
85958608}
85968609If a call does not respect some restriction,
8597- it returns a falsy value.
8610+ it returns a false value.
85988611Otherwise,
85998612the call returns the old limit.
86008613
@@ -8736,15 +8749,15 @@ lua [options] [script [args]]
87368749}
87378750The options are:
87388751@description{
8739- @item{@T{-e @rep{stat}}| executes string @rep{stat};}
8740- @item{@T{-l @rep{mod}}| @Q{requires} @rep{mod} and assigns the
8752+ @item{@T{-e @rep{stat}}| execute string @rep{stat};}
8753+ @item{@T{-i}| enter interactive mode after running @rep{script};}
8754+ @item{@T{-l @rep{mod}}| @Q{require} @rep{mod} and assign the
87418755 result to global @rep{mod};}
8742- @item{@T{-i}| enters interactive mode after running @rep{script};}
8743- @item{@T{-v}| prints version information;}
8744- @item{@T{-E}| ignores environment variables;}
8756+ @item{@T{-v}| print version information;}
8757+ @item{@T{-E}| ignore environment variables;}
87458758@item{@T{-W}| turn warnings on;}
8746- @item{@T{--}| stops handling options;}
8747- @item{@T{-}| executes @id{stdin} as a file and stops handling options.}
8759+ @item{@T{--}| stop handling options;}
8760+ @item{@T{-}| execute @id{stdin} as a file and stop handling options.}
87488761}
87498762After handling its options, @id{lua} runs the given @emph{script}.
87508763When called without arguments,
@@ -8761,12 +8774,10 @@ then @id{lua} executes the file.
87618774Otherwise, @id{lua} executes the string itself.
87628775
87638776When called with the option @T{-E},
8764- besides ignoring @id{LUA_INIT},
8765- Lua also ignores
8766- the values of @id{LUA_PATH} and @id{LUA_CPATH},
8767- setting the values of
8768- @Lid{package.path} and @Lid{package.cpath}
8769- with the default paths defined in @id{luaconf.h}.
8777+ Lua does not consult any environment variables.
8778+ In particular,
8779+ the values of @Lid{package.path} and @Lid{package.cpath}
8780+ are set with the default paths defined in @id{luaconf.h}.
87708781
87718782The options @T{-e}, @T{-l}, and @T{-W} are handled in
87728783the order they appear.
0 commit comments