mirror of
https://github.com/lua/lua
synced 2024-11-21 20:31:22 +03:00
Details
Corrections in comments and manual. Added note in the manual about local variables in the REPL.
This commit is contained in:
parent
9d985db7bb
commit
262dc5729a
@ -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'.
|
||||
*/
|
||||
static int panic (lua_State *L) {
|
||||
|
2
lgc.c
2
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
|
||||
** "as fast as possible". In particular, it skips the propagation
|
||||
** 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.
|
||||
*/
|
||||
static l_obj singlestep (lua_State *L, int fast) {
|
||||
|
2
lgc.h
2
lgc.h
@ -135,7 +135,7 @@
|
||||
**
|
||||
** 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
|
||||
** 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',
|
||||
** which in the next cycle becomes 'old1'. So, 'old0' objects is
|
||||
** old but can point to new and survival objects; 'old1' is old
|
||||
|
2
lstate.h
2
lstate.h
@ -259,7 +259,7 @@ typedef struct global_State {
|
||||
l_obj totalobjs; /* total number of objects allocated + GCdebt */
|
||||
l_obj GCdebt; /* objects counted but not yet allocated */
|
||||
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 */
|
||||
TValue l_registry;
|
||||
TValue nilvalue; /* a nil value */
|
||||
|
4
lua.c
4
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)'.
|
||||
** 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) {
|
||||
int status;
|
||||
@ -230,7 +230,7 @@ static int dolibrary (lua_State *L, char *globname) {
|
||||
status = docall(L, 1, 1); /* call 'require(modname)' */
|
||||
if (status == LUA_OK) {
|
||||
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) */
|
||||
}
|
||||
return report(L, status);
|
||||
|
@ -261,7 +261,7 @@
|
||||
/*
|
||||
** LUA_IGMARK is a mark to ignore all after it when building the
|
||||
** 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".
|
||||
*/
|
||||
#define LUA_IGMARK "-"
|
||||
|
8
lvm.c
8
lvm.c
@ -92,10 +92,10 @@ static int l_strton (const TValue *obj, TValue *result) {
|
||||
if (!cvt2num(obj)) /* is object not a string? */
|
||||
return 0;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ Whenever there is an error,
|
||||
an @def{error object}
|
||||
is propagated with information about the error.
|
||||
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.
|
||||
It is up to the Lua program or its host to handle such error objects.
|
||||
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)
|
||||
you may give a @def{message handler}
|
||||
you can give a @def{message handler}
|
||||
to be called in case of errors.
|
||||
This function is called with the original 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}
|
||||
and the metamethod is the function that performs the addition.
|
||||
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.
|
||||
|
||||
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,
|
||||
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.
|
||||
A label should not be declared
|
||||
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
|
||||
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};
|
||||
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
|
||||
that will be called to close the stream
|
||||
when the handle is closed or collected;
|
||||
@ -9239,11 +9239,25 @@ Lua repeatedly prompts and waits for a line.
|
||||
After reading a line,
|
||||
Lua first try to interpret the line as an expression.
|
||||
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
|
||||
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,
|
||||
then its value is used as the prompt.
|
||||
Similarly, if the global variable @defid{_PROMPT2} contains a string,
|
||||
|
@ -56,7 +56,8 @@ assert(f(" \n\r*&\n\r xuxu \n\n", "%g%g%g+") == "xuxu")
|
||||
|
||||
-- Adapt a pattern to UTF-8
|
||||
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)
|
||||
return string.gsub(c, ".", "%0?")
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user