aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-29 11:47:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-29 11:47:12 -0300
commitbef250eb8d44ba58fa04f82df7550a79b068d2d0 (patch)
tree62c7ca754b529b907c701e93a1e8f364904a7907
parentba81adaad9a72530d1ac81149a1fdd154b010b06 (diff)
downloadlua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.gz
lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.bz2
lua-bef250eb8d44ba58fa04f82df7550a79b068d2d0.zip
Details
Comments and small improvements in the manual.
-rw-r--r--lobject.h2
-rw-r--r--lopcodes.h21
-rw-r--r--lstate.c2
-rw-r--r--ltablib.c2
-rw-r--r--manual/manual.of21
5 files changed, 32 insertions, 16 deletions
diff --git a/lobject.h b/lobject.h
index 950bebbd..a1b45543 100644
--- a/lobject.h
+++ b/lobject.h
@@ -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_); \
diff --git a/lopcodes.h b/lopcodes.h
index d6a47e5a..7c274515 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -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
196typedef enum { 197typedef enum {
@@ -203,7 +204,7 @@ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */
203OP_LOADK,/* A Bx R[A] := K[Bx] */ 204OP_LOADK,/* A Bx R[A] := K[Bx] */
204OP_LOADKX,/* A R[A] := K[extra arg] */ 205OP_LOADKX,/* A R[A] := K[extra arg] */
205OP_LOADFALSE,/* A R[A] := false */ 206OP_LOADFALSE,/* A R[A] := false */
206OP_LFALSESKIP,/*A R[A] := false; pc++ */ 207OP_LFALSESKIP,/*A R[A] := false; pc++ (*) */
207OP_LOADTRUE,/* A R[A] := true */ 208OP_LOADTRUE,/* A R[A] := true */
208OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ 209OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */
209OP_GETUPVAL,/* A B R[A] := UpValue[B] */ 210OP_GETUPVAL,/* A B R[A] := UpValue[B] */
@@ -254,7 +255,7 @@ OP_BXOR,/* A B C R[A] := R[B] ~ R[C] */
254OP_SHL,/* A B C R[A] := R[B] << R[C] */ 255OP_SHL,/* A B C R[A] := R[B] << R[C] */
255OP_SHR,/* A B C R[A] := R[B] >> R[C] */ 256OP_SHR,/* A B C R[A] := R[B] >> R[C] */
256 257
257OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */ 258OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] (*) */
258OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ 259OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */
259OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */ 260OP_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++ */
280OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ 281OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */
281 282
282OP_TEST,/* A k if (not R[A] == k) then pc++ */ 283OP_TEST,/* A k if (not R[A] == k) then pc++ */
283OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */ 284OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] (*) */
284 285
285OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ 286OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */
286OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */ 287OP_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'.
diff --git a/lstate.c b/lstate.c
index c5e3b437..bfc59026 100644
--- a/lstate.c
+++ b/lstate.c
@@ -269,7 +269,7 @@ static void preinit_thread (lua_State *L, global_State *g) {
269static void close_state (lua_State *L) { 269static 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 */
diff --git a/ltablib.c b/ltablib.c
index d80eb801..dbfe2509 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -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
5915on top of the library table. 5915on top of the library table.
5916These values are popped from the stack after the registration. 5916These values are popped from the stack after the registration.
5917 5917
5918A function with a @id{NULL} value represents a placeholder,
5919which 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;
6397instead, @id{pcall} catches the error 6400instead, @id{pcall} catches the error
6398and returns a status code. 6401and returns a status code.
6399Its first result is the status code (a boolean), 6402Its first result is the status code (a boolean),
6400which is true if the call succeeds without errors. 6403which is @true if the call succeeds without errors.
6401In such case, @id{pcall} also returns all results from the call, 6404In such case, @id{pcall} also returns all results from the call,
6402after this first result. 6405after this first result.
6403In case of any error, @id{pcall} returns @false plus the error object. 6406In 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
6606Returns true when the coroutine @id{co} can yield. 6609Returns @true when the coroutine @id{co} can yield.
6607The default for @id{co} is the running coroutine. 6610The default for @id{co} is the running coroutine.
6608 6611
6609A coroutine is yieldable if it is not the main thread and 6612A 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
6637Returns the running coroutine plus a boolean, 6640Returns the running coroutine plus a boolean,
6638true 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]}.
6731If the loader does not return a non-nil value and 6734If the loader does not return a non-nil value and
6732has not assigned any value to @T{package.loaded[modname]}, 6735has not assigned any value to @T{package.loaded[modname]},
6733then @id{require} assigns @Rw{true} to this entry. 6736then @id{require} assigns @true to this entry.
6734In any case, @id{require} returns the 6737In any case, @id{require} returns the
6735final value of @T{package.loaded[modname]}. 6738final value of @T{package.loaded[modname]}.
6736Besides that value, @id{require} also returns as a second result 6739Besides that value, @id{require} also returns as a second result
@@ -7051,7 +7054,7 @@ otherwise, it returns @fail.
7051A third, optional numeric argument @id{init} specifies 7054A third, optional numeric argument @id{init} specifies
7052where to start the search; 7055where to start the search;
7053its default value @N{is 1} and can be negative. 7056its default value @N{is 1} and can be negative.
7054A value of @true as a fourth, optional argument @id{plain} 7057A @true as a fourth, optional argument @id{plain}
7055turns off the pattern matching facilities, 7058turns off the pattern matching facilities,
7056so the function does a plain @Q{find substring} operation, 7059so the function does a plain @Q{find substring} operation,
7057with no characters in @id{pattern} being considered magic. 7060with 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
8079Returns a boolean, 8082Returns a boolean,
8080true 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
8081they are compared as @x{unsigned integers}. 8084they 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
8492Calls the @ANSI{exit} to terminate the host program. 8495Calls the @ANSI{exit} to terminate the host program.
8493If @id{code} is @Rw{true}, 8496If @id{code} is @true,
8494the returned status is @idx{EXIT_SUCCESS}; 8497the returned status is @idx{EXIT_SUCCESS};
8495if @id{code} is @Rw{false}, 8498if @id{code} is @false,
8496the returned status is @idx{EXIT_FAILURE}; 8499the returned status is @idx{EXIT_FAILURE};
8497if @id{code} is a number, 8500if @id{code} is a number,
8498the returned status is this number. 8501the returned status is this number.
8499The default value for @id{code} is @Rw{true}. 8502The default value for @id{code} is @true.
8500 8503
8501If the optional second argument @id{close} is true, 8504If the optional second argument @id{close} is true,
8502closes the Lua state before exiting. 8505closes the Lua state before exiting.