Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c32d93

Browse files
committed
Several enhancements in the manual
1 parent 6e285e5 commit 4c32d93

File tree

1 file changed

+54
-43
lines changed

1 file changed

+54
-43
lines changed

manual/manual.of

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ whose main property is to be different from any other value;
8282
it often represents the absence of a useful value.
8383
The type @emph{boolean} has two values, @false and @true.
8484
Both @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

8788
The type @emph{number} represents both
8889
integer numbers and real (floating-point) numbers,
@@ -278,9 +279,9 @@ so, an error inside the message handler
278279
will call the message handler again.
279280
If this loop goes on for too long,
280281
Lua 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.
282283
It 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

285286
Lua also offers a system of @emph{warnings} @seeF{warn}.
286287
Unlike errors, warnings do not interfere
@@ -467,7 +468,7 @@ Behavior similar to the less than operation.
467468
The indexing access operation @T{table[key]}.
468469
This event happens when @id{table} is not a table or
469470
when @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

472473
Despite the name,
473474
the 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:
528529
and @idx{__name}.
529530
(The entry @idx{__name},
530531
when 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

533534
For the unary operators (negation, length, and bitwise NOT),
534535
the metamethod is computed and called with a dummy second operand,
@@ -638,7 +639,7 @@ In generational mode,
638639
the collector does frequent @emph{minor} collections,
639640
which traverses only objects recently created.
640641
If 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,
642643
which traverses all objects.
643644
The generational mode uses two parameters:
644645
the @def{minor multiplier} and the @def{the major multiplier}.
@@ -943,7 +944,7 @@ Lua is a @x{free-form} language.
943944
It ignores spaces and comments between lexical elements (@x{tokens}),
944945
except as delimiters between two tokens.
945946
In source code,
946-
Lua recognizes as spaces the standard ASCII white-space
947+
Lua recognizes as spaces the standard ASCII whitespace
947948
characters space, form feed, newline,
948949
carriage return, horizontal tab, and vertical tab.
949950

@@ -998,7 +999,7 @@ and @Char{\'} (apostrophe [single quote]).
998999
A backslash followed by a line break
9991000
results in a newline in the string.
10001001
The escape sequence @Char{\z} skips the following span
1001-
of white-space characters,
1002+
of whitespace characters,
10021003
including line breaks;
10031004
it is particularly useful to break and indent a long literal string
10041005
into multiple lines without adding the newlines and spaces
@@ -1769,7 +1770,7 @@ Otherwise, the conversion fails.
17691770
Several places in Lua coerce strings to numbers when necessary.
17701771
A string is converted to an integer or a float
17711772
following 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.)
17731774
All conversions from strings to numbers
17741775
accept both a dot and the current locale mark
17751776
as the radix character.
@@ -2182,7 +2183,7 @@ function r() return 1,2,3 end
21822183
Then, we have the following mapping from arguments to parameters and
21832184
to the vararg expression:
21842185
@verbatim{
2185-
CALL PARAMETERS
2186+
CALL PARAMETERS
21862187

21872188
f(3) a=3, b=nil
21882189
f(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

28042805
Calls 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

28062811
To 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;
28082813
then, the arguments to the call are pushed
28092814
in direct order;
28102815
that is, the first argument is pushed first.
28112816
Finally you call @Lid{lua_call};
28122817
@id{nargs} is the number of arguments that you pushed onto the stack.
28132818
When the function returns,
28142819
all 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.
28162821
The number of results is adjusted to @id{nresults},
28172822
unless @id{nresults} is @defid{LUA_MULTRET}.
28182823
In 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

28252830
Any 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

28302833
The following example shows how the host program can do the
28312834
equivalent to this Lua code:
@@ -3971,7 +3974,8 @@ leaves the error object on the top of the stack,
39713974
Starts and resumes a coroutine in the given thread @id{L}.
39723975

39733976
To 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.
39753979
then you call @Lid{lua_resume},
39763980
with @id{nargs} being the number of arguments.
39773981
This 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}.
39883992
In case of errors,
39893993
the 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},
39933998
and then call @Lid{lua_resume}.
39943999

39954000
The parameter @id{from} represents the coroutine that is resuming @id{L}.
@@ -4152,7 +4157,7 @@ and returns the total size of the string,
41524157
that is, its length plus one.
41534158
The conversion can result in an integer or a float,
41544159
according 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.
41564161
If the string is not a valid numeral,
41574162
returns 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
57915796
that will be called to close the stream
57925797
when the handle is closed or collected;
57935798
this 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,
57955800
or a false value plus an error message, in case of error.
57965801
Once Lua calls this field,
57975802
it changes the field value to @id{NULL}
@@ -5914,12 +5919,12 @@ to its expected parameters.
59145919
For instance, a function documented as @T{foo(arg)}
59155920
should 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,
59205925
but that may change in future versions.
59215926
The 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

59255930
Currently, Lua has the following standard libraries:
@@ -6338,19 +6343,25 @@ the function returns @fail.
63386343
}
63396344

63406345
@LibEntry{tostring (v)|
6346+
63416347
Receives a value of any type and
63426348
converts it to a string in a human-readable format.
6343-
(For complete control of how numbers are converted,
6344-
use @Lid{string.format}.)
63456349

63466350
If the metatable of @id{v} has a @idx{__tostring} field,
63476351
then @id{tostring} calls the corresponding value
63486352
with @id{v} as argument,
63496353
and 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+
63546365
Returns the type of its only argument, coded as a string.
63556366
The 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

66046616
Lua initializes the @N{C path} @Lid{package.cpath} in the same way
66056617
it 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

66616674
At start-up, Lua initializes this variable with
66626675
the 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
73987411
according 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.)
74037416
Except for padding, spaces, and configurations
@@ -8106,7 +8119,7 @@ The available formats are
81068119
@item{@St{n}|
81078120
reads a numeral and returns it as a float or an integer,
81088121
following 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.)
81108123
This format always reads the longest input sequence that
81118124
is a valid prefix for a numeral;
81128125
if 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
}
85968609
If a call does not respect some restriction,
8597-
it returns a falsy value.
8610+
it returns a false value.
85988611
Otherwise,
85998612
the call returns the old limit.
86008613

@@ -8736,15 +8749,15 @@ lua [options] [script [args]]
87368749
}
87378750
The 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
}
87498762
After handling its options, @id{lua} runs the given @emph{script}.
87508763
When called without arguments,
@@ -8761,12 +8774,10 @@ then @id{lua} executes the file.
87618774
Otherwise, @id{lua} executes the string itself.
87628775

87638776
When 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

87718782
The options @T{-e}, @T{-l}, and @T{-W} are handled in
87728783
the order they appear.

0 commit comments

Comments
 (0)