summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-04-10 15:44:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-04-10 15:44:48 -0300
commit7ccc6d8290143009d2bab8f4330bbf443fc25846 (patch)
treee59c44cccd98d725bc7fe9b4ad2d85420dc04802
parent7288528a1e081d101a1bc19346a974088b6b8315 (diff)
downloadlua-7ccc6d8290143009d2bab8f4330bbf443fc25846.tar.gz
lua-7ccc6d8290143009d2bab8f4330bbf443fc25846.tar.bz2
lua-7ccc6d8290143009d2bab8f4330bbf443fc25846.zip
Improvements in the manual
Several small improvements, in particular a new subsection consolidating all status codes in the API.
-rw-r--r--manual/manual.of110
1 files changed, 64 insertions, 46 deletions
diff --git a/manual/manual.of b/manual/manual.of
index d5b4a572..3ba82b09 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -96,6 +96,14 @@ is particularly attractive
96for small machines and embedded systems. 96for small machines and embedded systems.
97(See macro @id{LUA_32BITS} in file @id{luaconf.h}.) 97(See macro @id{LUA_32BITS} in file @id{luaconf.h}.)
98 98
99Unless stated otherwise,
100any overflow when manipulating integer values @def{wrap around},
101according to the usual rules of two-complement arithmetic.
102(In other words,
103the actual result is the unique representable integer
104that is equal modulo @M{2@sp{n}} to the mathematical result,
105where @M{n} is the number of bits of the integer type.)
106
99Lua has explicit rules about when each subtype is used, 107Lua has explicit rules about when each subtype is used,
100but it also converts between them automatically as needed @see{coercion}. 108but it also converts between them automatically as needed @see{coercion}.
101Therefore, 109Therefore,
@@ -1098,8 +1106,11 @@ if its value fits in an integer or it is a hexadecimal constant,
1098it denotes an integer; 1106it denotes an integer;
1099otherwise (that is, a decimal integer numeral that overflows), 1107otherwise (that is, a decimal integer numeral that overflows),
1100it denotes a float. 1108it denotes a float.
1101(Hexadecimal integer numerals that overflow @emph{wrap around}; 1109Hexadecimal numerals with neither a radix point nor an exponent
1102they always denote an integer value.) 1110always denote an integer value;
1111if the value overflows, it @emph{wraps around}
1112to fit into a valid integer.
1113
1103Examples of valid integer constants are 1114Examples of valid integer constants are
1104@verbatim{ 1115@verbatim{
11053 345 0xff 0xBEBADA 11163 345 0xff 0xBEBADA
@@ -1712,12 +1723,7 @@ Modulo is defined as the remainder of a division
1712that rounds the quotient towards minus infinity (floor division). 1723that rounds the quotient towards minus infinity (floor division).
1713 1724
1714In case of overflows in integer arithmetic, 1725In case of overflows in integer arithmetic,
1715all operations @emphx{wrap around}, 1726all operations @emphx{wrap around}.
1716according to the usual rules of two-complement arithmetic.
1717(In other words,
1718they return the unique representable integer
1719that is equal modulo @M{2@sp{n}} to the mathematical result,
1720where @M{n} is the number of bits of the integer type.)
1721} 1727}
1722 1728
1723@sect3{bitwise| @title{Bitwise Operators} 1729@sect3{bitwise| @title{Bitwise Operators}
@@ -2364,9 +2370,8 @@ and
2364(that is, the element at @N{the top}) 2370(that is, the element at @N{the top})
2365and index @M{-n} represents the first element. 2371and index @M{-n} represents the first element.
2366 2372
2367}
2368 2373
2369@sect2{stacksize| @title{Stack Size} 2374@sect3{stacksize| @title{Stack Size}
2370 2375
2371When you interact with the Lua API, 2376When you interact with the Lua API,
2372you are responsible for ensuring consistency. 2377you are responsible for ensuring consistency.
@@ -2391,7 +2396,7 @@ you should use @Lid{lua_checkstack}.
2391 2396
2392} 2397}
2393 2398
2394@sect2{@title{Valid and Acceptable Indices} 2399@sect3{@title{Valid and Acceptable Indices}
2395 2400
2396Any function in the API that receives stack indices 2401Any function in the API that receives stack indices
2397works only with @emphx{valid indices} or @emphx{acceptable indices}. 2402works only with @emphx{valid indices} or @emphx{acceptable indices}.
@@ -2433,6 +2438,8 @@ which behaves like a nil value.
2433 2438
2434} 2439}
2435 2440
2441}
2442
2436@sect2{c-closure| @title{C Closures} 2443@sect2{c-closure| @title{C Closures}
2437 2444
2438When a @N{C function} is created, 2445When a @N{C function} is created,
@@ -2552,6 +2559,33 @@ However, there is no guarantee about stack space.
2552To push anything on the stack, 2559To push anything on the stack,
2553the panic function must first check the available space @see{stacksize}. 2560the panic function must first check the available space @see{stacksize}.
2554 2561
2562
2563@sect3{statuscodes|@title{Status Codes}
2564
2565Several functions that report errors in the API use the following
2566status codes to indicate different kinds of errors or other conditions:
2567@description{
2568
2569@item{@defid{LUA_OK} (0)| no errors.}
2570
2571@item{@defid{LUA_ERRRUN}| a runtime error.}
2572
2573@item{@defid{LUA_ERRMEM}|
2574@x{memory allocation error}.
2575For such errors, Lua does not call the @x{message handler}.
2576}
2577
2578@item{@defid{LUA_ERRERR}| error while running the @x{message handler}.}
2579
2580@item{@defid{LUA_ERRSYNTAX}| syntax error during precompilation.}
2581
2582@item{@defid{LUA_YIELD}| the thread (coroutine) yields.}
2583
2584}
2585These constants are defined in the header file @id{lua.h}.
2586
2587}
2588
2555} 2589}
2556 2590
2557@sect2{continuations|@title{Handling Yields in C} 2591@sect2{continuations|@title{Handling Yields in C}
@@ -3407,19 +3441,6 @@ If there are no errors,
3407function on top of the stack. 3441function on top of the stack.
3408Otherwise, it pushes an error message. 3442Otherwise, it pushes an error message.
3409 3443
3410The return values of @id{lua_load} are:
3411@description{
3412
3413@item{@Lid{LUA_OK}| no errors;}
3414
3415@item{@defid{LUA_ERRSYNTAX}|
3416syntax error during precompilation;}
3417
3418@item{@Lid{LUA_ERRMEM}|
3419@x{memory allocation (out-of-memory) error};}
3420
3421}
3422
3423The @id{lua_load} function uses a user-supplied @id{reader} function 3444The @id{lua_load} function uses a user-supplied @id{reader} function
3424to read the chunk @seeC{lua_Reader}. 3445to read the chunk @seeC{lua_Reader}.
3425The @id{data} argument is an opaque value passed to the reader function. 3446The @id{data} argument is an opaque value passed to the reader function.
@@ -3437,6 +3458,11 @@ a @id{NULL} value is equivalent to the string @St{bt}.
3437so the reader function must always leave the stack 3458so the reader function must always leave the stack
3438unmodified when returning. 3459unmodified when returning.
3439 3460
3461@id{lua_load} can return
3462@Lid{LUA_OK}, @Lid{LUA_ERRSYNTAX}, or @Lid{LUA_ERRMEM}.
3463The function may also return other values corresponding to
3464errors raised by the read function @see{statuscodes}.
3465
3440If the resulting function has upvalues, 3466If the resulting function has upvalues,
3441its first upvalue is set to the value of the @x{global environment} 3467its first upvalue is set to the value of the @x{global environment}
3442stored at index @id{LUA_RIDX_GLOBALS} in the registry @see{registry}. 3468stored at index @id{LUA_RIDX_GLOBALS} in the registry @see{registry}.
@@ -3590,25 +3616,8 @@ information to the error object, such as a stack traceback.
3590Such information cannot be gathered after the return of @Lid{lua_pcall}, 3616Such information cannot be gathered after the return of @Lid{lua_pcall},
3591since by then the stack has unwound. 3617since by then the stack has unwound.
3592 3618
3593The @Lid{lua_pcall} function returns one of the following constants 3619The @Lid{lua_pcall} function returns one of the following status codes:
3594(defined in @id{lua.h}): 3620@Lid{LUA_OK}, @Lid{LUA_ERRRUN}, @Lid{LUA_ERRMEM}, or @Lid{LUA_ERRERR}.
3595@description{
3596
3597@item{@defid{LUA_OK} (0)|
3598success.}
3599
3600@item{@defid{LUA_ERRRUN}|
3601a runtime error.
3602}
3603
3604@item{@defid{LUA_ERRMEM}|
3605@x{memory allocation error}.
3606For such errors, Lua does not call the @x{message handler}.
3607}
3608
3609@item{@defid{LUA_ERRERR}|
3610error while running the @x{message handler}.
3611}
3612 3621
3613} 3622}
3614 3623
@@ -3624,7 +3633,7 @@ int lua_pcallk (lua_State *L,
3624@apii{nargs + 1,nresults|1,-} 3633@apii{nargs + 1,nresults|1,-}
3625 3634
3626This function behaves exactly like @Lid{lua_pcall}, 3635This function behaves exactly like @Lid{lua_pcall},
3627but allows the called function to yield @see{continuations}. 3636except that it allows the called function to yield @see{continuations}.
3628 3637
3629} 3638}
3630 3639
@@ -4002,7 +4011,7 @@ or returned by the body function.
4002@Lid{LUA_YIELD} if the coroutine yields, 4011@Lid{LUA_YIELD} if the coroutine yields,
4003@Lid{LUA_OK} if the coroutine finishes its execution 4012@Lid{LUA_OK} if the coroutine finishes its execution
4004without errors, 4013without errors,
4005or an error code in case of errors @seeC{lua_pcall}. 4014or an error code in case of errors @see{statuscodes}.
4006In case of errors, 4015In case of errors,
4007the error object is on the top of the stack. 4016the error object is on the top of the stack.
4008 4017
@@ -4153,7 +4162,7 @@ Returns the status of the thread @id{L}.
4153The status can be @Lid{LUA_OK} for a normal thread, 4162The status can be @Lid{LUA_OK} for a normal thread,
4154an error code if the thread finished the execution 4163an error code if the thread finished the execution
4155of a @Lid{lua_resume} with an error, 4164of a @Lid{lua_resume} with an error,
4156or @defid{LUA_YIELD} if the thread is suspended. 4165or @Lid{LUA_YIELD} if the thread is suspended.
4157 4166
4158You can call functions only in threads with status @Lid{LUA_OK}. 4167You can call functions only in threads with status @Lid{LUA_OK}.
4159You can resume threads with status @Lid{LUA_OK} 4168You can resume threads with status @Lid{LUA_OK}
@@ -6263,6 +6272,7 @@ which is true if the call succeeds without errors.
6263In such case, @id{pcall} also returns all results from the call, 6272In such case, @id{pcall} also returns all results from the call,
6264after this first result. 6273after this first result.
6265In case of any error, @id{pcall} returns @false plus the error object. 6274In case of any error, @id{pcall} returns @false plus the error object.
6275Note that errors caught by @id{pcall} do not call a message handler.
6266 6276
6267} 6277}
6268 6278
@@ -8950,6 +8960,14 @@ not a float.
8950} 8960}
8951 8961
8952@item{ 8962@item{
8963Literal decimal integer constants that overflow are read as floats,
8964instead of wrapping around.
8965You can use hexadecimal notation for such constants if you
8966want the old bevhavior
8967(reading them as integers with wrap around).
8968}
8969
8970@item{
8953The use of the @idx{__lt} metamethod to emulate @id{__le} 8971The use of the @idx{__lt} metamethod to emulate @id{__le}
8954has been removed. 8972has been removed.
8955When needed, this metamethod must be explicitly defined. 8973When needed, this metamethod must be explicitly defined.