Browse Source

Details

Corrections in comments and manual. Added note in the manual about
local variables in the REPL.
Roberto Ierusalimschy 1 year ago
parent
commit
262dc5729a
9 changed files with 36 additions and 21 deletions
  1. 1 1
      lauxlib.c
  2. 1 1
      lgc.c
  3. 1 1
      lgc.h
  4. 1 1
      lstate.h
  5. 2 2
      lua.c
  6. 1 1
      luaconf.h
  7. 4 4
      lvm.c
  8. 23 9
      manual/manual.of
  9. 2 1
      testes/pm.lua

+ 1 - 1
lauxlib.c

@@ -1044,7 +1044,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
 
 
 
 
 /*
 /*
-** Standard panic funcion just prints an error message. The test
+** Standard panic function just prints an error message. The test
 ** with 'lua_type' avoids possible memory errors in 'lua_tostring'.
 ** with 'lua_type' avoids possible memory errors in 'lua_tostring'.
 */
 */
 static int panic (lua_State *L) {
 static int panic (lua_State *L) {

+ 1 - 1
lgc.c

@@ -1541,7 +1541,7 @@ static void sweepstep (lua_State *L, global_State *g,
 ** object.) When 'fast' is true, 'singlestep' tries to finish a state
 ** object.) When 'fast' is true, 'singlestep' tries to finish a state
 ** "as fast as possible". In particular, it skips the propagation
 ** "as fast as possible". In particular, it skips the propagation
 ** phase and leaves all objects to be traversed by the atomic phase:
 ** phase and leaves all objects to be traversed by the atomic phase:
-** That avoids traversing twice some objects, such as theads and
+** That avoids traversing twice some objects, such as threads and
 ** weak tables.
 ** weak tables.
 */
 */
 static l_obj singlestep (lua_State *L, int fast) {
 static l_obj singlestep (lua_State *L, int fast) {

+ 1 - 1
lgc.h

@@ -135,7 +135,7 @@
 **
 **
 ** To keep its invariants, the generational mode uses the same barriers
 ** To keep its invariants, the generational mode uses the same barriers
 ** also used by the incremental mode. If a young object is caught in a
 ** also used by the incremental mode. If a young object is caught in a
-** foward barrier, it cannot become old immediately, because it can
+** forward barrier, it cannot become old immediately, because it can
 ** still point to other young objects. Instead, it becomes 'old0',
 ** still point to other young objects. Instead, it becomes 'old0',
 ** which in the next cycle becomes 'old1'. So, 'old0' objects is
 ** which in the next cycle becomes 'old1'. So, 'old0' objects is
 ** old but can point to new and survival objects; 'old1' is old
 ** old but can point to new and survival objects; 'old1' is old

+ 1 - 1
lstate.h

@@ -259,7 +259,7 @@ typedef struct global_State {
   l_obj totalobjs;  /* total number of objects allocated + GCdebt */
   l_obj totalobjs;  /* total number of objects allocated + GCdebt */
   l_obj GCdebt;  /* objects counted but not yet allocated */
   l_obj GCdebt;  /* objects counted but not yet allocated */
   l_obj marked;  /* number of objects marked in a GC cycle */
   l_obj marked;  /* number of objects marked in a GC cycle */
-  l_obj GCmajorminor;  /* auxiliar counter to control major-minor shifts */
+  l_obj GCmajorminor;  /* auxiliary counter to control major-minor shifts */
   stringtable strt;  /* hash table for strings */
   stringtable strt;  /* hash table for strings */
   TValue l_registry;
   TValue l_registry;
   TValue nilvalue;  /* a nil value */
   TValue nilvalue;  /* a nil value */

+ 2 - 2
lua.c

@@ -211,7 +211,7 @@ static int dostring (lua_State *L, const char *s, const char *name) {
 /*
 /*
 ** Receives 'globname[=modname]' and runs 'globname = require(modname)'.
 ** Receives 'globname[=modname]' and runs 'globname = require(modname)'.
 ** If there is no explicit modname and globname contains a '-', cut
 ** If there is no explicit modname and globname contains a '-', cut
-** the sufix after '-' (the "version") to make the global name.
+** the suffix after '-' (the "version") to make the global name.
 */
 */
 static int dolibrary (lua_State *L, char *globname) {
 static int dolibrary (lua_State *L, char *globname) {
   int status;
   int status;
@@ -230,7 +230,7 @@ static int dolibrary (lua_State *L, char *globname) {
   status = docall(L, 1, 1);  /* call 'require(modname)' */
   status = docall(L, 1, 1);  /* call 'require(modname)' */
   if (status == LUA_OK) {
   if (status == LUA_OK) {
     if (suffix != NULL)  /* is there a suffix mark? */
     if (suffix != NULL)  /* is there a suffix mark? */
-      *suffix = '\0';  /* remove sufix from global name */
+      *suffix = '\0';  /* remove suffix from global name */
     lua_setglobal(L, globname);  /* globname = require(modname) */
     lua_setglobal(L, globname);  /* globname = require(modname) */
   }
   }
   return report(L, status);
   return report(L, status);

+ 1 - 1
luaconf.h

@@ -261,7 +261,7 @@
 /*
 /*
 ** LUA_IGMARK is a mark to ignore all after it when building the
 ** LUA_IGMARK is a mark to ignore all after it when building the
 ** module name (e.g., used to build the luaopen_ function name).
 ** module name (e.g., used to build the luaopen_ function name).
-** Typically, the sufix after the mark is the module version,
+** Typically, the suffix after the mark is the module version,
 ** as in "mod-v1.2.so".
 ** as in "mod-v1.2.so".
 */
 */
 #define LUA_IGMARK		"-"
 #define LUA_IGMARK		"-"

+ 4 - 4
lvm.c

@@ -92,10 +92,10 @@ static int l_strton (const TValue *obj, TValue *result) {
   if (!cvt2num(obj))  /* is object not a string? */
   if (!cvt2num(obj))  /* is object not a string? */
     return 0;
     return 0;
   else {
   else {
-  TString *st = tsvalue(obj);
-  size_t stlen;
-  const char *s = getlstr(st, stlen);
-  return (luaO_str2num(s, result) == stlen + 1);
+    TString *st = tsvalue(obj);
+    size_t stlen;
+    const char *s = getlstr(st, stlen);
+    return (luaO_str2num(s, result) == stlen + 1);
   }
   }
 }
 }
 
 

+ 23 - 9
manual/manual.of

@@ -289,7 +289,7 @@ Whenever there is an error,
 an @def{error object}
 an @def{error object}
 is propagated with information about the error.
 is propagated with information about the error.
 Lua itself only generates errors whose error object is a string,
 Lua itself only generates errors whose error object is a string,
-but programs may generate errors with
+but programs can generate errors with
 any value as the error object.
 any value as the error object.
 It is up to the Lua program or its host to handle such error objects.
 It is up to the Lua program or its host to handle such error objects.
 For historical reasons,
 For historical reasons,
@@ -298,7 +298,7 @@ even though it does not have to be a string.
 
 
 
 
 When you use @Lid{xpcall} (or @Lid{lua_pcall}, in C)
 When you use @Lid{xpcall} (or @Lid{lua_pcall}, in C)
-you may give a @def{message handler}
+you can give a @def{message handler}
 to be called in case of errors.
 to be called in case of errors.
 This function is called with the original error object
 This function is called with the original error object
 and returns a new error object.
 and returns a new error object.
@@ -343,7 +343,7 @@ which is then called a @def{metamethod}.
 In the previous example, the key is the string @St{__add}
 In the previous example, the key is the string @St{__add}
 and the metamethod is the function that performs the addition.
 and the metamethod is the function that performs the addition.
 Unless stated otherwise,
 Unless stated otherwise,
-a metamethod may in fact be any @x{callable value},
+a metamethod can in fact be any @x{callable value},
 which is either a function or a value with a @idx{__call} metamethod.
 which is either a function or a value with a @idx{__call} metamethod.
 
 
 You can query the metatable of any value
 You can query the metatable of any value
@@ -1421,7 +1421,7 @@ labels in Lua are considered statements too:
 
 
 A label is visible in the entire block where it is defined,
 A label is visible in the entire block where it is defined,
 except inside nested functions.
 except inside nested functions.
-A goto may jump to any visible label as long as it does not
+A goto can jump to any visible label as long as it does not
 enter into the scope of a local variable.
 enter into the scope of a local variable.
 A label should not be declared
 A label should not be declared
 where a label with the same name is visible,
 where a label with the same name is visible,
@@ -4549,7 +4549,7 @@ corresponding Lua value is removed from the stack @see{constchar}.
 
 
 This function can raise memory errors only
 This function can raise memory errors only
 when converting a number to a string
 when converting a number to a string
-(as then it may have to create a new string).
+(as then it may create a new string).
 
 
 }
 }
 
 
@@ -6113,8 +6113,8 @@ The metatable is created by the I/O library
 
 
 This userdata must start with the structure @id{luaL_Stream};
 This userdata must start with the structure @id{luaL_Stream};
 it can contain other data after this initial structure.
 it can contain other data after this initial structure.
-The field @id{f} points to the corresponding C stream
-(or it can be @id{NULL} to indicate an incompletely created handle).
+The field @id{f} points to the corresponding C stream,
+or it is @id{NULL} to indicate an incompletely created handle.
 The field @id{closef} points to a Lua function
 The field @id{closef} points to a Lua function
 that will be called to close the stream
 that will be called to close the stream
 when the handle is closed or collected;
 when the handle is closed or collected;
@@ -9239,11 +9239,25 @@ Lua repeatedly prompts and waits for a line.
 After reading a line,
 After reading a line,
 Lua first try to interpret the line as an expression.
 Lua first try to interpret the line as an expression.
 If it succeeds, it prints its value.
 If it succeeds, it prints its value.
-Otherwise, it interprets the line as a statement.
-If you write an incomplete statement,
+Otherwise, it interprets the line as a chunk.
+If you write an incomplete chunk,
 the interpreter waits for its completion
 the interpreter waits for its completion
 by issuing a different prompt.
 by issuing a different prompt.
 
 
+Note that, as each complete line is read as a new chunk,
+local variables do not outlive lines:
+@verbatim{
+> x = 20
+> local x = 10; print(x)   --> 10
+> print(x)                 --> 20    -- global 'x'
+> do       -- incomplete line
+>> local x = 10; print(x)    -- '>>' prompts for line completion
+>> print(x)
+>> end     -- line completed; Lua will run it as a single chunk
+   --> 10
+   --> 10
+}
+
 If the global variable @defid{_PROMPT} contains a string,
 If the global variable @defid{_PROMPT} contains a string,
 then its value is used as the prompt.
 then its value is used as the prompt.
 Similarly, if the global variable @defid{_PROMPT2} contains a string,
 Similarly, if the global variable @defid{_PROMPT2} contains a string,

+ 2 - 1
testes/pm.lua

@@ -56,7 +56,8 @@ assert(f("  \n\r*&\n\r   xuxu  \n\n", "%g%g%g+") == "xuxu")
 
 
 -- Adapt a pattern to UTF-8
 -- Adapt a pattern to UTF-8
 local function PU (p)
 local function PU (p)
-  -- break '?' into each individual byte of a character
+  -- distribute '?' into each individual byte of a character.
+  -- (For instance, "á?" becomes "\195?\161?".)
   p = string.gsub(p, "(" .. utf8.charpattern .. ")%?", function (c)
   p = string.gsub(p, "(" .. utf8.charpattern .. ")%?", function (c)
     return string.gsub(c, ".", "%0?")
     return string.gsub(c, ".", "%0?")
   end)
   end)