aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-16 14:58:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-16 14:58:02 -0300
commitb96b0b5abbf40cbdbed7952bf35a5a27ddf75928 (patch)
tree5d9d5463cb7d3424833abab20dd87bce1f4b240f /manual
parentca13be9af784b7288d3a07d9b5bccb329086e885 (diff)
downloadlua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.tar.gz
lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.tar.bz2
lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.zip
Added macro 'luaL_pushfail'
The macro 'luaL_pushfail' documents all places in the standard libraries that return nil to signal some kind of failure. It is defined as 'lua_pushnil'. The manual also got a notation (@fail) to document those returns. The tests were changed to be agnostic regarding whether 'fail' is 'nil' or 'false'.
Diffstat (limited to 'manual')
-rwxr-xr-xmanual/2html1
-rw-r--r--manual/manual.of87
2 files changed, 52 insertions, 36 deletions
diff --git a/manual/2html b/manual/2html
index 605c6e59..a300f8d4 100755
--- a/manual/2html
+++ b/manual/2html
@@ -324,6 +324,7 @@ N = function (s) return (string.gsub(s, " ", "&nbsp;")) end,
324NE = id, -- tag"foreignphrase", 324NE = id, -- tag"foreignphrase",
325num = id, 325num = id,
326["nil"] = fixed(Tag.b"nil"), 326["nil"] = fixed(Tag.b"nil"),
327fail = fixed(Tag.b"fail"),
327Open = fixed"{", 328Open = fixed"{",
328part = section("h1", true), 329part = section("h1", true),
329Pat = compose(verbfixed, prepos("'", "'")), 330Pat = compose(verbfixed, prepos("'", "'")),
diff --git a/manual/manual.of b/manual/manual.of
index bb6ae884..53073a54 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -4058,12 +4058,15 @@ Returns 0 if the userdata does not have that value.
4058 4058
4059} 4059}
4060 4060
4061@APIEntry{void lua_setmetatable (lua_State *L, int index);| 4061@APIEntry{int lua_setmetatable (lua_State *L, int index);|
4062@apii{1,0,-} 4062@apii{1,0,-}
4063 4063
4064Pops a table from the stack and 4064Pops a table from the stack and
4065sets it as the new metatable for the value at the given index. 4065sets it as the new metatable for the value at the given index.
4066 4066
4067(For historical reasons, this function returns an @id{int},
4068which now is always 1.)
4069
4067} 4070}
4068 4071
4069@APIEntry{void lua_settable (lua_State *L, int index);| 4072@APIEntry{void lua_settable (lua_State *L, int index);|
@@ -5782,7 +5785,7 @@ that will be called to close the stream
5782when the handle is closed or collected; 5785when the handle is closed or collected;
5783this function receives the file handle as its sole argument and 5786this function receives the file handle as its sole argument and
5784must return either @true, in case of success, 5787must return either @true, in case of success,
5785or @nil plus an error message, in case of error. 5788or a false value plus an error message, in case of error.
5786Once Lua calls this field, 5789Once Lua calls this field,
5787it changes the field value to @id{NULL} 5790it changes the field value to @id{NULL}
5788to signal that the handle is closed. 5791to signal that the handle is closed.
@@ -5904,6 +5907,14 @@ to its expected parameters.
5904For instance, a function documented as @T{foo(arg)} 5907For instance, a function documented as @T{foo(arg)}
5905should not be called without an argument. 5908should not be called without an argument.
5906 5909
5910The notation @fail means a return value representing
5911some kind of failure or the absence of a better value to return.
5912Currently, @fail is equal to @nil,
5913but that may change in future versions.
5914The recommendation is to test the success of these functions
5915with @T{(not status)}, instead of @T{(status == nil)}.
5916
5917
5907Currently, Lua has the following standard libraries: 5918Currently, Lua has the following standard libraries:
5908@itemize{ 5919@itemize{
5909 5920
@@ -6108,8 +6119,8 @@ with previous results.
6108A return of an empty string, @nil, or no value signals the end of the chunk. 6119A return of an empty string, @nil, or no value signals the end of the chunk.
6109 6120
6110If there are no syntactic errors, 6121If there are no syntactic errors,
6111returns the compiled chunk as a function; 6122@id{load} returns the compiled chunk as a function;
6112otherwise, returns @nil plus the error message. 6123otherwise, it returns @fail plus the error message.
6113 6124
6114When you load a main chunk, 6125When you load a main chunk,
6115the resulting function will always have exactly one upvalue, 6126the resulting function will always have exactly one upvalue,
@@ -6301,7 +6312,7 @@ When called with no @id{base},
6301If the argument is already a number or 6312If the argument is already a number or
6302a string convertible to a number, 6313a string convertible to a number,
6303then @id{tonumber} returns this number; 6314then @id{tonumber} returns this number;
6304otherwise, it returns @nil. 6315otherwise, it returns @fail.
6305 6316
6306The conversion of strings can result in integers or floats, 6317The conversion of strings can result in integers or floats,
6307according to the lexical conventions of Lua @see{lexical}. 6318according to the lexical conventions of Lua @see{lexical}.
@@ -6315,7 +6326,7 @@ In bases @N{above 10}, the letter @Char{A} (in either upper or lower case)
6315@N{represents 10}, @Char{B} @N{represents 11}, and so forth, 6326@N{represents 10}, @Char{B} @N{represents 11}, and so forth,
6316with @Char{Z} representing 35. 6327with @Char{Z} representing 35.
6317If the string @id{e} is not a valid numeral in the given base, 6328If the string @id{e} is not a valid numeral in the given base,
6318the function returns @nil. 6329the function returns @fail.
6319 6330
6320} 6331}
6321 6332
@@ -6762,7 +6773,7 @@ will try to open the files
6762 6773
6763Returns the resulting name of the first file that it can 6774Returns the resulting name of the first file that it can
6764open in read mode (after closing the file), 6775open in read mode (after closing the file),
6765or @nil plus an error message if none succeeds. 6776or @fail plus an error message if none succeeds.
6766(This error message lists all file names it tried to open.) 6777(This error message lists all file names it tried to open.)
6767 6778
6768} 6779}
@@ -6841,7 +6852,7 @@ Looks for the first match of
6841@id{pattern} @see{pm} in the string @id{s}. 6852@id{pattern} @see{pm} in the string @id{s}.
6842If it finds a match, then @id{find} returns the indices @N{of @T{s}} 6853If it finds a match, then @id{find} returns the indices @N{of @T{s}}
6843where this occurrence starts and ends; 6854where this occurrence starts and ends;
6844otherwise, it returns @nil. 6855otherwise, it returns @fail.
6845A third, optional numeric argument @id{init} specifies 6856A third, optional numeric argument @id{init} specifies
6846where to start the search; 6857where to start the search;
6847its default value @N{is 1} and can be negative. 6858its default value @N{is 1} and can be negative.
@@ -7034,7 +7045,7 @@ Looks for the first @emph{match} of
7034the @id{pattern} @see{pm} in the string @id{s}. 7045the @id{pattern} @see{pm} in the string @id{s}.
7035If it finds one, then @id{match} returns 7046If it finds one, then @id{match} returns
7036the captures from the pattern; 7047the captures from the pattern;
7037otherwise it returns @nil. 7048otherwise it returns @fail.
7038If @id{pattern} specifies no captures, 7049If @id{pattern} specifies no captures,
7039then the whole match is returned. 7050then the whole match is returned.
7040A third, optional numeric argument @id{init} specifies 7051A third, optional numeric argument @id{init} specifies
@@ -7499,7 +7510,7 @@ Returns the number of UTF-8 characters in string @id{s}
7499that start between positions @id{i} and @id{j} (both inclusive). 7510that start between positions @id{i} and @id{j} (both inclusive).
7500The default for @id{i} is @num{1} and for @id{j} is @num{-1}. 7511The default for @id{i} is @num{1} and for @id{j} is @num{-1}.
7501If it finds any invalid byte sequence, 7512If it finds any invalid byte sequence,
7502returns a false value plus the position of the first invalid byte. 7513returns @fail plus the position of the first invalid byte.
7503 7514
7504} 7515}
7505 7516
@@ -7515,7 +7526,7 @@ so that @T{utf8.offset(s, -n)} gets the offset of the
7515@id{n}-th character from the end of the string. 7526@id{n}-th character from the end of the string.
7516If the specified character is neither in the subject 7527If the specified character is neither in the subject
7517nor right after its end, 7528nor right after its end,
7518the function returns @nil. 7529the function returns @fail.
7519 7530
7520As a special case, 7531As a special case,
7521when @id{n} is 0 the function returns the start of the encoding 7532when @id{n} is 0 the function returns the start of the encoding
@@ -7850,7 +7861,7 @@ Returns the tangent of @id{x} (assumed to be in radians).
7850 7861
7851If the value @id{x} is convertible to an integer, 7862If the value @id{x} is convertible to an integer,
7852returns that integer. 7863returns that integer.
7853Otherwise, returns @nil. 7864Otherwise, returns @fail.
7854 7865
7855} 7866}
7856 7867
@@ -7858,7 +7869,7 @@ Otherwise, returns @nil.
7858 7869
7859Returns @St{integer} if @id{x} is an integer, 7870Returns @St{integer} if @id{x} is an integer,
7860@St{float} if it is a float, 7871@St{float} if it is a float,
7861or @nil if @id{x} is not a number. 7872or @fail if @id{x} is not a number.
7862 7873
7863} 7874}
7864 7875
@@ -7897,10 +7908,10 @@ three predefined file handles with their usual meanings from C:
7897The I/O library never closes these files. 7908The I/O library never closes these files.
7898 7909
7899Unless otherwise stated, 7910Unless otherwise stated,
7900all I/O functions return @nil on failure, 7911all I/O functions return @fail on failure,
7901plus an error message as a second result and 7912plus an error message as a second result and
7902a system-dependent error code as a third result, 7913a system-dependent error code as a third result,
7903and some value different from @nil on success. 7914and some non-false value on success.
7904On non-POSIX systems, 7915On non-POSIX systems,
7905the computation of the error message and error code 7916the computation of the error message and error code
7906in case of errors 7917in case of errors
@@ -8021,7 +8032,7 @@ and it is automatically removed when the program ends.
8021Checks whether @id{obj} is a valid file handle. 8032Checks whether @id{obj} is a valid file handle.
8022Returns the string @T{"file"} if @id{obj} is an open file handle, 8033Returns the string @T{"file"} if @id{obj} is an open file handle,
8023@T{"closed file"} if @id{obj} is a closed file handle, 8034@T{"closed file"} if @id{obj} is a closed file handle,
8024or @nil if @id{obj} is not a file handle. 8035or @fail if @id{obj} is not a file handle.
8025 8036
8026} 8037}
8027 8038
@@ -8075,7 +8086,7 @@ Reads the file @id{file},
8075according to the given formats, which specify what to read. 8086according to the given formats, which specify what to read.
8076For each format, 8087For each format,
8077the function returns a string or a number with the characters read, 8088the function returns a string or a number with the characters read,
8078or @nil if it cannot read data with the specified format. 8089or @fail if it cannot read data with the specified format.
8079(In this latter case, 8090(In this latter case,
8080the function does not read subsequent formats.) 8091the function does not read subsequent formats.)
8081When called without arguments, 8092When called without arguments,
@@ -8094,31 +8105,32 @@ is a valid prefix for a numeral;
8094if that prefix does not form a valid numeral 8105if that prefix does not form a valid numeral
8095(e.g., an empty string, @St{0x}, or @St{3.4e-}) 8106(e.g., an empty string, @St{0x}, or @St{3.4e-})
8096or it is too long (more than 200 characters), 8107or it is too long (more than 200 characters),
8097it is discarded and the format returns @nil. 8108it is discarded and the format returns @fail.
8098} 8109}
8099 8110
8100@item{@St{a}| 8111@item{@St{a}|
8101reads the whole file, starting at the current position. 8112reads the whole file, starting at the current position.
8102On end of file, it returns the empty string. 8113On end of file, it returns the empty string;
8114this format never fails.
8103} 8115}
8104 8116
8105@item{@St{l}| 8117@item{@St{l}|
8106reads the next line skipping the end of line, 8118reads the next line skipping the end of line,
8107returning @nil on end of file. 8119returning @fail on end of file.
8108This is the default format. 8120This is the default format.
8109} 8121}
8110 8122
8111@item{@St{L}| 8123@item{@St{L}|
8112reads the next line keeping the end-of-line character (if present), 8124reads the next line keeping the end-of-line character (if present),
8113returning @nil on end of file. 8125returning @fail on end of file.
8114} 8126}
8115 8127
8116@item{@emph{number}| 8128@item{@emph{number}|
8117reads a string with up to this number of bytes, 8129reads a string with up to this number of bytes,
8118returning @nil on end of file. 8130returning @fail on end of file.
8119If @id{number} is zero, 8131If @id{number} is zero,
8120it reads nothing and returns an empty string, 8132it reads nothing and returns an empty string,
8121or @nil on end of file. 8133or @fail on end of file.
8122} 8134}
8123 8135
8124} 8136}
@@ -8139,7 +8151,7 @@ specified by the string @id{whence}, as follows:
8139} 8151}
8140In case of success, @id{seek} returns the final file position, 8152In case of success, @id{seek} returns the final file position,
8141measured in bytes from the beginning of the file. 8153measured in bytes from the beginning of the file.
8142If @id{seek} fails, it returns @nil, 8154If @id{seek} fails, it returns @fail,
8143plus a string describing the error. 8155plus a string describing the error.
8144 8156
8145The default value for @id{whence} is @T{"cur"}, 8157The default value for @id{whence} is @T{"cur"},
@@ -8179,7 +8191,6 @@ Writes the value of each of its arguments to @id{file}.
8179The arguments must be strings or numbers. 8191The arguments must be strings or numbers.
8180 8192
8181In case of success, this function returns @id{file}. 8193In case of success, this function returns @id{file}.
8182Otherwise it returns @nil plus a string describing the error.
8183 8194
8184} 8195}
8185 8196
@@ -8251,7 +8262,7 @@ This function is equivalent to the @ANSI{system}.
8251It passes @id{command} to be executed by an operating system shell. 8262It passes @id{command} to be executed by an operating system shell.
8252Its first result is @true 8263Its first result is @true
8253if the command terminated successfully, 8264if the command terminated successfully,
8254or @nil otherwise. 8265or @fail otherwise.
8255After this first result 8266After this first result
8256the function returns a string plus a number, 8267the function returns a string plus a number,
8257as follows: 8268as follows:
@@ -8293,7 +8304,7 @@ closes the Lua state before exiting.
8293@LibEntry{os.getenv (varname)| 8304@LibEntry{os.getenv (varname)|
8294 8305
8295Returns the value of the process environment variable @id{varname}, 8306Returns the value of the process environment variable @id{varname},
8296or @nil if the variable is not defined. 8307or @fail if the variable is not defined.
8297 8308
8298} 8309}
8299 8310
@@ -8301,7 +8312,7 @@ or @nil if the variable is not defined.
8301 8312
8302Deletes the file (or empty directory, on @x{POSIX} systems) 8313Deletes the file (or empty directory, on @x{POSIX} systems)
8303with the given name. 8314with the given name.
8304If this function fails, it returns @nil, 8315If this function fails, it returns @fail
8305plus a string describing the error and the error code. 8316plus a string describing the error and the error code.
8306Otherwise, it returns true. 8317Otherwise, it returns true.
8307 8318
@@ -8310,7 +8321,7 @@ Otherwise, it returns true.
8310@LibEntry{os.rename (oldname, newname)| 8321@LibEntry{os.rename (oldname, newname)|
8311 8322
8312Renames the file or directory named @id{oldname} to @id{newname}. 8323Renames the file or directory named @id{oldname} to @id{newname}.
8313If this function fails, it returns @nil, 8324If this function fails, it returns @fail,
8314plus a string describing the error and the error code. 8325plus a string describing the error and the error code.
8315Otherwise, it returns true. 8326Otherwise, it returns true.
8316 8327
@@ -8325,7 +8336,7 @@ Sets the current locale of the program.
8325@T{"monetary"}, @T{"numeric"}, or @T{"time"}; 8336@T{"monetary"}, @T{"numeric"}, or @T{"time"};
8326the default category is @T{"all"}. 8337the default category is @T{"all"}.
8327The function returns the name of the new locale, 8338The function returns the name of the new locale,
8328or @nil if the request cannot be honored. 8339or @fail if the request cannot be honored.
8329 8340
8330If @id{locale} is the empty string, 8341If @id{locale} is the empty string,
8331the current locale is set to an implementation-defined native locale. 8342the current locale is set to an implementation-defined native locale.
@@ -8444,6 +8455,8 @@ the current hook function, the current hook mask,
8444and the current hook count, 8455and the current hook count,
8445as set by the @Lid{debug.sethook} function. 8456as set by the @Lid{debug.sethook} function.
8446 8457
8458Returns @fail if there is no active hook.
8459
8447} 8460}
8448 8461
8449@LibEntry{debug.getinfo ([thread,] f [, what])| 8462@LibEntry{debug.getinfo ([thread,] f [, what])|
@@ -8458,7 +8471,7 @@ of the given thread:
8458(except for tail calls, which do not count on the stack); 8471(except for tail calls, which do not count on the stack);
8459and so on. 8472and so on.
8460If @id{f} is a number greater than the number of active functions, 8473If @id{f} is a number greater than the number of active functions,
8461then @id{getinfo} returns @nil. 8474then @id{getinfo} returns @fail.
8462 8475
8463The returned table can contain all the fields returned by @Lid{lua_getinfo}, 8476The returned table can contain all the fields returned by @Lid{lua_getinfo},
8464with the string @id{what} describing which fields to fill in. 8477with the string @id{what} describing which fields to fill in.
@@ -8496,7 +8509,8 @@ Compile-time constants may not appear in this listing,
8496if they were optimized away by the compiler. 8509if they were optimized away by the compiler.
8497Negative indices refer to vararg arguments; 8510Negative indices refer to vararg arguments;
8498@num{-1} is the first vararg argument. 8511@num{-1} is the first vararg argument.
8499The function returns @nil if there is no variable with the given index, 8512The function returns @fail
8513if there is no variable with the given index,
8500and raises an error when called with a level out of range. 8514and raises an error when called with a level out of range.
8501(You can call @Lid{debug.getinfo} to check whether the level is valid.) 8515(You can call @Lid{debug.getinfo} to check whether the level is valid.)
8502 8516
@@ -8527,7 +8541,8 @@ Returns the registry table @see{registry}.
8527 8541
8528This function returns the name and the value of the upvalue 8542This function returns the name and the value of the upvalue
8529with index @id{up} of the function @id{f}. 8543with index @id{up} of the function @id{f}.
8530The function returns @nil if there is no upvalue with the given index. 8544The function returns @fail
8545if there is no upvalue with the given index.
8531 8546
8532(For Lua functions, 8547(For Lua functions,
8533upvalues are the external local variables that the function uses, 8548upvalues are the external local variables that the function uses,
@@ -8615,7 +8630,7 @@ and @N{level 1} is the hook function.)
8615 8630
8616This function assigns the value @id{value} to the local variable 8631This function assigns the value @id{value} to the local variable
8617with index @id{local} of the function at level @id{level} of the stack. 8632with index @id{local} of the function at level @id{level} of the stack.
8618The function returns @nil if there is no local 8633The function returns @fail if there is no local
8619variable with the given index, 8634variable with the given index,
8620and raises an error when called with a @id{level} out of range. 8635and raises an error when called with a @id{level} out of range.
8621(You can call @id{getinfo} to check whether the level is valid.) 8636(You can call @id{getinfo} to check whether the level is valid.)
@@ -8638,7 +8653,7 @@ Returns @id{value}.
8638 8653
8639This function assigns the value @id{value} to the upvalue 8654This function assigns the value @id{value} to the upvalue
8640with index @id{up} of the function @id{f}. 8655with index @id{up} of the function @id{f}.
8641The function returns @nil if there is no upvalue 8656The function returns @fail if there is no upvalue
8642with the given index. 8657with the given index.
8643Otherwise, it returns the name of the upvalue. 8658Otherwise, it returns the name of the upvalue.
8644 8659
@@ -8653,7 +8668,7 @@ the @id{n}-th user value associated to the given @id{udata}.
8653@id{udata} must be a full userdata. 8668@id{udata} must be a full userdata.
8654 8669
8655Returns @id{udata}, 8670Returns @id{udata},
8656or @nil if the userdata does not have that value. 8671or @fail if the userdata does not have that value.
8657 8672
8658} 8673}
8659 8674