diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-05-08 17:50:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-05-08 17:50:10 -0300 |
commit | 262dc5729a28b2bad0b6413d4eab2290d14395cf (patch) | |
tree | c92cbf6c6d5d88bc352dd71f7f27be4dd44cf16f | |
parent | 9d985db7bb09c92b5b3fa660fffe5907d01e6a02 (diff) | |
download | lua-262dc5729a28b2bad0b6413d4eab2290d14395cf.tar.gz lua-262dc5729a28b2bad0b6413d4eab2290d14395cf.tar.bz2 lua-262dc5729a28b2bad0b6413d4eab2290d14395cf.zip |
Details
Corrections in comments and manual. Added note in the manual about
local variables in the REPL.
Diffstat (limited to '')
-rw-r--r-- | lauxlib.c | 2 | ||||
-rw-r--r-- | lgc.c | 2 | ||||
-rw-r--r-- | lgc.h | 2 | ||||
-rw-r--r-- | lstate.h | 2 | ||||
-rw-r--r-- | lua.c | 4 | ||||
-rw-r--r-- | luaconf.h | 2 | ||||
-rw-r--r-- | lvm.c | 8 | ||||
-rw-r--r-- | manual/manual.of | 32 | ||||
-rw-r--r-- | testes/pm.lua | 3 |
9 files changed, 36 insertions, 21 deletions
@@ -1044,7 +1044,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { | |||
1044 | 1044 | ||
1045 | 1045 | ||
1046 | /* | 1046 | /* |
1047 | ** Standard panic funcion just prints an error message. The test | 1047 | ** Standard panic function just prints an error message. The test |
1048 | ** with 'lua_type' avoids possible memory errors in 'lua_tostring'. | 1048 | ** with 'lua_type' avoids possible memory errors in 'lua_tostring'. |
1049 | */ | 1049 | */ |
1050 | static int panic (lua_State *L) { | 1050 | static int panic (lua_State *L) { |
@@ -1541,7 +1541,7 @@ static void sweepstep (lua_State *L, global_State *g, | |||
1541 | ** object.) When 'fast' is true, 'singlestep' tries to finish a state | 1541 | ** object.) When 'fast' is true, 'singlestep' tries to finish a state |
1542 | ** "as fast as possible". In particular, it skips the propagation | 1542 | ** "as fast as possible". In particular, it skips the propagation |
1543 | ** phase and leaves all objects to be traversed by the atomic phase: | 1543 | ** phase and leaves all objects to be traversed by the atomic phase: |
1544 | ** That avoids traversing twice some objects, such as theads and | 1544 | ** That avoids traversing twice some objects, such as threads and |
1545 | ** weak tables. | 1545 | ** weak tables. |
1546 | */ | 1546 | */ |
1547 | static l_obj singlestep (lua_State *L, int fast) { | 1547 | static l_obj singlestep (lua_State *L, int fast) { |
@@ -135,7 +135,7 @@ | |||
135 | ** | 135 | ** |
136 | ** To keep its invariants, the generational mode uses the same barriers | 136 | ** To keep its invariants, the generational mode uses the same barriers |
137 | ** also used by the incremental mode. If a young object is caught in a | 137 | ** also used by the incremental mode. If a young object is caught in a |
138 | ** foward barrier, it cannot become old immediately, because it can | 138 | ** forward barrier, it cannot become old immediately, because it can |
139 | ** still point to other young objects. Instead, it becomes 'old0', | 139 | ** still point to other young objects. Instead, it becomes 'old0', |
140 | ** which in the next cycle becomes 'old1'. So, 'old0' objects is | 140 | ** which in the next cycle becomes 'old1'. So, 'old0' objects is |
141 | ** old but can point to new and survival objects; 'old1' is old | 141 | ** old but can point to new and survival objects; 'old1' is old |
@@ -259,7 +259,7 @@ typedef struct global_State { | |||
259 | l_obj totalobjs; /* total number of objects allocated + GCdebt */ | 259 | l_obj totalobjs; /* total number of objects allocated + GCdebt */ |
260 | l_obj GCdebt; /* objects counted but not yet allocated */ | 260 | l_obj GCdebt; /* objects counted but not yet allocated */ |
261 | l_obj marked; /* number of objects marked in a GC cycle */ | 261 | l_obj marked; /* number of objects marked in a GC cycle */ |
262 | l_obj GCmajorminor; /* auxiliar counter to control major-minor shifts */ | 262 | l_obj GCmajorminor; /* auxiliary counter to control major-minor shifts */ |
263 | stringtable strt; /* hash table for strings */ | 263 | stringtable strt; /* hash table for strings */ |
264 | TValue l_registry; | 264 | TValue l_registry; |
265 | TValue nilvalue; /* a nil value */ | 265 | TValue nilvalue; /* a nil value */ |
@@ -211,7 +211,7 @@ static int dostring (lua_State *L, const char *s, const char *name) { | |||
211 | /* | 211 | /* |
212 | ** Receives 'globname[=modname]' and runs 'globname = require(modname)'. | 212 | ** Receives 'globname[=modname]' and runs 'globname = require(modname)'. |
213 | ** If there is no explicit modname and globname contains a '-', cut | 213 | ** If there is no explicit modname and globname contains a '-', cut |
214 | ** the sufix after '-' (the "version") to make the global name. | 214 | ** the suffix after '-' (the "version") to make the global name. |
215 | */ | 215 | */ |
216 | static int dolibrary (lua_State *L, char *globname) { | 216 | static int dolibrary (lua_State *L, char *globname) { |
217 | int status; | 217 | int status; |
@@ -230,7 +230,7 @@ static int dolibrary (lua_State *L, char *globname) { | |||
230 | status = docall(L, 1, 1); /* call 'require(modname)' */ | 230 | status = docall(L, 1, 1); /* call 'require(modname)' */ |
231 | if (status == LUA_OK) { | 231 | if (status == LUA_OK) { |
232 | if (suffix != NULL) /* is there a suffix mark? */ | 232 | if (suffix != NULL) /* is there a suffix mark? */ |
233 | *suffix = '\0'; /* remove sufix from global name */ | 233 | *suffix = '\0'; /* remove suffix from global name */ |
234 | lua_setglobal(L, globname); /* globname = require(modname) */ | 234 | lua_setglobal(L, globname); /* globname = require(modname) */ |
235 | } | 235 | } |
236 | return report(L, status); | 236 | return report(L, status); |
@@ -261,7 +261,7 @@ | |||
261 | /* | 261 | /* |
262 | ** LUA_IGMARK is a mark to ignore all after it when building the | 262 | ** LUA_IGMARK is a mark to ignore all after it when building the |
263 | ** module name (e.g., used to build the luaopen_ function name). | 263 | ** module name (e.g., used to build the luaopen_ function name). |
264 | ** Typically, the sufix after the mark is the module version, | 264 | ** Typically, the suffix after the mark is the module version, |
265 | ** as in "mod-v1.2.so". | 265 | ** as in "mod-v1.2.so". |
266 | */ | 266 | */ |
267 | #define LUA_IGMARK "-" | 267 | #define LUA_IGMARK "-" |
@@ -92,10 +92,10 @@ static int l_strton (const TValue *obj, TValue *result) { | |||
92 | if (!cvt2num(obj)) /* is object not a string? */ | 92 | if (!cvt2num(obj)) /* is object not a string? */ |
93 | return 0; | 93 | return 0; |
94 | else { | 94 | else { |
95 | TString *st = tsvalue(obj); | 95 | TString *st = tsvalue(obj); |
96 | size_t stlen; | 96 | size_t stlen; |
97 | const char *s = getlstr(st, stlen); | 97 | const char *s = getlstr(st, stlen); |
98 | return (luaO_str2num(s, result) == stlen + 1); | 98 | return (luaO_str2num(s, result) == stlen + 1); |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
diff --git a/manual/manual.of b/manual/manual.of index 7df32fcf..5aea2623 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -289,7 +289,7 @@ Whenever there is an error, | |||
289 | an @def{error object} | 289 | an @def{error object} |
290 | is propagated with information about the error. | 290 | is propagated with information about the error. |
291 | Lua itself only generates errors whose error object is a string, | 291 | Lua itself only generates errors whose error object is a string, |
292 | but programs may generate errors with | 292 | but programs can generate errors with |
293 | any value as the error object. | 293 | any value as the error object. |
294 | It is up to the Lua program or its host to handle such error objects. | 294 | It is up to the Lua program or its host to handle such error objects. |
295 | For historical reasons, | 295 | For historical reasons, |
@@ -298,7 +298,7 @@ even though it does not have to be a string. | |||
298 | 298 | ||
299 | 299 | ||
300 | When you use @Lid{xpcall} (or @Lid{lua_pcall}, in C) | 300 | When you use @Lid{xpcall} (or @Lid{lua_pcall}, in C) |
301 | you may give a @def{message handler} | 301 | you can give a @def{message handler} |
302 | to be called in case of errors. | 302 | to be called in case of errors. |
303 | This function is called with the original error object | 303 | This function is called with the original error object |
304 | and returns a new error object. | 304 | and returns a new error object. |
@@ -343,7 +343,7 @@ which is then called a @def{metamethod}. | |||
343 | In the previous example, the key is the string @St{__add} | 343 | In the previous example, the key is the string @St{__add} |
344 | and the metamethod is the function that performs the addition. | 344 | and the metamethod is the function that performs the addition. |
345 | Unless stated otherwise, | 345 | Unless stated otherwise, |
346 | a metamethod may in fact be any @x{callable value}, | 346 | a metamethod can in fact be any @x{callable value}, |
347 | which is either a function or a value with a @idx{__call} metamethod. | 347 | which is either a function or a value with a @idx{__call} metamethod. |
348 | 348 | ||
349 | You can query the metatable of any value | 349 | You can query the metatable of any value |
@@ -1421,7 +1421,7 @@ labels in Lua are considered statements too: | |||
1421 | 1421 | ||
1422 | A label is visible in the entire block where it is defined, | 1422 | A label is visible in the entire block where it is defined, |
1423 | except inside nested functions. | 1423 | except inside nested functions. |
1424 | A goto may jump to any visible label as long as it does not | 1424 | A goto can jump to any visible label as long as it does not |
1425 | enter into the scope of a local variable. | 1425 | enter into the scope of a local variable. |
1426 | A label should not be declared | 1426 | A label should not be declared |
1427 | where a label with the same name is visible, | 1427 | where a label with the same name is visible, |
@@ -4549,7 +4549,7 @@ corresponding Lua value is removed from the stack @see{constchar}. | |||
4549 | 4549 | ||
4550 | This function can raise memory errors only | 4550 | This function can raise memory errors only |
4551 | when converting a number to a string | 4551 | when converting a number to a string |
4552 | (as then it may have to create a new string). | 4552 | (as then it may create a new string). |
4553 | 4553 | ||
4554 | } | 4554 | } |
4555 | 4555 | ||
@@ -6113,8 +6113,8 @@ The metatable is created by the I/O library | |||
6113 | 6113 | ||
6114 | This userdata must start with the structure @id{luaL_Stream}; | 6114 | This userdata must start with the structure @id{luaL_Stream}; |
6115 | it can contain other data after this initial structure. | 6115 | it can contain other data after this initial structure. |
6116 | The field @id{f} points to the corresponding C stream | 6116 | The field @id{f} points to the corresponding C stream, |
6117 | (or it can be @id{NULL} to indicate an incompletely created handle). | 6117 | or it is @id{NULL} to indicate an incompletely created handle. |
6118 | The field @id{closef} points to a Lua function | 6118 | The field @id{closef} points to a Lua function |
6119 | that will be called to close the stream | 6119 | that will be called to close the stream |
6120 | when the handle is closed or collected; | 6120 | when the handle is closed or collected; |
@@ -9239,11 +9239,25 @@ Lua repeatedly prompts and waits for a line. | |||
9239 | After reading a line, | 9239 | After reading a line, |
9240 | Lua first try to interpret the line as an expression. | 9240 | Lua first try to interpret the line as an expression. |
9241 | If it succeeds, it prints its value. | 9241 | If it succeeds, it prints its value. |
9242 | Otherwise, it interprets the line as a statement. | 9242 | Otherwise, it interprets the line as a chunk. |
9243 | If you write an incomplete statement, | 9243 | If you write an incomplete chunk, |
9244 | the interpreter waits for its completion | 9244 | the interpreter waits for its completion |
9245 | by issuing a different prompt. | 9245 | by issuing a different prompt. |
9246 | 9246 | ||
9247 | Note that, as each complete line is read as a new chunk, | ||
9248 | local variables do not outlive lines: | ||
9249 | @verbatim{ | ||
9250 | > x = 20 | ||
9251 | > local x = 10; print(x) --> 10 | ||
9252 | > print(x) --> 20 -- global 'x' | ||
9253 | > do -- incomplete line | ||
9254 | >> local x = 10; print(x) -- '>>' prompts for line completion | ||
9255 | >> print(x) | ||
9256 | >> end -- line completed; Lua will run it as a single chunk | ||
9257 | --> 10 | ||
9258 | --> 10 | ||
9259 | } | ||
9260 | |||
9247 | If the global variable @defid{_PROMPT} contains a string, | 9261 | If the global variable @defid{_PROMPT} contains a string, |
9248 | then its value is used as the prompt. | 9262 | then its value is used as the prompt. |
9249 | Similarly, if the global variable @defid{_PROMPT2} contains a string, | 9263 | Similarly, if the global variable @defid{_PROMPT2} contains a string, |
diff --git a/testes/pm.lua b/testes/pm.lua index 44454dff..f5889fcd 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
@@ -56,7 +56,8 @@ assert(f(" \n\r*&\n\r xuxu \n\n", "%g%g%g+") == "xuxu") | |||
56 | 56 | ||
57 | -- Adapt a pattern to UTF-8 | 57 | -- Adapt a pattern to UTF-8 |
58 | local function PU (p) | 58 | local function PU (p) |
59 | -- break '?' into each individual byte of a character | 59 | -- distribute '?' into each individual byte of a character. |
60 | -- (For instance, "รก?" becomes "\195?\161?".) | ||
60 | p = string.gsub(p, "(" .. utf8.charpattern .. ")%?", function (c) | 61 | p = string.gsub(p, "(" .. utf8.charpattern .. ")%?", function (c) |
61 | return string.gsub(c, ".", "%0?") | 62 | return string.gsub(c, ".", "%0?") |
62 | end) | 63 | end) |