summaryrefslogtreecommitdiff
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-github-bef250eb8d44ba58fa04f82df7550a79b068d2d0.tar.gz
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 {
#define settt_(o,t) ((o)->tt_=(t))
-/* main macro to copy values (from 'obj1' to 'obj2') */
+/* main macro to copy values (from 'obj2' to 'obj1') */
#define setobj(L,obj1,obj2) \
{ TValue *io1=(obj1); const TValue *io2=(obj2); \
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 */
/*
-** grep "ORDER OP" if you change these enums
+** Grep "ORDER OP" if you change these enums. Opcodes marked with a (*)
+** has extra descriptions in the notes after the enumeration.
*/
typedef enum {
@@ -203,7 +204,7 @@ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */
OP_LOADK,/* A Bx R[A] := K[Bx] */
OP_LOADKX,/* A R[A] := K[extra arg] */
OP_LOADFALSE,/* A R[A] := false */
-OP_LFALSESKIP,/*A R[A] := false; pc++ */
+OP_LFALSESKIP,/*A R[A] := false; pc++ (*) */
OP_LOADTRUE,/* A R[A] := true */
OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */
OP_GETUPVAL,/* A B R[A] := UpValue[B] */
@@ -254,7 +255,7 @@ OP_BXOR,/* A B C R[A] := R[B] ~ R[C] */
OP_SHL,/* A B C R[A] := R[B] << R[C] */
OP_SHR,/* A B C R[A] := R[B] >> R[C] */
-OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */
+OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] (*) */
OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */
OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */
@@ -280,7 +281,7 @@ OP_GTI,/* A sB k if ((R[A] > sB) ~= k) then pc++ */
OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */
OP_TEST,/* A k if (not R[A] == k) then pc++ */
-OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */
+OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] (*) */
OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */
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 */
/*===========================================================================
Notes:
+
+ (*) Opcode OP_LFALSESKIP is used to convert a condition to a boolean
+ value, in a code equivalent to (not cond ? false : true). (It
+ produces false and skips the next instruction producing true.)
+
+ (*) Opcodes OP_MMBIN and variants follow each arithmetic and
+ bitwise opcode. If the operation succeeds, it skips this next
+ opcode. Otherwise, this opcode calls the corresponding metamethod.
+
+ (*) Opcode OP_TESTSET is used in short-circuit expressions that need
+ both to jump and to produce a value, such as (a = b or c).
+
(*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then
'top' is set to last_result+1, so next open instruction (OP_CALL,
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) {
static void close_state (lua_State *L) {
global_State *g = G(L);
if (!completestate(g)) /* closing a partially built state? */
- luaC_freeallobjects(L); /* jucst collect its objects */
+ luaC_freeallobjects(L); /* just collect its objects */
else { /* closing a fully built state */
luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */
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) {
lua_geti(L, 1, i);
if (l_unlikely(!lua_isstring(L, -1)))
luaL_error(L, "invalid value (%s) at index %I in table for 'concat'",
- luaL_typename(L, -1), i);
+ luaL_typename(L, -1), (LUAI_UACINT)i);
luaL_addvalue(b);
}
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
on top of the library table.
These values are popped from the stack after the registration.
+A function with a @id{NULL} value represents a placeholder,
+which is filled with @false.
+
}
@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;
instead, @id{pcall} catches the error
and returns a status code.
Its first result is the status code (a boolean),
-which is true if the call succeeds without errors.
+which is @true if the call succeeds without errors.
In such case, @id{pcall} also returns all results from the call,
after this first result.
In case of any error, @id{pcall} returns @false plus the error object.
@@ -6603,7 +6606,7 @@ an object with type @T{"thread"}.
@LibEntry{coroutine.isyieldable ([co])|
-Returns true when the coroutine @id{co} can yield.
+Returns @true when the coroutine @id{co} can yield.
The default for @id{co} is the running coroutine.
A coroutine is yieldable if it is not the main thread and
@@ -6635,7 +6638,7 @@ If there is any error,
@LibEntry{coroutine.running ()|
Returns the running coroutine plus a boolean,
-true when the running coroutine is the main one.
+@true when the running coroutine is the main one.
}
@@ -6730,7 +6733,7 @@ If the loader returns any non-nil value,
@id{require} assigns the returned value to @T{package.loaded[modname]}.
If the loader does not return a non-nil value and
has not assigned any value to @T{package.loaded[modname]},
-then @id{require} assigns @Rw{true} to this entry.
+then @id{require} assigns @true to this entry.
In any case, @id{require} returns the
final value of @T{package.loaded[modname]}.
Besides that value, @id{require} also returns as a second result
@@ -7051,7 +7054,7 @@ otherwise, it returns @fail.
A third, optional numeric argument @id{init} specifies
where to start the search;
its default value @N{is 1} and can be negative.
-A value of @true as a fourth, optional argument @id{plain}
+A @true as a fourth, optional argument @id{plain}
turns off the pattern matching facilities,
so the function does a plain @Q{find substring} operation,
with no characters in @id{pattern} being considered magic.
@@ -8077,7 +8080,7 @@ or @fail if @id{x} is not a number.
@LibEntry{math.ult (m, n)|
Returns a boolean,
-true if and only if integer @id{m} is below integer @id{n} when
+@true if and only if integer @id{m} is below integer @id{n} when
they are compared as @x{unsigned integers}.
}
@@ -8490,13 +8493,13 @@ When called without a @id{command},
@LibEntry{os.exit ([code [, close]])|
Calls the @ANSI{exit} to terminate the host program.
-If @id{code} is @Rw{true},
+If @id{code} is @true,
the returned status is @idx{EXIT_SUCCESS};
-if @id{code} is @Rw{false},
+if @id{code} is @false,
the returned status is @idx{EXIT_FAILURE};
if @id{code} is a number,
the returned status is this number.
-The default value for @id{code} is @Rw{true}.
+The default value for @id{code} is @true.
If the optional second argument @id{close} is true,
closes the Lua state before exiting.