diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-29 11:47:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-29 11:47:12 -0300 |
commit | bef250eb8d44ba58fa04f82df7550a79b068d2d0 (patch) | |
tree | 62c7ca754b529b907c701e93a1e8f364904a7907 | |
parent | ba81adaad9a72530d1ac81149a1fdd154b010b06 (diff) | |
download | lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.gz lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.bz2 lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.zip |
Details
Comments and small improvements in the manual.
-rw-r--r-- | lobject.h | 2 | ||||
-rw-r--r-- | lopcodes.h | 21 | ||||
-rw-r--r-- | lstate.c | 2 | ||||
-rw-r--r-- | ltablib.c | 2 | ||||
-rw-r--r-- | manual/manual.of | 21 |
5 files changed, 32 insertions, 16 deletions
@@ -112,7 +112,7 @@ typedef struct TValue { | |||
112 | #define settt_(o,t) ((o)->tt_=(t)) | 112 | #define settt_(o,t) ((o)->tt_=(t)) |
113 | 113 | ||
114 | 114 | ||
115 | /* main macro to copy values (from 'obj1' to 'obj2') */ | 115 | /* main macro to copy values (from 'obj2' to 'obj1') */ |
116 | #define setobj(L,obj1,obj2) \ | 116 | #define setobj(L,obj1,obj2) \ |
117 | { TValue *io1=(obj1); const TValue *io2=(obj2); \ | 117 | { TValue *io1=(obj1); const TValue *io2=(obj2); \ |
118 | io1->value_ = io2->value_; settt_(io1, io2->tt_); \ | 118 | io1->value_ = io2->value_; settt_(io1, io2->tt_); \ |
@@ -190,7 +190,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
190 | 190 | ||
191 | 191 | ||
192 | /* | 192 | /* |
193 | ** grep "ORDER OP" if you change these enums | 193 | ** Grep "ORDER OP" if you change these enums. Opcodes marked with a (*) |
194 | ** has extra descriptions in the notes after the enumeration. | ||
194 | */ | 195 | */ |
195 | 196 | ||
196 | typedef enum { | 197 | typedef enum { |
@@ -203,7 +204,7 @@ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ | |||
203 | OP_LOADK,/* A Bx R[A] := K[Bx] */ | 204 | OP_LOADK,/* A Bx R[A] := K[Bx] */ |
204 | OP_LOADKX,/* A R[A] := K[extra arg] */ | 205 | OP_LOADKX,/* A R[A] := K[extra arg] */ |
205 | OP_LOADFALSE,/* A R[A] := false */ | 206 | OP_LOADFALSE,/* A R[A] := false */ |
206 | OP_LFALSESKIP,/*A R[A] := false; pc++ */ | 207 | OP_LFALSESKIP,/*A R[A] := false; pc++ (*) */ |
207 | OP_LOADTRUE,/* A R[A] := true */ | 208 | OP_LOADTRUE,/* A R[A] := true */ |
208 | OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ | 209 | OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ |
209 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ | 210 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ |
@@ -254,7 +255,7 @@ OP_BXOR,/* A B C R[A] := R[B] ~ R[C] */ | |||
254 | OP_SHL,/* A B C R[A] := R[B] << R[C] */ | 255 | OP_SHL,/* A B C R[A] := R[B] << R[C] */ |
255 | OP_SHR,/* A B C R[A] := R[B] >> R[C] */ | 256 | OP_SHR,/* A B C R[A] := R[B] >> R[C] */ |
256 | 257 | ||
257 | OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */ | 258 | OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] (*) */ |
258 | OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ | 259 | OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ |
259 | OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */ | 260 | OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */ |
260 | 261 | ||
@@ -280,7 +281,7 @@ OP_GTI,/* A sB k if ((R[A] > sB) ~= k) then pc++ */ | |||
280 | OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ | 281 | OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ |
281 | 282 | ||
282 | OP_TEST,/* A k if (not R[A] == k) then pc++ */ | 283 | OP_TEST,/* A k if (not R[A] == k) then pc++ */ |
283 | OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */ | 284 | OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] (*) */ |
284 | 285 | ||
285 | OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ | 286 | OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ |
286 | OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */ | 287 | OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */ |
@@ -315,6 +316,18 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
315 | 316 | ||
316 | /*=========================================================================== | 317 | /*=========================================================================== |
317 | Notes: | 318 | Notes: |
319 | |||
320 | (*) Opcode OP_LFALSESKIP is used to convert a condition to a boolean | ||
321 | value, in a code equivalent to (not cond ? false : true). (It | ||
322 | produces false and skips the next instruction producing true.) | ||
323 | |||
324 | (*) Opcodes OP_MMBIN and variants follow each arithmetic and | ||
325 | bitwise opcode. If the operation succeeds, it skips this next | ||
326 | opcode. Otherwise, this opcode calls the corresponding metamethod. | ||
327 | |||
328 | (*) Opcode OP_TESTSET is used in short-circuit expressions that need | ||
329 | both to jump and to produce a value, such as (a = b or c). | ||
330 | |||
318 | (*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then | 331 | (*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then |
319 | 'top' is set to last_result+1, so next open instruction (OP_CALL, | 332 | 'top' is set to last_result+1, so next open instruction (OP_CALL, |
320 | OP_RETURN*, OP_SETLIST) may use 'top'. | 333 | OP_RETURN*, OP_SETLIST) may use 'top'. |
@@ -269,7 +269,7 @@ static void preinit_thread (lua_State *L, global_State *g) { | |||
269 | static void close_state (lua_State *L) { | 269 | static void close_state (lua_State *L) { |
270 | global_State *g = G(L); | 270 | global_State *g = G(L); |
271 | if (!completestate(g)) /* closing a partially built state? */ | 271 | if (!completestate(g)) /* closing a partially built state? */ |
272 | luaC_freeallobjects(L); /* jucst collect its objects */ | 272 | luaC_freeallobjects(L); /* just collect its objects */ |
273 | else { /* closing a fully built state */ | 273 | else { /* closing a fully built state */ |
274 | luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */ | 274 | luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */ |
275 | luaC_freeallobjects(L); /* collect all objects */ | 275 | luaC_freeallobjects(L); /* collect all objects */ |
@@ -147,7 +147,7 @@ static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) { | |||
147 | lua_geti(L, 1, i); | 147 | lua_geti(L, 1, i); |
148 | if (l_unlikely(!lua_isstring(L, -1))) | 148 | if (l_unlikely(!lua_isstring(L, -1))) |
149 | luaL_error(L, "invalid value (%s) at index %I in table for 'concat'", | 149 | luaL_error(L, "invalid value (%s) at index %I in table for 'concat'", |
150 | luaL_typename(L, -1), i); | 150 | luaL_typename(L, -1), (LUAI_UACINT)i); |
151 | luaL_addvalue(b); | 151 | luaL_addvalue(b); |
152 | } | 152 | } |
153 | 153 | ||
diff --git a/manual/manual.of b/manual/manual.of index c69970d2..2a837b5e 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -5915,6 +5915,9 @@ previously pushed on the stack | |||
5915 | on top of the library table. | 5915 | on top of the library table. |
5916 | These values are popped from the stack after the registration. | 5916 | These values are popped from the stack after the registration. |
5917 | 5917 | ||
5918 | A function with a @id{NULL} value represents a placeholder, | ||
5919 | which is filled with @false. | ||
5920 | |||
5918 | } | 5921 | } |
5919 | 5922 | ||
5920 | @APIEntry{void luaL_setmetatable (lua_State *L, const char *tname);| | 5923 | @APIEntry{void luaL_setmetatable (lua_State *L, const char *tname);| |
@@ -6397,7 +6400,7 @@ This means that any error @N{inside @T{f}} is not propagated; | |||
6397 | instead, @id{pcall} catches the error | 6400 | instead, @id{pcall} catches the error |
6398 | and returns a status code. | 6401 | and returns a status code. |
6399 | Its first result is the status code (a boolean), | 6402 | Its first result is the status code (a boolean), |
6400 | which is true if the call succeeds without errors. | 6403 | which is @true if the call succeeds without errors. |
6401 | In such case, @id{pcall} also returns all results from the call, | 6404 | In such case, @id{pcall} also returns all results from the call, |
6402 | after this first result. | 6405 | after this first result. |
6403 | In case of any error, @id{pcall} returns @false plus the error object. | 6406 | In case of any error, @id{pcall} returns @false plus the error object. |
@@ -6603,7 +6606,7 @@ an object with type @T{"thread"}. | |||
6603 | 6606 | ||
6604 | @LibEntry{coroutine.isyieldable ([co])| | 6607 | @LibEntry{coroutine.isyieldable ([co])| |
6605 | 6608 | ||
6606 | Returns true when the coroutine @id{co} can yield. | 6609 | Returns @true when the coroutine @id{co} can yield. |
6607 | The default for @id{co} is the running coroutine. | 6610 | The default for @id{co} is the running coroutine. |
6608 | 6611 | ||
6609 | A coroutine is yieldable if it is not the main thread and | 6612 | A coroutine is yieldable if it is not the main thread and |
@@ -6635,7 +6638,7 @@ If there is any error, | |||
6635 | @LibEntry{coroutine.running ()| | 6638 | @LibEntry{coroutine.running ()| |
6636 | 6639 | ||
6637 | Returns the running coroutine plus a boolean, | 6640 | Returns the running coroutine plus a boolean, |
6638 | true when the running coroutine is the main one. | 6641 | @true when the running coroutine is the main one. |
6639 | 6642 | ||
6640 | } | 6643 | } |
6641 | 6644 | ||
@@ -6730,7 +6733,7 @@ If the loader returns any non-nil value, | |||
6730 | @id{require} assigns the returned value to @T{package.loaded[modname]}. | 6733 | @id{require} assigns the returned value to @T{package.loaded[modname]}. |
6731 | If the loader does not return a non-nil value and | 6734 | If the loader does not return a non-nil value and |
6732 | has not assigned any value to @T{package.loaded[modname]}, | 6735 | has not assigned any value to @T{package.loaded[modname]}, |
6733 | then @id{require} assigns @Rw{true} to this entry. | 6736 | then @id{require} assigns @true to this entry. |
6734 | In any case, @id{require} returns the | 6737 | In any case, @id{require} returns the |
6735 | final value of @T{package.loaded[modname]}. | 6738 | final value of @T{package.loaded[modname]}. |
6736 | Besides that value, @id{require} also returns as a second result | 6739 | Besides that value, @id{require} also returns as a second result |
@@ -7051,7 +7054,7 @@ otherwise, it returns @fail. | |||
7051 | A third, optional numeric argument @id{init} specifies | 7054 | A third, optional numeric argument @id{init} specifies |
7052 | where to start the search; | 7055 | where to start the search; |
7053 | its default value @N{is 1} and can be negative. | 7056 | its default value @N{is 1} and can be negative. |
7054 | A value of @true as a fourth, optional argument @id{plain} | 7057 | A @true as a fourth, optional argument @id{plain} |
7055 | turns off the pattern matching facilities, | 7058 | turns off the pattern matching facilities, |
7056 | so the function does a plain @Q{find substring} operation, | 7059 | so the function does a plain @Q{find substring} operation, |
7057 | with no characters in @id{pattern} being considered magic. | 7060 | with no characters in @id{pattern} being considered magic. |
@@ -8077,7 +8080,7 @@ or @fail if @id{x} is not a number. | |||
8077 | @LibEntry{math.ult (m, n)| | 8080 | @LibEntry{math.ult (m, n)| |
8078 | 8081 | ||
8079 | Returns a boolean, | 8082 | Returns a boolean, |
8080 | true if and only if integer @id{m} is below integer @id{n} when | 8083 | @true if and only if integer @id{m} is below integer @id{n} when |
8081 | they are compared as @x{unsigned integers}. | 8084 | they are compared as @x{unsigned integers}. |
8082 | 8085 | ||
8083 | } | 8086 | } |
@@ -8490,13 +8493,13 @@ When called without a @id{command}, | |||
8490 | @LibEntry{os.exit ([code [, close]])| | 8493 | @LibEntry{os.exit ([code [, close]])| |
8491 | 8494 | ||
8492 | Calls the @ANSI{exit} to terminate the host program. | 8495 | Calls the @ANSI{exit} to terminate the host program. |
8493 | If @id{code} is @Rw{true}, | 8496 | If @id{code} is @true, |
8494 | the returned status is @idx{EXIT_SUCCESS}; | 8497 | the returned status is @idx{EXIT_SUCCESS}; |
8495 | if @id{code} is @Rw{false}, | 8498 | if @id{code} is @false, |
8496 | the returned status is @idx{EXIT_FAILURE}; | 8499 | the returned status is @idx{EXIT_FAILURE}; |
8497 | if @id{code} is a number, | 8500 | if @id{code} is a number, |
8498 | the returned status is this number. | 8501 | the returned status is this number. |
8499 | The default value for @id{code} is @Rw{true}. | 8502 | The default value for @id{code} is @true. |
8500 | 8503 | ||
8501 | If the optional second argument @id{close} is true, | 8504 | If the optional second argument @id{close} is true, |
8502 | closes the Lua state before exiting. | 8505 | closes the Lua state before exiting. |