aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-10 12:41:56 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-10 12:41:56 -0300
commit979ad95eb114d8d43f928b184f051ac0cfacedf7 (patch)
treefbea7150dbbb3bbbf68d80b6bd24d42a81d2afdb /manual
parent0f028b9008097f00aa3953a3425c72e7ae2b4c98 (diff)
downloadlua-979ad95eb114d8d43f928b184f051ac0cfacedf7.tar.gz
lua-979ad95eb114d8d43f928b184f051ac0cfacedf7.tar.bz2
lua-979ad95eb114d8d43f928b184f051ac0cfacedf7.zip
Thorough revision of the reference manual
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of692
1 files changed, 351 insertions, 341 deletions
diff --git a/manual/manual.of b/manual/manual.of
index fc2550e0..9f1ef631 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -15,7 +15,7 @@ Lua is dynamically typed,
15runs by interpreting bytecode with a register-based 15runs by interpreting bytecode with a register-based
16virtual machine, 16virtual machine,
17and has automatic memory management with 17and has automatic memory management with
18incremental garbage collection, 18a generational garbage collection,
19making it ideal for configuration, scripting, 19making it ideal for configuration, scripting,
20and rapid prototyping. 20and rapid prototyping.
21 21
@@ -79,7 +79,7 @@ There are eight @x{basic types} in Lua:
79@def{thread}, and @def{table}. 79@def{thread}, and @def{table}.
80The type @emph{nil} has one single value, @nil, 80The type @emph{nil} has one single value, @nil,
81whose main property is to be different from any other value; 81whose main property is to be different from any other value;
82it usually represents the absence of a useful value. 82it often represents the absence of a useful value.
83The type @emph{boolean} has two values, @false and @true. 83The type @emph{boolean} has two values, @false and @true.
84Both @nil and @false make a condition false; 84Both @nil and @false make a condition false;
85any other value makes it true. 85any other value makes it true.
@@ -130,7 +130,8 @@ the programmer can define operations for full userdata values
130@see{metatable}. 130@see{metatable}.
131Userdata values cannot be created or modified in Lua, 131Userdata values cannot be created or modified in Lua,
132only through the @N{C API}. 132only through the @N{C API}.
133This guarantees the integrity of data owned by the host program. 133This guarantees the integrity of data owned by
134the host program and @N{C libraries}.
134 135
135The type @def{thread} represents independent threads of execution 136The type @def{thread} represents independent threads of execution
136and it is used to implement coroutines @see{coroutine}. 137and it is used to implement coroutines @see{coroutine}.
@@ -146,7 +147,7 @@ used by the @x{IEEE 754} standard to represent
146undefined numerical results, such as @T{0/0}.) 147undefined numerical results, such as @T{0/0}.)
147Tables can be @emph{heterogeneous}; 148Tables can be @emph{heterogeneous};
148that is, they can contain values of all types (except @nil). 149that is, they can contain values of all types (except @nil).
149Any key with value @nil is not considered part of the table. 150Any key associated to the value @nil is not considered part of the table.
150Conversely, any key that is not part of a table has 151Conversely, any key that is not part of a table has
151an associated value @nil. 152an associated value @nil.
152 153
@@ -176,14 +177,10 @@ In particular, floats with integral values
176are equal to their respective integers 177are equal to their respective integers
177(e.g., @T{1.0 == 1}). 178(e.g., @T{1.0 == 1}).
178To avoid ambiguities, 179To avoid ambiguities,
179any float with integral value used as a key 180any float used as a key that is equal to an integer
180is converted to its respective integer. 181is converted to that integer.
181For instance, if you write @T{a[2.0] = true}, 182For instance, if you write @T{a[2.0] = true},
182the actual key inserted into the table will be the 183the actual key inserted into the table will be the integer @T{2}.
183integer @T{2}.
184(On the other hand,
1852 and @St{2} are different Lua values and therefore
186denote different table entries.)
187 184
188 185
189Tables, functions, threads, and (full) userdata values are @emph{objects}: 186Tables, functions, threads, and (full) userdata values are @emph{objects}:
@@ -194,13 +191,13 @@ always manipulate references to such values;
194these operations do not imply any kind of copy. 191these operations do not imply any kind of copy.
195 192
196The library function @Lid{type} returns a string describing the type 193The library function @Lid{type} returns a string describing the type
197of a given value @see{predefined}. 194of a given value @seeF{type}.
198 195
199} 196}
200 197
201@sect2{globalenv| @title{Environments and the Global Environment} 198@sect2{globalenv| @title{Environments and the Global Environment}
202 199
203As will be discussed in @refsec{variables} and @refsec{assignment}, 200As we will discuss further in @refsec{variables} and @refsec{assignment},
204any reference to a free name 201any reference to a free name
205(that is, a name not bound to any declaration) @id{var} 202(that is, a name not bound to any declaration) @id{var}
206is syntactically translated to @T{_ENV.var}. 203is syntactically translated to @T{_ENV.var}.
@@ -222,14 +219,15 @@ Any table used as the value of @id{_ENV} is called an @def{environment}.
222Lua keeps a distinguished environment called the @def{global environment}. 219Lua keeps a distinguished environment called the @def{global environment}.
223This value is kept at a special index in the C registry @see{registry}. 220This value is kept at a special index in the C registry @see{registry}.
224In Lua, the global variable @Lid{_G} is initialized with this same value. 221In Lua, the global variable @Lid{_G} is initialized with this same value.
225(@Lid{_G} is never used internally.) 222(@Lid{_G} is never used internally,
223so changing its value will affect only your own code.)
226 224
227When Lua loads a chunk, 225When Lua loads a chunk,
228the default value for its @id{_ENV} upvalue 226the default value for its @id{_ENV} upvalue
229is the global environment @seeF{load}. 227is the global environment @seeF{load}.
230Therefore, by default, 228Therefore, by default,
231free names in Lua code refer to entries in the global environment 229free names in Lua code refer to entries in the global environment
232(and, therefore, they are also called @def{global variables}). 230and, therefore, they are also called @def{global variables}.
233Moreover, all standard libraries are loaded in the global environment 231Moreover, all standard libraries are loaded in the global environment
234and some functions there operate on that environment. 232and some functions there operate on that environment.
235You can use @Lid{load} (or @Lid{loadfile}) 233You can use @Lid{load} (or @Lid{loadfile})
@@ -284,6 +282,12 @@ Lua breaks it and returns an appropriate message.
284It is not called for memory-allocation errors 282It is not called for memory-allocation errors
285nor for errors while running finalizers.) 283nor for errors while running finalizers.)
286 284
285Lua also offers a system of @emph{warnings} @seeF{warn}.
286Unlike errors, warnings do not interfere
287in any way with program execution.
288They typically only generate a message to the user,
289although this behavior can be adapted from C @see{lua_setwarnf}.
290
287} 291}
288 292
289@sect2{metatable| @title{Metatables and Metamethods} 293@sect2{metatable| @title{Metatables and Metamethods}
@@ -310,20 +314,14 @@ metamethods should be function values.
310You can query the metatable of any value 314You can query the metatable of any value
311using the @Lid{getmetatable} function. 315using the @Lid{getmetatable} function.
312Lua queries metamethods in metatables using a raw access @seeF{rawget}. 316Lua queries metamethods in metatables using a raw access @seeF{rawget}.
313So, to retrieve the metamethod for event @id{ev} in object @id{o},
314Lua does the equivalent to the following code:
315@verbatim{
316rawget(getmetatable(@rep{o}) or {}, "__@rep{ev}")
317}
318 317
319You can replace the metatable of tables 318You can replace the metatable of tables
320using the @Lid{setmetatable} function. 319using the @Lid{setmetatable} function.
321You cannot change the metatable of other types from Lua code 320You cannot change the metatable of other types from Lua code,
322(except by using the @link{debuglib|debug library}); 321except by using the @link{debuglib|debug library}.
323you should use the @N{C API} for that.
324 322
325Tables and full userdata have individual metatables 323Tables and full userdata have individual metatables,
326(although multiple tables and userdata can share their metatables). 324although multiple tables and userdata can share their metatables.
327Values of all other types share one single metatable per type; 325Values of all other types share one single metatable per type;
328that is, there is one single metatable for all numbers, 326that is, there is one single metatable for all numbers,
329one for all strings, etc. 327one for all strings, etc.
@@ -351,8 +349,7 @@ Each operation is identified by its corresponding key.
351 349
352@item{@idx{__add}| 350@item{@idx{__add}|
353the addition (@T{+}) operation. 351the addition (@T{+}) operation.
354If any operand for an addition is not a number 352If any operand for an addition is not a number,
355(nor a string coercible to a number),
356Lua will try to call a metamethod. 353Lua will try to call a metamethod.
357First, Lua will check the first operand (even if it is valid). 354First, Lua will check the first operand (even if it is valid).
358If that operand does not define a metamethod for @idx{__add}, 355If that operand does not define a metamethod for @idx{__add},
@@ -406,7 +403,7 @@ the bitwise AND (@T{&}) operation.
406Behavior similar to the addition operation, 403Behavior similar to the addition operation,
407except that Lua will try a metamethod 404except that Lua will try a metamethod
408if any operand is neither an integer 405if any operand is neither an integer
409nor a value coercible to an integer @see{coercion}. 406nor a float coercible to an integer @see{coercion}.
410} 407}
411 408
412@item{@idx{__bor}| 409@item{@idx{__bor}|
@@ -493,8 +490,8 @@ and the result of the call
493is the result of the operation. 490is the result of the operation.
494If it is a table, 491If it is a table,
495the final result is the result of indexing this table with @id{key}. 492the final result is the result of indexing this table with @id{key}.
496(This indexing is regular, not raw, 493This indexing is regular, not raw,
497and therefore can trigger another metamethod.) 494and therefore can trigger another metamethod.
498} 495}
499 496
500@item{@idx{__newindex}| 497@item{@idx{__newindex}|
@@ -510,8 +507,8 @@ If it is a function,
510it is called with @id{table}, @id{key}, and @id{value} as arguments. 507it is called with @id{table}, @id{key}, and @id{value} as arguments.
511If it is a table, 508If it is a table,
512Lua does an indexing assignment to this table with the same key and value. 509Lua does an indexing assignment to this table with the same key and value.
513(This assignment is regular, not raw, 510This assignment is regular, not raw,
514and therefore can trigger another metamethod.) 511and therefore can trigger another metamethod.
515 512
516Whenever there is a @idx{__newindex} metamethod, 513Whenever there is a @idx{__newindex} metamethod,
517Lua does not perform the primitive assignment. 514Lua does not perform the primitive assignment.
@@ -530,7 +527,7 @@ the metamethod is called with @id{func} as its first argument,
530followed by the arguments of the original call (@id{args}). 527followed by the arguments of the original call (@id{args}).
531All results of the call 528All results of the call
532are the result of the operation. 529are the result of the operation.
533(This is the only metamethod that allows multiple results.) 530This is the only metamethod that allows multiple results.
534} 531}
535 532
536} 533}
@@ -566,17 +563,17 @@ incremental and generational.
566 563
567The default GC mode with the default parameters 564The default GC mode with the default parameters
568are adequate for most uses. 565are adequate for most uses.
569Programs that waste a large proportion of its time 566However, programs that waste a large proportion of their time
570allocating and freeing memory can benefit from other settings. 567allocating and freeing memory can benefit from other settings.
571Keep in mind that the GC behavior is non-portable 568Keep in mind that the GC behavior is non-portable
572both across platforms and across different Lua releases; 569both across platforms and across different Lua releases;
573therefore, optimal settings are also non-portable. 570therefore, optimal settings are also non-portable.
574 571
575You can change the GC mode and parameters by calling 572You can change the GC mode and parameters by calling
576@Lid{lua_gc} in C 573@Lid{lua_gc} @N{in C}
577or @Lid{collectgarbage} in Lua. 574or @Lid{collectgarbage} in Lua.
578You can also use these functions to control 575You can also use these functions to control
579the collector directly (e.g., stop and restart it). 576the collector directly (e.g., to stop and restart it).
580 577
581@sect3{@title{Incremental Garbage Collection} 578@sect3{@title{Incremental Garbage Collection}
582 579
@@ -601,7 +598,7 @@ to double before starting a new cycle.
601The default value is 200; the maximum value is 1000. 598The default value is 200; the maximum value is 1000.
602 599
603The garbage-collector step multiplier 600The garbage-collector step multiplier
604controls the relative speed of the collector relative to 601controls the speed of the collector relative to
605memory allocation, 602memory allocation,
606that is, 603that is,
607how many elements it marks or sweeps for each 604how many elements it marks or sweeps for each
@@ -623,7 +620,7 @@ bytes between steps and perform equivalent work during the step.
623A large value (e.g., 60) makes the collector a stop-the-world 620A large value (e.g., 60) makes the collector a stop-the-world
624(non-incremental) collector. 621(non-incremental) collector.
625The default value is 13, 622The default value is 13,
626which makes for steps of approximately @N{8 Kbytes}. 623which means steps of approximately @N{8 Kbytes}.
627 624
628} 625}
629 626
@@ -669,8 +666,8 @@ These metamethods, called @def{finalizers},
669are called when the garbage collector detects that the 666are called when the garbage collector detects that the
670corresponding table or userdata is unreachable. 667corresponding table or userdata is unreachable.
671Finalizers allow you to coordinate Lua's garbage collection 668Finalizers allow you to coordinate Lua's garbage collection
672with external resource management 669with external resource management such as closing files,
673such as closing files, network or database connections, 670network or database connections,
674or freeing your own memory. 671or freeing your own memory.
675 672
676For an object (table or userdata) to be finalized when collected, 673For an object (table or userdata) to be finalized when collected,
@@ -682,7 +679,7 @@ Note that if you set a metatable without a @idx{__gc} field
682and later create that field in the metatable, 679and later create that field in the metatable,
683the object will not be marked for finalization. 680the object will not be marked for finalization.
684 681
685When a marked object becomes garbage, 682When a marked object becomes unreachable,
686it is not collected immediately by the garbage collector. 683it is not collected immediately by the garbage collector.
687Instead, Lua puts it in a list. 684Instead, Lua puts it in a list.
688After the collection, 685After the collection,
@@ -693,7 +690,7 @@ If it is present,
693Lua calls it with the object as its single argument. 690Lua calls it with the object as its single argument.
694 691
695At the end of each garbage-collection cycle, 692At the end of each garbage-collection cycle,
696the finalizers for objects are called in 693the finalizers are called in
697the reverse order that the objects were marked for finalization, 694the reverse order that the objects were marked for finalization,
698among those collected in that cycle; 695among those collected in that cycle;
699that is, the first finalizer to be called is the one associated 696that is, the first finalizer to be called is the one associated
@@ -723,9 +720,16 @@ If any finalizer marks objects for collection during that phase,
723these marks have no effect. 720these marks have no effect.
724 721
725Finalizers cannot yield. 722Finalizers cannot yield.
723Except for that, they can do anything,
724such as raise errors, create new objects,
725or even run the garbage collector.
726However, because they can run in unpredictable times,
727it is good practice to restrict each finalizer
728to the minimum necessary to properly release
729its associated resource.
726 730
727Any error while running a finalizer generates a warning; 731Any error while running a finalizer generates a warning;
728it is not propagated. 732the error is not propagated.
729 733
730} 734}
731 735
@@ -773,8 +777,10 @@ are not subject to garbage collection,
773and therefore are not removed from weak tables 777and therefore are not removed from weak tables
774(unless their associated values are collected). 778(unless their associated values are collected).
775Although strings are subject to garbage collection, 779Although strings are subject to garbage collection,
776they do not have an explicit construction, 780they do not have an explicit construction and
777and therefore are not removed from weak tables. 781their equality is by value;
782they behave more like values than like objects.
783Therefore, they are not removed from weak tables.
778 784
779Resurrected objects 785Resurrected objects
780(that is, objects being finalized 786(that is, objects being finalized
@@ -828,7 +834,7 @@ In case of normal termination,
828@Lid{coroutine.resume} returns @true, 834@Lid{coroutine.resume} returns @true,
829plus any values returned by the coroutine main function. 835plus any values returned by the coroutine main function.
830In case of errors, @Lid{coroutine.resume} returns @false 836In case of errors, @Lid{coroutine.resume} returns @false
831plus an error object. 837plus the error object.
832 838
833A coroutine yields by calling @Lid{coroutine.yield}. 839A coroutine yields by calling @Lid{coroutine.yield}.
834When a coroutine yields, 840When a coroutine yields,
@@ -922,7 +928,7 @@ at the end of this manual.
922 928
923Lua is a @x{free-form} language. 929Lua is a @x{free-form} language.
924It ignores spaces and comments between lexical elements (@x{tokens}), 930It ignores spaces and comments between lexical elements (@x{tokens}),
925except as delimiters between @x{names} and @x{keywords}. 931except as delimiters between two tokens.
926In source code, 932In source code,
927Lua recognizes as spaces the standard ASCII white-space 933Lua recognizes as spaces the standard ASCII white-space
928characters space, form feed, newline, 934characters space, form feed, newline,
@@ -1001,11 +1007,12 @@ it must be expressed using exactly three digits.)
1001The @x{UTF-8} encoding of a @x{Unicode} character 1007The @x{UTF-8} encoding of a @x{Unicode} character
1002can be inserted in a literal string with 1008can be inserted in a literal string with
1003the escape sequence @T{\u{@rep{XXX}}} 1009the escape sequence @T{\u{@rep{XXX}}}
1004(note the mandatory enclosing brackets), 1010(with mandatory enclosing brackets),
1005where @rep{XXX} is a sequence of one or more hexadecimal digits 1011where @rep{XXX} is a sequence of one or more hexadecimal digits
1006representing the character code point. 1012representing the character code point.
1007This code point can be any value less than @M{2@sp{31}}. 1013This code point can be any value less than @M{2@sp{31}}.
1008(Lua uses the original UTF-8 specification here.) 1014(Lua uses the original UTF-8 specification here,
1015which is not restricted to valid Unicode code points.)
1009 1016
1010Literal strings can also be defined using a long format 1017Literal strings can also be defined using a long format
1011enclosed by @def{long brackets}. 1018enclosed by @def{long brackets}.
@@ -1028,9 +1035,9 @@ Any kind of end-of-line sequence
1028(carriage return, newline, carriage return followed by newline, 1035(carriage return, newline, carriage return followed by newline,
1029or newline followed by carriage return) 1036or newline followed by carriage return)
1030is converted to a simple newline. 1037is converted to a simple newline.
1031
1032When the opening long bracket is immediately followed by a newline, 1038When the opening long bracket is immediately followed by a newline,
1033the newline is not included in the string. 1039the newline is not included in the string.
1040
1034As an example, in a system using ASCII 1041As an example, in a system using ASCII
1035(in which @Char{a} is coded @N{as 97}, 1042(in which @Char{a} is coded @N{as 97},
1036newline is coded @N{as 10}, and @Char{1} is coded @N{as 49}), 1043newline is coded @N{as 10}, and @Char{1} is coded @N{as 49}),
@@ -1052,7 +1059,7 @@ However, Lua opens files for parsing in text mode,
1052and the system's file functions may have problems with 1059and the system's file functions may have problems with
1053some control characters. 1060some control characters.
1054So, it is safer to represent 1061So, it is safer to represent
1055non-text data as a quoted literal with 1062binary data as a quoted literal with
1056explicit escape sequences for the non-text characters. 1063explicit escape sequences for the non-text characters.
1057 1064
1058A @def{numeric constant} (or @def{numeral}) 1065A @def{numeric constant} (or @def{numeral})
@@ -1106,7 +1113,7 @@ which is a particular kind of local variable):
1106@Produc{ 1113@Produc{
1107@producname{var}@producbody{@bnfNter{Name}} 1114@producname{var}@producbody{@bnfNter{Name}}
1108} 1115}
1109@bnfNter{Name} denotes identifiers, as defined in @See{lexical}. 1116@bnfNter{Name} denotes identifiers @see{lexical}.
1110 1117
1111Any variable name is assumed to be global unless explicitly declared 1118Any variable name is assumed to be global unless explicitly declared
1112as a local @see{localvar}. 1119as a local @see{localvar}.
@@ -1139,9 +1146,9 @@ the variable @id{_ENV} itself is never global @see{globalenv}.
1139@sect2{stats| @title{Statements} 1146@sect2{stats| @title{Statements}
1140 1147
1141Lua supports an almost conventional set of @x{statements}, 1148Lua supports an almost conventional set of @x{statements},
1142similar to those in Pascal or C. 1149similar to those in other conventional languages.
1143This set includes 1150This set includes
1144assignments, control structures, function calls, 1151blocks, assignments, control structures, function calls,
1145and variable declarations. 1152and variable declarations.
1146 1153
1147@sect3{@title{Blocks} 1154@sect3{@title{Blocks}
@@ -1159,7 +1166,7 @@ or write two semicolons in sequence:
1159@producname{stat}@producbody{@bnfter{;}} 1166@producname{stat}@producbody{@bnfter{;}}
1160} 1167}
1161 1168
1162Function calls and assignments 1169Both function calls and assignments
1163can start with an open parenthesis. 1170can start with an open parenthesis.
1164This possibility leads to an ambiguity in Lua's grammar. 1171This possibility leads to an ambiguity in Lua's grammar.
1165Consider the following fragment: 1172Consider the following fragment:
@@ -1167,7 +1174,7 @@ Consider the following fragment:
1167a = b + c 1174a = b + c
1168(print or io.write)('done') 1175(print or io.write)('done')
1169} 1176}
1170The grammar could see it in two ways: 1177The grammar could see this fragment in two ways:
1171@verbatim{ 1178@verbatim{
1172a = b + c(print or io.write)('done') 1179a = b + c(print or io.write)('done')
1173 1180
@@ -1223,7 +1230,7 @@ and then Lua executes the compiled code
1223with an interpreter for the virtual machine. 1230with an interpreter for the virtual machine.
1224 1231
1225Chunks can also be precompiled into binary form; 1232Chunks can also be precompiled into binary form;
1226see program @idx{luac} and function @Lid{string.dump} for details. 1233see the program @idx{luac} and the function @Lid{string.dump} for details.
1227Programs in source and compiled forms are interchangeable; 1234Programs in source and compiled forms are interchangeable;
1228Lua automatically detects the file type and acts accordingly @seeF{load}. 1235Lua automatically detects the file type and acts accordingly @seeF{load}.
1229 1236
@@ -1249,7 +1256,7 @@ the list of variables.@index{adjustment}
1249If there are more values than needed, 1256If there are more values than needed,
1250the excess values are thrown away. 1257the excess values are thrown away.
1251If there are fewer values than needed, 1258If there are fewer values than needed,
1252the list is extended with as many @nil's as needed. 1259the list is extended with @nil's.
1253If the list of expressions ends with a function call, 1260If the list of expressions ends with a function call,
1254then all values returned by that call enter the list of values, 1261then all values returned by that call enter the list of values,
1255before the adjustment 1262before the adjustment
@@ -1306,7 +1313,7 @@ The @x{condition expression} of a
1306control structure can return any value. 1313control structure can return any value.
1307Both @false and @nil test false. 1314Both @false and @nil test false.
1308All values different from @nil and @false test true. 1315All values different from @nil and @false test true.
1309(In particular, the number 0 and the empty string also test true). 1316In particular, the number 0 and the empty string also test true.
1310 1317
1311In the @Rw{repeat}@En@Rw{until} loop, 1318In the @Rw{repeat}@En@Rw{until} loop,
1312the inner block does not end at the @Rw{until} keyword, 1319the inner block does not end at the @Rw{until} keyword,
@@ -1347,7 +1354,7 @@ A @Rw{break} ends the innermost enclosing loop.
1347 1354
1348The @Rw{return} statement is used to return values 1355The @Rw{return} statement is used to return values
1349from a function or a chunk 1356from a function or a chunk
1350(which is an anonymous function). 1357(which is handled as an anonymous function).
1351@index{return statement} 1358@index{return statement}
1352Functions can return more than one value, 1359Functions can return more than one value,
1353so the syntax for the @Rw{return} statement is 1360so the syntax for the @Rw{return} statement is
@@ -1357,7 +1364,7 @@ so the syntax for the @Rw{return} statement is
1357 1364
1358The @Rw{return} statement can only be written 1365The @Rw{return} statement can only be written
1359as the last statement of a block. 1366as the last statement of a block.
1360If it is really necessary to @Rw{return} in the middle of a block, 1367If it is necessary to @Rw{return} in the middle of a block,
1361then an explicit inner block can be used, 1368then an explicit inner block can be used,
1362as in the idiom @T{do return end}, 1369as in the idiom @T{do return end},
1363because now @Rw{return} is the last statement in its (inner) block. 1370because now @Rw{return} is the last statement in its (inner) block.
@@ -1395,11 +1402,12 @@ until that value passes the limit.
1395A negative step makes a decreasing sequence; 1402A negative step makes a decreasing sequence;
1396a step equal to zero raises an error. 1403a step equal to zero raises an error.
1397If the initial value is already greater than the limit 1404If the initial value is already greater than the limit
1398(or less than, if the step is negative), the body is not executed. 1405(or less than, if the step is negative),
1406the body is not executed.
1399 1407
1400If both the initial value and the step are integers, 1408If both the initial value and the step are integers,
1401the loop is done with integers; 1409the loop is done with integers;
1402in this case, the range of the control variable is limited 1410in this case, the range of the control variable is clipped
1403by the range of integers. 1411by the range of integers.
1404Otherwise, the loop is done with floats. 1412Otherwise, the loop is done with floats.
1405(Beware of floating-point accuracy in this case.) 1413(Beware of floating-point accuracy in this case.)
@@ -1426,52 +1434,37 @@ The generic @Rw{for} loop has the following syntax:
1426} 1434}
1427A @Rw{for} statement like 1435A @Rw{for} statement like
1428@verbatim{ 1436@verbatim{
1429for @rep{var_1}, @Cdots, @rep{var_n} in @rep{explist} do @rep{block} end 1437for @rep{var_1}, @Cdots, @rep{var_n} in @rep{explist} do @rep{body} end
1430} 1438}
1431is equivalent to the code: 1439works as follows.
1432@verbatim{
1433do
1434 local @rep{f}, @rep{s}, @rep{var}
1435 local *toclose @rep{tbc} = nil
1436 @rep{f}, @rep{s}, @rep{var}, @rep{tbc} = @rep{explist}
1437 while true do
1438 local @rep{var_1}, @Cdots, @rep{var_n} = @rep{f}(@rep{s}, @rep{var})
1439 if @rep{var_1} == nil then break end
1440 @rep{var} = @rep{var_1}
1441 @rep{block}
1442 end
1443end
1444}
1445Note the following:
1446@itemize{
1447 1440
1448@item{ 1441The names @rep{var_i} declare loop variables local to the loop body.
1449@T{@rep{explist}} is evaluated only once. 1442The first of these variables is the @emph{control variable}.
1450Its results are an @emph{iterator} function, 1443
1444The loop starts by evaluating @rep{explist}
1445to produce four values:
1446an @emph{iterator function},
1451a @emph{state}, 1447a @emph{state},
1452an initial value for the first @emph{iterator variable}, 1448an initial value for the control variable,
1453and a to-be-closed variable @see{to-be-closed}, 1449and a @emph{closing value}.
1450
1451Then, at each iteration,
1452Lua calls the iterator function with two arguments:
1453the state and the control variable.
1454The results from this call are then assigned to the loop variables,
1455following the rules of multiple assignments @see{assignment}.
1456If the control variable becomes @nil,
1457the loop terminates.
1458Otherwise, the body is executed and the loop goes
1459to the next iteration.
1460
1461The closing value behaves like a
1462to-be-closed variable @see{to-be-closed},
1454which can be used to release resources when the loop ends. 1463which can be used to release resources when the loop ends.
1455} 1464Otherwise, it does not interfere with the loop.
1456
1457@item{
1458@T{@rep{f}}, @T{@rep{s}}, @T{@rep{var}}, and @T{@rep{tbc}}
1459are invisible variables.
1460The names are here for explanatory purposes only.
1461}
1462
1463@item{
1464You can use @Rw{break} to exit a @Rw{for} loop.
1465}
1466 1465
1467@item{ 1466You should not change the value of the control variable
1468The loop variables @T{@rep{var_i}} are local to the loop; 1467during the loop.
1469you cannot use their values after the @Rw{for} ends.
1470If you need these values,
1471then assign them to other variables before breaking or exiting the loop.
1472}
1473
1474}
1475 1468
1476} 1469}
1477 1470
@@ -1541,7 +1534,8 @@ the other pending closing methods will still be called.
1541If a coroutine yields inside a block and is never resumed again, 1534If a coroutine yields inside a block and is never resumed again,
1542the variables visible at that block will never go out of scope, 1535the variables visible at that block will never go out of scope,
1543and therefore they will not be closed. 1536and therefore they will not be closed.
1544(You should use finalizers to handle this case.) 1537(You should use finalizers to handle this case,
1538or else call @Lid{coroutine.kill} to close the variables.)
1545 1539
1546} 1540}
1547 1541
@@ -1659,7 +1653,7 @@ so that it works for non-integer exponents too.
1659 1653
1660Floor division (@T{//}) is a division 1654Floor division (@T{//}) is a division
1661that rounds the quotient towards minus infinity, 1655that rounds the quotient towards minus infinity,
1662that is, the floor of the division of its operands. 1656resulting in the floor of the division of its operands.
1663 1657
1664Modulo is defined as the remainder of a division 1658Modulo is defined as the remainder of a division
1665that rounds the quotient towards minus infinity (floor division). 1659that rounds the quotient towards minus infinity (floor division).
@@ -1725,21 +1719,30 @@ it is in the range of integer representation).
1725If it does, that representation is the result. 1719If it does, that representation is the result.
1726Otherwise, the conversion fails. 1720Otherwise, the conversion fails.
1727 1721
1728The string library uses metamethods that try to coerce 1722Several places in Lua coerce strings to numbers when necessary.
1729strings to numbers in all arithmetic operations. 1723A string is converted to an integer or a float
1730Any string operator is converted to an integer or a float,
1731following its syntax and the rules of the Lua lexer. 1724following its syntax and the rules of the Lua lexer.
1732(The string may have also leading and trailing spaces and a sign.) 1725(The string may have also leading and trailing spaces and a sign.)
1733All conversions from strings to numbers 1726All conversions from strings to numbers
1734accept both a dot and the current locale mark 1727accept both a dot and the current locale mark
1735as the radix character. 1728as the radix character.
1736(The Lua lexer, however, accepts only a dot.) 1729(The Lua lexer, however, accepts only a dot.)
1730If the string is not a valid numeral,
1731the conversion fails.
1732If necessary, the result of this first step is then converted
1733to the required number subtype following the previous rules
1734for conversions between floats and integers.
1735
1736The string library uses metamethods that try to coerce
1737strings to numbers in all arithmetic operations.
1738If the conversion fails,
1739the library calls the metamethod of the other operand
1740(if present) or it raises an error.
1737 1741
1738The conversion from numbers to strings uses a 1742The conversion from numbers to strings uses a
1739non-specified human-readable format. 1743non-specified human-readable format.
1740For complete control over how numbers are converted to strings, 1744To convert numbers to strings in any specific way,
1741use the @id{format} function from the string library 1745use the function @Lid{string.format}.
1742@seeF{string.format}.
1743 1746
1744} 1747}
1745 1748
@@ -1758,7 +1761,7 @@ These operators always result in @false or @true.
1758Equality (@T{==}) first compares the type of its operands. 1761Equality (@T{==}) first compares the type of its operands.
1759If the types are different, then the result is @false. 1762If the types are different, then the result is @false.
1760Otherwise, the values of the operands are compared. 1763Otherwise, the values of the operands are compared.
1761Strings are equal if they have the same content. 1764Strings are equal if they have the same byte content.
1762Numbers are equal if they denote the same mathematical value. 1765Numbers are equal if they denote the same mathematical value.
1763 1766
1764Tables, userdata, and threads 1767Tables, userdata, and threads
@@ -1787,8 +1790,8 @@ The operator @T{~=} is exactly the negation of equality (@T{==}).
1787 1790
1788The order operators work as follows. 1791The order operators work as follows.
1789If both arguments are numbers, 1792If both arguments are numbers,
1790then they are compared according to their mathematical values 1793then they are compared according to their mathematical values,
1791(regardless of their subtypes). 1794regardless of their subtypes.
1792Otherwise, if both arguments are strings, 1795Otherwise, if both arguments are strings,
1793then their values are compared according to the current locale. 1796then their values are compared according to the current locale.
1794Otherwise, Lua tries to call the @idx{__lt} or the @idx{__le} 1797Otherwise, Lua tries to call the @idx{__lt} or the @idx{__le}
@@ -1797,8 +1800,8 @@ A comparison @T{a > b} is translated to @T{b < a}
1797and @T{a >= b} is translated to @T{b <= a}. 1800and @T{a >= b} is translated to @T{b <= a}.
1798 1801
1799Following the @x{IEEE 754} standard, 1802Following the @x{IEEE 754} standard,
1800@x{NaN} is considered neither less than, 1803the special value @x{NaN} is considered neither less than,
1801nor equal to, nor greater than any value (including itself). 1804nor equal to, nor greater than any value, including itself.
1802 1805
1803} 1806}
1804 1807
@@ -1836,8 +1839,9 @@ false or nil --> nil
1836@sect3{concat| @title{Concatenation} 1839@sect3{concat| @title{Concatenation}
1837The string @x{concatenation} operator in Lua is 1840The string @x{concatenation} operator in Lua is
1838denoted by two dots (@Char{..}). 1841denoted by two dots (@Char{..}).
1839If both operands are strings or numbers, then they are converted to 1842If both operands are strings or numbers,
1840strings according to the rules described in @See{coercion}. 1843then the numbers are converted to strings
1844in a non-specified format @see{coercion}.
1841Otherwise, the @idx{__concat} metamethod is called @see{metatable}. 1845Otherwise, the @idx{__concat} metamethod is called @see{metatable}.
1842 1846
1843} 1847}
@@ -1846,9 +1850,9 @@ Otherwise, the @idx{__concat} metamethod is called @see{metatable}.
1846 1850
1847The length operator is denoted by the unary prefix operator @T{#}. 1851The length operator is denoted by the unary prefix operator @T{#}.
1848 1852
1849The length of a string is its number of bytes 1853The length of a string is its number of bytes.
1850(that is, the usual meaning of string length when each 1854(That is the usual meaning of string length when each
1851character is one byte). 1855character is one byte.)
1852 1856
1853The length operator applied on a table 1857The length operator applied on a table
1854returns a @x{border} in that table. 1858returns a @x{border} in that table.
@@ -1867,8 +1871,10 @@ For instance, the table @T{{10, 20, 30, 40, 50}} is a sequence,
1867as it has only one border (5). 1871as it has only one border (5).
1868The table @T{{10, 20, 30, nil, 50}} has two borders (3 and 5), 1872The table @T{{10, 20, 30, nil, 50}} has two borders (3 and 5),
1869and therefore it is not a sequence. 1873and therefore it is not a sequence.
1874(The @nil at index 4 is called a @emphx{hole}.)
1870The table @T{{nil, 20, 30, nil, nil, 60, nil}} 1875The table @T{{nil, 20, 30, nil, nil, 60, nil}}
1871has three borders (0, 3, and 6), 1876has three borders (0, 3, and 6) and three holes
1877(at indices 1, 4, and 5),
1872so it is not a sequence, too. 1878so it is not a sequence, too.
1873The table @T{{}} is a sequence with border 0. 1879The table @T{{}} is a sequence with border 0.
1874Note that non-natural keys do not interfere 1880Note that non-natural keys do not interfere
@@ -1936,10 +1942,10 @@ Each field of the form @T{[exp1] = exp2} adds to the new table an entry
1936with key @id{exp1} and value @id{exp2}. 1942with key @id{exp1} and value @id{exp2}.
1937A field of the form @T{name = exp} is equivalent to 1943A field of the form @T{name = exp} is equivalent to
1938@T{["name"] = exp}. 1944@T{["name"] = exp}.
1939Finally, fields of the form @id{exp} are equivalent to 1945Fields of the form @id{exp} are equivalent to
1940@T{[i] = exp}, where @id{i} are consecutive integers 1946@T{[i] = exp}, where @id{i} are consecutive integers
1941starting with 1. 1947starting with 1;
1942Fields in the other formats do not affect this counting. 1948fields in the other formats do not affect this counting.
1943For example, 1949For example,
1944@verbatim{ 1950@verbatim{
1945a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } 1951a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
@@ -1982,8 +1988,9 @@ first @bnfNter{prefixexp} and @bnfNter{args} are evaluated.
1982If the value of @bnfNter{prefixexp} has type @emph{function}, 1988If the value of @bnfNter{prefixexp} has type @emph{function},
1983then this function is called 1989then this function is called
1984with the given arguments. 1990with the given arguments.
1985Otherwise, the @bnfNter{prefixexp} @idx{__call} metamethod is called, 1991Otherwise, if present,
1986having as first argument the value of @bnfNter{prefixexp}, 1992the @bnfNter{prefixexp} @idx{__call} metamethod is called:
1993its first argument is the value of @bnfNter{prefixexp},
1987followed by the original call arguments 1994followed by the original call arguments
1988@see{metatable}. 1995@see{metatable}.
1989 1996
@@ -1991,7 +1998,7 @@ The form
1991@Produc{ 1998@Produc{
1992@producname{functioncall}@producbody{prefixexp @bnfter{:} @bnfNter{Name} args} 1999@producname{functioncall}@producbody{prefixexp @bnfter{:} @bnfNter{Name} args}
1993} 2000}
1994can be used to call @Q{methods}. 2001can be used to emulate methods.
1995A call @T{v:name(@rep{args})} 2002A call @T{v:name(@rep{args})}
1996is syntactic sugar for @T{v.name(v,@rep{args})}, 2003is syntactic sugar for @T{v.name(v,@rep{args})},
1997except that @id{v} is evaluated only once. 2004except that @id{v} is evaluated only once.
@@ -2014,7 +2021,7 @@ that is, the argument list is a single literal string.
2014A call of the form @T{return @rep{functioncall}} not in the 2021A call of the form @T{return @rep{functioncall}} not in the
2015scope of a to-be-closed variable is called a @def{tail call}. 2022scope of a to-be-closed variable is called a @def{tail call}.
2016Lua implements @def{proper tail calls} 2023Lua implements @def{proper tail calls}
2017(or @emph{proper tail recursion}): 2024(or @def{proper tail recursion}):
2018in a tail call, 2025in a tail call,
2019the called function reuses the stack entry of the calling function. 2026the called function reuses the stack entry of the calling function.
2020Therefore, there is no limit on the number of nested tail calls that 2027Therefore, there is no limit on the number of nested tail calls that
@@ -2086,10 +2093,11 @@ contains references to @id{f}.)
2086A function definition is an executable expression, 2093A function definition is an executable expression,
2087whose value has type @emph{function}. 2094whose value has type @emph{function}.
2088When Lua precompiles a chunk, 2095When Lua precompiles a chunk,
2089all its function bodies are precompiled too. 2096all its function bodies are precompiled too,
2097but they are not created yet.
2090Then, whenever Lua executes the function definition, 2098Then, whenever Lua executes the function definition,
2091the function is @emph{instantiated} (or @emph{closed}). 2099the function is @emph{instantiated} (or @emph{closed}).
2092This function instance (or @emphx{closure}) 2100This function instance, or @emphx{closure},
2093is the final value of the expression. 2101is the final value of the expression.
2094 2102
2095Parameters act as local variables that are 2103Parameters act as local variables that are
@@ -2152,8 +2160,8 @@ that a function may return.
2152This limit is guaranteed to be greater than 1000. 2160This limit is guaranteed to be greater than 1000.
2153 2161
2154The @emphx{colon} syntax 2162The @emphx{colon} syntax
2155is used for defining @def{methods}, 2163is used to emulate @def{methods},
2156that is, functions that have an implicit extra parameter @idx{self}. 2164adding an implicit extra parameter @idx{self} to the function.
2157Thus, the statement 2165Thus, the statement
2158@verbatim{ 2166@verbatim{
2159function t.a.b.c:f (@rep{params}) @rep{body} end 2167function t.a.b.c:f (@rep{params}) @rep{body} end
@@ -2282,8 +2290,8 @@ For convenience,
2282most query operations in the API do not follow a strict stack discipline. 2290most query operations in the API do not follow a strict stack discipline.
2283Instead, they can refer to any element in the stack 2291Instead, they can refer to any element in the stack
2284by using an @emph{index}:@index{index (API stack)} 2292by using an @emph{index}:@index{index (API stack)}
2285A positive index represents an absolute stack position 2293A positive index represents an absolute stack position,
2286(starting @N{at 1}); 2294starting @N{at 1} as the bottom of the stack;
2287a negative index represents an offset relative to the top of the stack. 2295a negative index represents an offset relative to the top of the stack.
2288More specifically, if the stack has @rep{n} elements, 2296More specifically, if the stack has @rep{n} elements,
2289then @N{index 1} represents the first element 2297then @N{index 1} represents the first element
@@ -2353,7 +2361,7 @@ functions in the API work with acceptable indices.
2353Acceptable indices serve to avoid extra tests 2361Acceptable indices serve to avoid extra tests
2354against the stack top when querying the stack. 2362against the stack top when querying the stack.
2355For instance, a @N{C function} can query its third argument 2363For instance, a @N{C function} can query its third argument
2356without the need to first check whether there is a third argument, 2364without the need to check whether there is a third argument,
2357that is, without the need to check whether 3 is a valid index. 2365that is, without the need to check whether 3 is a valid index.
2358 2366
2359For functions that can be called with acceptable indices, 2367For functions that can be called with acceptable indices,
@@ -2385,7 +2393,8 @@ current function
2385which is one plus the maximum number of upvalues in a closure), 2393which is one plus the maximum number of upvalues in a closure),
2386produces an acceptable but invalid index. 2394produces an acceptable but invalid index.
2387 2395
2388A @N{C closure} can also change the values of its corresponding upvalues. 2396A @N{C closure} can also change the values
2397of its corresponding upvalues.
2389 2398
2390} 2399}
2391 2400
@@ -2394,7 +2403,7 @@ A @N{C closure} can also change the values of its corresponding upvalues.
2394Lua provides a @def{registry}, 2403Lua provides a @def{registry},
2395a predefined table that can be used by any @N{C code} to 2404a predefined table that can be used by any @N{C code} to
2396store whatever Lua values it needs to store. 2405store whatever Lua values it needs to store.
2397The registry table is always located at pseudo-index 2406The registry table is always accessible at pseudo-index
2398@defid{LUA_REGISTRYINDEX}. 2407@defid{LUA_REGISTRYINDEX}.
2399Any @N{C library} can store data into this table, 2408Any @N{C library} can store data into this table,
2400but it must take care to choose keys 2409but it must take care to choose keys
@@ -2410,7 +2419,8 @@ uppercase letters are reserved for Lua.
2410The integer keys in the registry are used 2419The integer keys in the registry are used
2411by the reference mechanism @seeC{luaL_ref} 2420by the reference mechanism @seeC{luaL_ref}
2412and by some predefined values. 2421and by some predefined values.
2413Therefore, integer keys must not be used for other purposes. 2422Therefore, integer keys in the registry
2423must not be used for other purposes.
2414 2424
2415When you create a new Lua state, 2425When you create a new Lua state,
2416its registry comes with some predefined values. 2426its registry comes with some predefined values.
@@ -2435,15 +2445,16 @@ the @x{global environment}.
2435Internally, Lua uses the C @id{longjmp} facility to handle errors. 2445Internally, Lua uses the C @id{longjmp} facility to handle errors.
2436(Lua will use exceptions if you compile it as C++; 2446(Lua will use exceptions if you compile it as C++;
2437search for @id{LUAI_THROW} in the source code for details.) 2447search for @id{LUAI_THROW} in the source code for details.)
2438When Lua faces any error 2448When Lua faces any error,
2439(such as a @x{memory allocation error} or a type error) 2449such as a @x{memory allocation error} or a type error,
2440it @emph{raises} an error; 2450it @emph{raises} an error;
2441that is, it does a long jump. 2451that is, it does a long jump.
2442A @emphx{protected environment} uses @id{setjmp} 2452A @emphx{protected environment} uses @id{setjmp}
2443to set a recovery point; 2453to set a recovery point;
2444any error jumps to the most recent active recovery point. 2454any error jumps to the most recent active recovery point.
2445 2455
2446Inside a @N{C function} you can raise an error by calling @Lid{lua_error}. 2456Inside a @N{C function} you can raise an error explicitly
2457by calling @Lid{lua_error}.
2447 2458
2448Most functions in the API can raise an error, 2459Most functions in the API can raise an error,
2449for instance due to a @x{memory allocation error}. 2460for instance due to a @x{memory allocation error}.
@@ -2503,9 +2514,9 @@ the @emph{original function}.
2503This original function then calls one of those three functions in the C API, 2514This original function then calls one of those three functions in the C API,
2504which we will call the @emph{callee function}, 2515which we will call the @emph{callee function},
2505that then yields the current thread. 2516that then yields the current thread.
2506(This can happen when the callee function is @Lid{lua_yieldk}, 2517This can happen when the callee function is @Lid{lua_yieldk},
2507or when the callee function is either @Lid{lua_callk} or @Lid{lua_pcallk} 2518or when the callee function is either @Lid{lua_callk} or @Lid{lua_pcallk}
2508and the function called by them yields.) 2519and the function called by them yields.
2509 2520
2510Suppose the running thread yields while executing the callee function. 2521Suppose the running thread yields while executing the callee function.
2511After the thread resumes, 2522After the thread resumes,
@@ -2566,11 +2577,11 @@ you can do the equivalent work directly inside the original function.)
2566 2577
2567Besides the Lua state, 2578Besides the Lua state,
2568the continuation function has two other parameters: 2579the continuation function has two other parameters:
2569the final status of the call plus the context value (@id{ctx}) that 2580the final status of the call and the context value (@id{ctx}) that
2570was passed originally to @Lid{lua_pcallk}. 2581was passed originally to @Lid{lua_pcallk}.
2571(Lua does not use this context value; 2582Lua does not use this context value;
2572it only passes this value from the original function to the 2583it only passes this value from the original function to the
2573continuation function.) 2584continuation function.
2574For @Lid{lua_pcallk}, 2585For @Lid{lua_pcallk},
2575the status is the same value that would be returned by @Lid{lua_pcallk}, 2586the status is the same value that would be returned by @Lid{lua_pcallk},
2576except that it is @Lid{LUA_YIELD} when being executed after a yield 2587except that it is @Lid{LUA_YIELD} when being executed after a yield
@@ -2617,8 +2628,8 @@ A field in the form @T{x|y} means the function can push (or pop)
2617depending on the situation; 2628depending on the situation;
2618an interrogation mark @Char{?} means that 2629an interrogation mark @Char{?} means that
2619we cannot know how many elements the function pops/pushes 2630we cannot know how many elements the function pops/pushes
2620by looking only at its arguments 2631by looking only at its arguments.
2621(e.g., they may depend on what is on the stack). 2632(For instance, they may depend on what is on the stack.)
2622The third field, @T{x}, 2633The third field, @T{x},
2623tells whether the function may raise errors: 2634tells whether the function may raise errors:
2624@Char{-} means the function never raises any error; 2635@Char{-} means the function never raises any error;
@@ -2673,11 +2684,11 @@ Lua assumes the following behavior from the allocator function:
2673 2684
2674When @id{nsize} is zero, 2685When @id{nsize} is zero,
2675the allocator must behave like @id{free} 2686the allocator must behave like @id{free}
2676and return @id{NULL}. 2687and then return @id{NULL}.
2677 2688
2678When @id{nsize} is not zero, 2689When @id{nsize} is not zero,
2679the allocator must behave like @id{realloc}. 2690the allocator must behave like @id{realloc}.
2680The allocator returns @id{NULL} 2691In particular, the allocator returns @id{NULL}
2681if and only if it cannot fulfill the request. 2692if and only if it cannot fulfill the request.
2682 2693
2683Here is a simple implementation for the @x{allocator function}. 2694Here is a simple implementation for the @x{allocator function}.
@@ -2752,9 +2763,9 @@ in direct order;
2752that is, the first argument is pushed first. 2763that is, the first argument is pushed first.
2753Finally you call @Lid{lua_call}; 2764Finally you call @Lid{lua_call};
2754@id{nargs} is the number of arguments that you pushed onto the stack. 2765@id{nargs} is the number of arguments that you pushed onto the stack.
2755All arguments and the function value are popped from the stack 2766When the function returns,
2756when the function is called. 2767all arguments and the function value are popped
2757The function results are pushed onto the stack when the function returns. 2768and the function results are pushed onto the stack.
2758The number of results is adjusted to @id{nresults}, 2769The number of results is adjusted to @id{nresults},
2759unless @id{nresults} is @defid{LUA_MULTRET}. 2770unless @id{nresults} is @defid{LUA_MULTRET}.
2760In this case, all results from the function are pushed; 2771In this case, all results from the function are pushed;
@@ -2819,7 +2830,7 @@ The first argument (if any) is at index 1
2819and its last argument is at index @T{lua_gettop(L)}. 2830and its last argument is at index @T{lua_gettop(L)}.
2820To return values to Lua, a @N{C function} just pushes them onto the stack, 2831To return values to Lua, a @N{C function} just pushes them onto the stack,
2821in direct order (the first result is pushed first), 2832in direct order (the first result is pushed first),
2822and returns the number of results. 2833and returns in C the number of results.
2823Any other value in the stack below the results will be properly 2834Any other value in the stack below the results will be properly
2824discarded by Lua. 2835discarded by Lua.
2825Like a Lua function, a @N{C function} called by Lua can also return 2836Like a Lua function, a @N{C function} called by Lua can also return
@@ -2853,8 +2864,8 @@ static int foo (lua_State *L) {
2853@APIEntry{int lua_checkstack (lua_State *L, int n);| 2864@APIEntry{int lua_checkstack (lua_State *L, int n);|
2854@apii{0,0,-} 2865@apii{0,0,-}
2855 2866
2856Ensures that the stack has space for at least @id{n} extra slots 2867Ensures that the stack has space for at least @id{n} extra slots,
2857(that is, that you can safely push up to @id{n} values into it). 2868that is, that you can safely push up to @id{n} values into it.
2858It returns false if it cannot fulfill the request, 2869It returns false if it cannot fulfill the request,
2859either because it would cause the stack 2870either because it would cause the stack
2860to be greater than a fixed maximum size 2871to be greater than a fixed maximum size
@@ -2872,6 +2883,7 @@ it is left unchanged.
2872Destroys all objects in the given Lua state 2883Destroys all objects in the given Lua state
2873(calling the corresponding garbage-collection metamethods, if any) 2884(calling the corresponding garbage-collection metamethods, if any)
2874and frees all dynamic memory used by this state. 2885and frees all dynamic memory used by this state.
2886
2875On several platforms, you may not need to call this function, 2887On several platforms, you may not need to call this function,
2876because all resources are naturally released when the host program ends. 2888because all resources are naturally released when the host program ends.
2877On the other hand, long-running programs that create multiple states, 2889On the other hand, long-running programs that create multiple states,
@@ -2934,7 +2946,7 @@ will have as a sequence;
2934parameter @id{nrec} is a hint for how many other elements 2946parameter @id{nrec} is a hint for how many other elements
2935the table will have. 2947the table will have.
2936Lua may use these hints to preallocate memory for the new table. 2948Lua may use these hints to preallocate memory for the new table.
2937This preallocation is useful for performance when you know in advance 2949This preallocation may help performance when you know in advance
2938how many elements the table will have. 2950how many elements the table will have.
2939Otherwise you can use the function @Lid{lua_newtable}. 2951Otherwise you can use the function @Lid{lua_newtable}.
2940 2952
@@ -3369,11 +3381,11 @@ Other upvalues are initialized with @nil.
3369@APIEntry{lua_State *lua_newstate (lua_Alloc f, void *ud);| 3381@APIEntry{lua_State *lua_newstate (lua_Alloc f, void *ud);|
3370@apii{0,0,-} 3382@apii{0,0,-}
3371 3383
3372Creates a new thread running in a new, independent state. 3384Creates a new independent state and returns its main thread.
3373Returns @id{NULL} if it cannot create the thread or the state 3385Returns @id{NULL} if it cannot create the state
3374(due to lack of memory). 3386(due to lack of memory).
3375The argument @id{f} is the @x{allocator function}; 3387The argument @id{f} is the @x{allocator function};
3376Lua does all memory allocation for this state 3388Lua will do all memory allocation for this state
3377through this function @seeF{lua_Alloc}. 3389through this function @seeF{lua_Alloc}.
3378The second argument, @id{ud}, is an opaque pointer that Lua 3390The second argument, @id{ud}, is an opaque pointer that Lua
3379passes to the allocator in every call. 3391passes to the allocator in every call.
@@ -3407,7 +3419,7 @@ like any Lua object.
3407@apii{0,1,m} 3419@apii{0,1,m}
3408 3420
3409This function creates and pushes on the stack a new full userdata, 3421This function creates and pushes on the stack a new full userdata,
3410with @id{nuvalue} associated Lua values (called @id{user values}) 3422with @id{nuvalue} associated Lua values, called @id{user values},
3411plus an associated block of raw memory with @id{size} bytes. 3423plus an associated block of raw memory with @id{size} bytes.
3412(The user values can be set and read with the functions 3424(The user values can be set and read with the functions
3413@Lid{lua_setiuservalue} and @Lid{lua_getiuservalue}.) 3425@Lid{lua_setiuservalue} and @Lid{lua_getiuservalue}.)
@@ -3420,12 +3432,12 @@ The function returns the address of the block of memory.
3420@apii{1,2|0,v} 3432@apii{1,2|0,v}
3421 3433
3422Pops a key from the stack, 3434Pops a key from the stack,
3423and pushes a key@En{}value pair from the table at the given index 3435and pushes a key@En{}value pair from the table at the given index,
3424(the @Q{next} pair after the given key). 3436the @Q{next} pair after the given key.
3425If there are no more elements in the table, 3437If there are no more elements in the table,
3426then @Lid{lua_next} returns 0 (and pushes nothing). 3438then @Lid{lua_next} returns 0 and pushes nothing.
3427 3439
3428A typical traversal looks like this: 3440A typical table traversal looks like this:
3429@verbatim{ 3441@verbatim{
3430/* table is in the stack at index 't' */ 3442/* table is in the stack at index 't' */
3431lua_pushnil(L); /* first key */ 3443lua_pushnil(L); /* first key */
@@ -3440,7 +3452,7 @@ while (lua_next(L, t) != 0) {
3440} 3452}
3441 3453
3442While traversing a table, 3454While traversing a table,
3443do not call @Lid{lua_tolstring} directly on a key, 3455avoid calling @Lid{lua_tolstring} directly on a key,
3444unless you know that the key is actually a string. 3456unless you know that the key is actually a string.
3445Recall that @Lid{lua_tolstring} may change 3457Recall that @Lid{lua_tolstring} may change
3446the value at the given index; 3458the value at the given index;
@@ -3465,15 +3477,14 @@ but that can be changed to a single float or a long double.
3465 3477
3466@APIEntry{int lua_numbertointeger (lua_Number n, lua_Integer *p);| 3478@APIEntry{int lua_numbertointeger (lua_Number n, lua_Integer *p);|
3467 3479
3468Converts a Lua float to a Lua integer. 3480Tries to convert a Lua float to a Lua integer;
3469This macro assumes that @id{n} has an integral value. 3481the float @id{n} must have an integral value.
3470If that value is within the range of Lua integers, 3482If that value is within the range of Lua integers,
3471it is converted to an integer and assigned to @T{*p}. 3483it is converted to an integer and assigned to @T{*p}.
3472The macro results in a boolean indicating whether the 3484The macro results in a boolean indicating whether the
3473conversion was successful. 3485conversion was successful.
3474(Note that this range test can be tricky to do 3486(Note that this range test can be tricky to do
3475correctly without this macro, 3487correctly without this macro, due to rounding.)
3476due to roundings.)
3477 3488
3478This macro may evaluate its arguments more than once. 3489This macro may evaluate its arguments more than once.
3479 3490
@@ -3503,7 +3514,7 @@ Otherwise, @id{msgh} is the stack index of a
3503@emph{message handler}. 3514@emph{message handler}.
3504(This index cannot be a pseudo-index.) 3515(This index cannot be a pseudo-index.)
3505In case of runtime errors, 3516In case of runtime errors,
3506this function will be called with the error object 3517this handler will be called with the error object
3507and its return value will be the object 3518and its return value will be the object
3508returned on the stack by @Lid{lua_pcall}. 3519returned on the stack by @Lid{lua_pcall}.
3509 3520
@@ -3580,11 +3591,12 @@ and return its results @seeC{lua_CFunction}.
3580 3591
3581When a @N{C function} is created, 3592When a @N{C function} is created,
3582it is possible to associate some values with it, 3593it is possible to associate some values with it,
3583thus creating a @x{@N{C closure}} @see{c-closure}; 3594the so called upvalues;
3584these values are then accessible to the function whenever it is called. 3595these upvalues are then accessible to the function whenever it is called.
3585To associate values with a @N{C function}, 3596This association is called a @x{@N{C closure}} @see{c-closure}.
3586first these values must be pushed onto the stack 3597To create a @N{C closure},
3587(when there are multiple values, the first value is pushed first). 3598first the initial values for its upvalues must be pushed onto the stack.
3599(When there are multiple upvalues, the first value is pushed first.)
3588Then @Lid{lua_pushcclosure} 3600Then @Lid{lua_pushcclosure}
3589is called to create and push the @N{C function} onto the stack, 3601is called to create and push the @N{C function} onto the stack,
3590with the argument @id{n} telling how many values will be 3602with the argument @id{n} telling how many values will be
@@ -3604,6 +3616,7 @@ In that case, it never raises a memory error.
3604@apii{0,1,-} 3616@apii{0,1,-}
3605 3617
3606Pushes a @N{C function} onto the stack. 3618Pushes a @N{C function} onto the stack.
3619This function is equivalent to @Lid{lua_pushcclosure} with no upvalues.
3607 3620
3608} 3621}
3609 3622
@@ -3626,7 +3639,7 @@ The conversion specifiers can only be
3626@Char{%s} (inserts a zero-terminated string, with no size restrictions), 3639@Char{%s} (inserts a zero-terminated string, with no size restrictions),
3627@Char{%f} (inserts a @Lid{lua_Number}), 3640@Char{%f} (inserts a @Lid{lua_Number}),
3628@Char{%I} (inserts a @Lid{lua_Integer}), 3641@Char{%I} (inserts a @Lid{lua_Integer}),
3629@Char{%p} (inserts a pointer as a hexadecimal numeral), 3642@Char{%p} (inserts a pointer),
3630@Char{%d} (inserts an @T{int}), 3643@Char{%d} (inserts an @T{int}),
3631@Char{%c} (inserts an @T{int} as a one-byte character), and 3644@Char{%c} (inserts an @T{int} as a one-byte character), and
3632@Char{%U} (inserts a @T{long int} as a @x{UTF-8} byte sequence). 3645@Char{%U} (inserts a @T{long int} as a @x{UTF-8} byte sequence).
@@ -3670,6 +3683,7 @@ light userdata with the same @N{C address}.
3670 3683
3671This macro is equivalent to @Lid{lua_pushstring}, 3684This macro is equivalent to @Lid{lua_pushstring},
3672but should be used only when @id{s} is a literal string. 3685but should be used only when @id{s} is a literal string.
3686(Lua may optimize this case.)
3673 3687
3674} 3688}
3675 3689
@@ -3678,7 +3692,7 @@ but should be used only when @id{s} is a literal string.
3678 3692
3679Pushes the string pointed to by @id{s} with size @id{len} 3693Pushes the string pointed to by @id{s} with size @id{len}
3680onto the stack. 3694onto the stack.
3681Lua makes (or reuses) an internal copy of the given string, 3695Lua will make or reuse an internal copy of the given string,
3682so the memory at @id{s} can be freed or reused immediately after 3696so the memory at @id{s} can be freed or reused immediately after
3683the function returns. 3697the function returns.
3684The string can contain any binary data, 3698The string can contain any binary data,
@@ -3707,7 +3721,7 @@ Pushes a float with value @id{n} onto the stack.
3707 3721
3708Pushes the zero-terminated string pointed to by @id{s} 3722Pushes the zero-terminated string pointed to by @id{s}
3709onto the stack. 3723onto the stack.
3710Lua makes (or reuses) an internal copy of the given string, 3724Lua will make or reuse an internal copy of the given string,
3711so the memory at @id{s} can be freed or reused immediately after 3725so the memory at @id{s} can be freed or reused immediately after
3712the function returns. 3726the function returns.
3713 3727
@@ -3749,7 +3763,7 @@ instead of a variable number of arguments.
3749 3763
3750Returns 1 if the two values in indices @id{index1} and 3764Returns 1 if the two values in indices @id{index1} and
3751@id{index2} are primitively equal 3765@id{index2} are primitively equal
3752(that is, without calling the @idx{__eq} metamethod). 3766(that is, equal without calling the @idx{__eq} metamethod).
3753Otherwise @N{returns 0}. 3767Otherwise @N{returns 0}.
3754Also @N{returns 0} if any of the indices are not valid. 3768Also @N{returns 0} if any of the indices are not valid.
3755 3769
@@ -3796,8 +3810,8 @@ for strings, this is the string length;
3796for tables, this is the result of the length operator (@Char{#}) 3810for tables, this is the result of the length operator (@Char{#})
3797with no metamethods; 3811with no metamethods;
3798for userdata, this is the size of the block of memory allocated 3812for userdata, this is the size of the block of memory allocated
3799for the userdata; 3813for the userdata.
3800for other values, it @N{is 0}. 3814For other values, this call @N{returns 0}.
3801 3815
3802} 3816}
3803 3817
@@ -3842,8 +3856,8 @@ typedef const char * (*lua_Reader) (lua_State *L,
3842 size_t *size);| 3856 size_t *size);|
3843 3857
3844The reader function used by @Lid{lua_load}. 3858The reader function used by @Lid{lua_load}.
3845Every time it needs another piece of the chunk, 3859Every time @Lid{lua_load} needs another piece of the chunk,
3846@Lid{lua_load} calls the reader, 3860it calls the reader,
3847passing along its @id{data} parameter. 3861passing along its @id{data} parameter.
3848The reader must return a pointer to a block of memory 3862The reader must return a pointer to a block of memory
3849with a new piece of the chunk 3863with a new piece of the chunk
@@ -3912,9 +3926,9 @@ then you call @Lid{lua_resume},
3912with @id{nargs} being the number of arguments. 3926with @id{nargs} being the number of arguments.
3913This call returns when the coroutine suspends or finishes its execution. 3927This call returns when the coroutine suspends or finishes its execution.
3914When it returns, 3928When it returns,
3915@id{nresults} is updated and 3929@id{*nresults} is updated and
3916the top of the stack contains 3930the top of the stack contains
3917the @id{nresults} values passed to @Lid{lua_yield} 3931the @id{*nresults} values passed to @Lid{lua_yield}
3918or returned by the body function. 3932or returned by the body function.
3919@Lid{lua_resume} returns 3933@Lid{lua_resume} returns
3920@Lid{LUA_YIELD} if the coroutine yields, 3934@Lid{LUA_YIELD} if the coroutine yields,
@@ -3924,10 +3938,8 @@ or an error code in case of errors @seeC{lua_pcall}.
3924In case of errors, 3938In case of errors,
3925the error object is on the top of the stack. 3939the error object is on the top of the stack.
3926 3940
3927To resume a coroutine, 3941To resume a coroutine, you clear its stack,
3928you remove all results from the last @Lid{lua_yield}, 3942push only the values to be passed as results from @id{yield},
3929put on its stack only the values to
3930be passed as results from @id{yield},
3931and then call @Lid{lua_resume}. 3943and then call @Lid{lua_resume}.
3932 3944
3933The parameter @id{from} represents the coroutine that is resuming @id{L}. 3945The parameter @id{from} represents the coroutine that is resuming @id{L}.
@@ -4066,12 +4078,12 @@ which creates a Lua state from scratch.
4066 4078
4067Returns the status of the thread @id{L}. 4079Returns the status of the thread @id{L}.
4068 4080
4069The status can be 0 (@Lid{LUA_OK}) for a normal thread, 4081The status can be @Lid{LUA_OK} for a normal thread,
4070an error code if the thread finished the execution 4082an error code if the thread finished the execution
4071of a @Lid{lua_resume} with an error, 4083of a @Lid{lua_resume} with an error,
4072or @defid{LUA_YIELD} if the thread is suspended. 4084or @defid{LUA_YIELD} if the thread is suspended.
4073 4085
4074You can only call functions in threads with status @Lid{LUA_OK}. 4086You can call functions only in threads with status @Lid{LUA_OK}.
4075You can resume threads with status @Lid{LUA_OK} 4087You can resume threads with status @Lid{LUA_OK}
4076(to start a new coroutine) or @Lid{LUA_YIELD} 4088(to start a new coroutine) or @Lid{LUA_YIELD}
4077(to resume a coroutine). 4089(to resume a coroutine).
@@ -4127,7 +4139,7 @@ Like a to-be-closed variable in Lua,
4127the value at that index in the stack will be closed 4139the value at that index in the stack will be closed
4128when it goes out of scope. 4140when it goes out of scope.
4129Here, in the context of a C function, 4141Here, in the context of a C function,
4130to go out of scope means that the running function returns (to Lua), 4142to go out of scope means that the running function returns to Lua,
4131there is an error, 4143there is an error,
4132or the index is removed from the stack through 4144or the index is removed from the stack through
4133@Lid{lua_settop} or @Lid{lua_pop}. 4145@Lid{lua_settop} or @Lid{lua_pop}.
@@ -4250,7 +4262,7 @@ otherwise, the function returns @id{NULL}.
4250If the value at the given index is a full userdata, 4262If the value at the given index is a full userdata,
4251returns its memory-block address. 4263returns its memory-block address.
4252If the value is a light userdata, 4264If the value is a light userdata,
4253returns its pointer. 4265returns its value (a pointer).
4254Otherwise, returns @id{NULL}. 4266Otherwise, returns @id{NULL}.
4255 4267
4256} 4268}
@@ -4259,7 +4271,7 @@ Otherwise, returns @id{NULL}.
4259@apii{0,0,-} 4271@apii{0,0,-}
4260 4272
4261Returns the type of the value in the given valid index, 4273Returns the type of the value in the given valid index,
4262or @id{LUA_TNONE} for a non-valid (but acceptable) index. 4274or @id{LUA_TNONE} for a non-valid but acceptable index.
4263The types returned by @Lid{lua_type} are coded by the following constants 4275The types returned by @Lid{lua_type} are coded by the following constants
4264defined in @id{lua.h}: 4276defined in @id{lua.h}:
4265@defid{LUA_TNIL}, 4277@defid{LUA_TNIL},
@@ -4335,8 +4347,8 @@ typedef int (*lua_Writer) (lua_State *L,
4335 void* ud);| 4347 void* ud);|
4336 4348
4337The type of the writer function used by @Lid{lua_dump}. 4349The type of the writer function used by @Lid{lua_dump}.
4338Every time it produces another piece of chunk, 4350Every time @Lid{lua_dump} produces another piece of chunk,
4339@Lid{lua_dump} calls the writer, 4351it calls the writer,
4340passing along the buffer to be written (@id{p}), 4352passing along the buffer to be written (@id{p}),
4341its size (@id{sz}), 4353its size (@id{sz}),
4342and the @id{ud} parameter supplied to @Lid{lua_dump}. 4354and the @id{ud} parameter supplied to @Lid{lua_dump}.
@@ -4414,7 +4426,7 @@ of the (Lua) function that triggered the hook.
4414 4426
4415This function can raise an error if it is called from a thread 4427This function can raise an error if it is called from a thread
4416with a pending C call with no continuation function 4428with a pending C call with no continuation function
4417(what is called a @emphx{C-call boundary}, 4429(what is called a @emphx{C-call boundary}),
4418or it is called from a thread that is not running inside a resume 4430or it is called from a thread that is not running inside a resume
4419(typically the main thread). 4431(typically the main thread).
4420 4432
@@ -4439,6 +4451,7 @@ typedef struct lua_Debug {
4439 const char *namewhat; /* (n) */ 4451 const char *namewhat; /* (n) */
4440 const char *what; /* (S) */ 4452 const char *what; /* (S) */
4441 const char *source; /* (S) */ 4453 const char *source; /* (S) */
4454 size_t srclen; /* (S) */
4442 int currentline; /* (l) */ 4455 int currentline; /* (l) */
4443 int linedefined; /* (S) */ 4456 int linedefined; /* (S) */
4444 int lastlinedefined; /* (S) */ 4457 int lastlinedefined; /* (S) */
@@ -4459,13 +4472,13 @@ information about a function or an activation record.
4459@Lid{lua_getstack} fills only the private part 4472@Lid{lua_getstack} fills only the private part
4460of this structure, for later use. 4473of this structure, for later use.
4461To fill the other fields of @Lid{lua_Debug} with useful information, 4474To fill the other fields of @Lid{lua_Debug} with useful information,
4462call @Lid{lua_getinfo}. 4475you must call @Lid{lua_getinfo}.
4463 4476
4464The fields of @Lid{lua_Debug} have the following meaning: 4477The fields of @Lid{lua_Debug} have the following meaning:
4465@description{ 4478@description{
4466 4479
4467@item{@id{source}| 4480@item{@id{source}|
4468the name of the chunk that created the function. 4481the source of the chunk that created the function.
4469If @T{source} starts with a @Char{@At}, 4482If @T{source} starts with a @Char{@At},
4470it means that the function was defined in a file where 4483it means that the function was defined in a file where
4471the file name follows the @Char{@At}. 4484the file name follows the @Char{@At}.
@@ -4476,6 +4489,10 @@ the function was defined in a string where
4476@T{source} is that string. 4489@T{source} is that string.
4477} 4490}
4478 4491
4492@item{@id{srclen}|
4493The length of the string @id{source}.
4494}
4495
4479@item{@id{short_src}| 4496@item{@id{short_src}|
4480a @Q{printable} version of @T{source}, to be used in error messages. 4497a @Q{printable} version of @T{source}, to be used in error messages.
4481} 4498}
@@ -4694,9 +4711,9 @@ of the function executing at a given level.
4694@N{Level 0} is the current running function, 4711@N{Level 0} is the current running function,
4695whereas level @M{n+1} is the function that has called level @M{n} 4712whereas level @M{n+1} is the function that has called level @M{n}
4696(except for tail calls, which do not count on the stack). 4713(except for tail calls, which do not count on the stack).
4697When there are no errors, @Lid{lua_getstack} returns 1; 4714When called with a level greater than the stack depth,
4698when called with a level greater than the stack depth, 4715@Lid{lua_getstack} returns 0;
4699it returns 0. 4716otherwise it returns 1.
4700 4717
4701} 4718}
4702 4719
@@ -4716,10 +4733,6 @@ as a name for all upvalues.
4716upvalues are the external local variables that the function uses, 4733upvalues are the external local variables that the function uses,
4717and that are consequently included in its closure.) 4734and that are consequently included in its closure.)
4718 4735
4719Upvalues have no particular order,
4720as they are active through the whole function.
4721They are numbered in an arbitrary order.
4722
4723} 4736}
4724 4737
4725@APIEntry{typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);| 4738@APIEntry{typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);|
@@ -4780,24 +4793,22 @@ before the function gets its arguments.
4780 4793
4781@item{The return hook| is called when the interpreter returns from a function. 4794@item{The return hook| is called when the interpreter returns from a function.
4782The hook is called just before Lua leaves the function. 4795The hook is called just before Lua leaves the function.
4783There is no standard way to access the values
4784to be returned by the function.
4785} 4796}
4786 4797
4787@item{The line hook| is called when the interpreter is about to 4798@item{The line hook| is called when the interpreter is about to
4788start the execution of a new line of code, 4799start the execution of a new line of code,
4789or when it jumps back in the code (even to the same line). 4800or when it jumps back in the code (even to the same line).
4790(This event only happens while Lua is executing a Lua function.) 4801This event only happens while Lua is executing a Lua function.
4791} 4802}
4792 4803
4793@item{The count hook| is called after the interpreter executes every 4804@item{The count hook| is called after the interpreter executes every
4794@T{count} instructions. 4805@T{count} instructions.
4795(This event only happens while Lua is executing a Lua function.) 4806This event only happens while Lua is executing a Lua function.
4796} 4807}
4797 4808
4798} 4809}
4799 4810
4800A hook is disabled by setting @id{mask} to zero. 4811Hooks are disabled by setting @id{mask} to zero.
4801 4812
4802} 4813}
4803 4814
@@ -4813,7 +4824,7 @@ Returns @id{NULL} (and pops nothing)
4813when the index is greater than 4824when the index is greater than
4814the number of active local variables. 4825the number of active local variables.
4815 4826
4816Parameters @id{ar} and @id{n} are as in function @Lid{lua_getlocal}. 4827Parameters @id{ar} and @id{n} are as in the function @Lid{lua_getlocal}.
4817 4828
4818} 4829}
4819 4830
@@ -4828,7 +4839,8 @@ It also pops the value from the stack.
4828Returns @id{NULL} (and pops nothing) 4839Returns @id{NULL} (and pops nothing)
4829when the index @id{n} is greater than the number of upvalues. 4840when the index @id{n} is greater than the number of upvalues.
4830 4841
4831Parameters @id{funcindex} and @id{n} are as in function @Lid{lua_getupvalue}. 4842Parameters @id{funcindex} and @id{n} are as in
4843the function @Lid{lua_getupvalue}.
4832 4844
4833} 4845}
4834 4846
@@ -4844,7 +4856,8 @@ Lua closures that share an upvalue
4844(that is, that access a same external local variable) 4856(that is, that access a same external local variable)
4845will return identical ids for those upvalue indices. 4857will return identical ids for those upvalue indices.
4846 4858
4847Parameters @id{funcindex} and @id{n} are as in function @Lid{lua_getupvalue}, 4859Parameters @id{funcindex} and @id{n} are as in
4860the function @Lid{lua_getupvalue},
4848but @id{n} cannot be greater than the number of upvalues. 4861but @id{n} cannot be greater than the number of upvalues.
4849 4862
4850} 4863}
@@ -5086,7 +5099,7 @@ this function calls this field passing the object as its only argument.
5086In this case this function returns true and pushes onto the 5099In this case this function returns true and pushes onto the
5087stack the value returned by the call. 5100stack the value returned by the call.
5088If there is no metatable or no metamethod, 5101If there is no metatable or no metamethod,
5089this function returns false (without pushing any value on the stack). 5102this function returns false without pushing any value on the stack.
5090 5103
5091} 5104}
5092 5105
@@ -5103,7 +5116,7 @@ of any type (including @nil) at position @id{arg}.
5103 5116
5104Checks whether the function argument @id{arg} is an integer 5117Checks whether the function argument @id{arg} is an integer
5105(or can be converted to an integer) 5118(or can be converted to an integer)
5106and returns this integer cast to a @Lid{lua_Integer}. 5119and returns this integer.
5107 5120
5108} 5121}
5109 5122
@@ -5112,7 +5125,7 @@ and returns this integer cast to a @Lid{lua_Integer}.
5112 5125
5113Checks whether the function argument @id{arg} is a string 5126Checks whether the function argument @id{arg} is a string
5114and returns this string; 5127and returns this string;
5115if @id{l} is not @id{NULL} fills @T{*l} 5128if @id{l} is not @id{NULL} fills its referent
5116with the string's length. 5129with the string's length.
5117 5130
5118This function uses @Lid{lua_tolstring} to get its result, 5131This function uses @Lid{lua_tolstring} to get its result,
@@ -5124,7 +5137,7 @@ so all conversions and caveats of that function apply here.
5124@apii{0,0,v} 5137@apii{0,0,v}
5125 5138
5126Checks whether the function argument @id{arg} is a number 5139Checks whether the function argument @id{arg} is a number
5127and returns this number. 5140and returns this number converted to a @id{lua_Number}.
5128 5141
5129} 5142}
5130 5143
@@ -5300,8 +5313,8 @@ const char *luaL_gsub (lua_State *L,
5300 const char *r);| 5313 const char *r);|
5301@apii{0,1,m} 5314@apii{0,1,m}
5302 5315
5303Creates a copy of string @id{s} by replacing 5316Creates a copy of string @id{s},
5304any occurrence of the string @id{p} 5317replacing any occurrence of the string @id{p}
5305with the string @id{r}. 5318with the string @id{r}.
5306Pushes the resulting string on the stack and returns it. 5319Pushes the resulting string on the stack and returns it.
5307 5320
@@ -5314,7 +5327,7 @@ Returns the @Q{length} of the value at the given index
5314as a number; 5327as a number;
5315it is equivalent to the @Char{#} operator in Lua @see{len-op}. 5328it is equivalent to the @Char{#} operator in Lua @see{len-op}.
5316Raises an error if the result of the operation is not an integer. 5329Raises an error if the result of the operation is not an integer.
5317(This case only can happen through metamethods.) 5330(This case can only happen through metamethods.)
5318 5331
5319} 5332}
5320 5333
@@ -5345,7 +5358,7 @@ buffer pointed to by @id{buff} with size @id{sz}.
5345This function returns the same results as @Lid{lua_load}. 5358This function returns the same results as @Lid{lua_load}.
5346@id{name} is the chunk name, 5359@id{name} is the chunk name,
5347used for debug information and error messages. 5360used for debug information and error messages.
5348The string @id{mode} works as in function @Lid{lua_load}. 5361The string @id{mode} works as in the function @Lid{lua_load}.
5349 5362
5350} 5363}
5351 5364
@@ -5368,7 +5381,7 @@ If @id{filename} is @id{NULL},
5368then it loads from the standard input. 5381then it loads from the standard input.
5369The first line in the file is ignored if it starts with a @T{#}. 5382The first line in the file is ignored if it starts with a @T{#}.
5370 5383
5371The string @id{mode} works as in function @Lid{lua_load}. 5384The string @id{mode} works as in the function @Lid{lua_load}.
5372 5385
5373This function returns the same results as @Lid{lua_load}, 5386This function returns the same results as @Lid{lua_load},
5374but it has an extra error code @defid{LUA_ERRFILE} 5387but it has an extra error code @defid{LUA_ERRFILE}
@@ -5399,7 +5412,7 @@ it does not run it.
5399@apii{0,1,m} 5412@apii{0,1,m}
5400 5413
5401Creates a new table and registers there 5414Creates a new table and registers there
5402the functions in list @id{l}. 5415the functions in the list @id{l}.
5403 5416
5404It is implemented as the following macro: 5417It is implemented as the following macro:
5405@verbatim{ 5418@verbatim{
@@ -5437,7 +5450,8 @@ adds to the registry the pair @T{[tname] = new table},
5437and returns 1. 5450and returns 1.
5438(The entry @idx{__name} is used by some error-reporting functions.) 5451(The entry @idx{__name} is used by some error-reporting functions.)
5439 5452
5440In both cases pushes onto the stack the final value associated 5453In both cases,
5454the function pushes onto the stack the final value associated
5441with @id{tname} in the registry. 5455with @id{tname} in the registry.
5442 5456
5443} 5457}
@@ -5447,10 +5461,9 @@ with @id{tname} in the registry.
5447 5461
5448Creates a new Lua state. 5462Creates a new Lua state.
5449It calls @Lid{lua_newstate} with an 5463It calls @Lid{lua_newstate} with an
5450allocator based on the @N{standard C} @id{realloc} function 5464allocator based on the @N{standard C} allocation functions
5451and then sets a panic function @see{C-error} that prints 5465and then sets a warning function and a panic function @see{C-error}
5452an error message to the standard error output in case of fatal 5466that print messages to the standard error output.
5453errors.
5454 5467
5455Returns the new state, 5468Returns the new state,
5456or @id{NULL} if there is a @x{memory allocation error}. 5469or @id{NULL} if there is a @x{memory allocation error}.
@@ -5488,7 +5501,7 @@ lua_Integer luaL_optinteger (lua_State *L,
5488@apii{0,0,v} 5501@apii{0,0,v}
5489 5502
5490If the function argument @id{arg} is an integer 5503If the function argument @id{arg} is an integer
5491(or convertible to an integer), 5504(or it is convertible to an integer),
5492returns this integer. 5505returns this integer.
5493If this argument is absent or is @nil, 5506If this argument is absent or is @nil,
5494returns @id{d}. 5507returns @id{d}.
@@ -5510,7 +5523,7 @@ returns @id{d}.
5510Otherwise, raises an error. 5523Otherwise, raises an error.
5511 5524
5512If @id{l} is not @id{NULL}, 5525If @id{l} is not @id{NULL},
5513fills the position @T{*l} with the result's length. 5526fills its referent with the result's length.
5514If the result is @id{NULL} 5527If the result is @id{NULL}
5515(only possible when returning @id{d} and @T{d == NULL}), 5528(only possible when returning @id{d} and @T{d == NULL}),
5516its length is considered zero. 5529its length is considered zero.
@@ -5524,7 +5537,7 @@ so all conversions and caveats of that function apply here.
5524@apii{0,0,v} 5537@apii{0,0,v}
5525 5538
5526If the function argument @id{arg} is a number, 5539If the function argument @id{arg} is a number,
5527returns this number. 5540returns this number as a @id{lua_Number}.
5528If this argument is absent or is @nil, 5541If this argument is absent or is @nil,
5529returns @id{d}. 5542returns @id{d}.
5530Otherwise, raises an error. 5543Otherwise, raises an error.
@@ -5588,11 +5601,11 @@ in the table at index @id{t},
5588for the object on the top of the stack (and pops the object). 5601for the object on the top of the stack (and pops the object).
5589 5602
5590A reference is a unique integer key. 5603A reference is a unique integer key.
5591As long as you do not manually add integer keys into table @id{t}, 5604As long as you do not manually add integer keys into the table @id{t},
5592@Lid{luaL_ref} ensures the uniqueness of the key it returns. 5605@Lid{luaL_ref} ensures the uniqueness of the key it returns.
5593You can retrieve an object referred by reference @id{r} 5606You can retrieve an object referred by the reference @id{r}
5594by calling @T{lua_rawgeti(L, t, r)}. 5607by calling @T{lua_rawgeti(L, t, r)}.
5595Function @Lid{luaL_unref} frees a reference and its associated object. 5608The function @Lid{luaL_unref} frees a reference.
5596 5609
5597If the object on the top of the stack is @nil, 5610If the object on the top of the stack is @nil,
5598@Lid{luaL_ref} returns the constant @defid{LUA_REFNIL}. 5611@Lid{luaL_ref} returns the constant @defid{LUA_REFNIL}.
@@ -5623,12 +5636,12 @@ void luaL_requiref (lua_State *L, const char *modname,
5623@apii{0,1,e} 5636@apii{0,1,e}
5624 5637
5625If @T{package.loaded[modname]} is not true, 5638If @T{package.loaded[modname]} is not true,
5626calls function @id{openf} with string @id{modname} as an argument 5639calls the function @id{openf} with the string @id{modname} as an argument
5627and sets the call result to @T{package.loaded[modname]}, 5640and sets the call result to @T{package.loaded[modname]},
5628as if that function has been called through @Lid{require}. 5641as if that function has been called through @Lid{require}.
5629 5642
5630If @id{glb} is true, 5643If @id{glb} is true,
5631also stores the module into global @id{modname}. 5644also stores the module into the global @id{modname}.
5632 5645
5633Leaves a copy of the module on the stack. 5646Leaves a copy of the module on the stack.
5634 5647
@@ -5666,8 +5679,8 @@ typedef struct luaL_Stream {
5666} luaL_Stream; 5679} luaL_Stream;
5667| 5680|
5668 5681
5669The standard representation for @x{file handles}, 5682The standard representation for @x{file handles}
5670which is used by the standard I/O library. 5683used by the standard I/O library.
5671 5684
5672A file handle is implemented as a full userdata, 5685A file handle is implemented as a full userdata,
5673with a metatable called @id{LUA_FILEHANDLE} 5686with a metatable called @id{LUA_FILEHANDLE}
@@ -5677,14 +5690,14 @@ The metatable is created by the I/O library
5677 5690
5678This userdata must start with the structure @id{luaL_Stream}; 5691This userdata must start with the structure @id{luaL_Stream};
5679it can contain other data after this initial structure. 5692it can contain other data after this initial structure.
5680Field @id{f} points to the corresponding C stream 5693The field @id{f} points to the corresponding C stream
5681(or it can be @id{NULL} to indicate an incompletely created handle). 5694(or it can be @id{NULL} to indicate an incompletely created handle).
5682Field @id{closef} points to a Lua function 5695The field @id{closef} points to a Lua function
5683that will be called to close the stream 5696that will be called to close the stream
5684when the handle is closed or collected; 5697when the handle is closed or collected;
5685this function receives the file handle as its sole argument and 5698this function receives the file handle as its sole argument and
5686must return either @true (in case of success) 5699must return either @true, in case of success,
5687or @nil plus an error message (in case of error). 5700or @nil plus an error message, in case of error.
5688Once Lua calls this field, 5701Once Lua calls this field,
5689it changes the field value to @id{NULL} 5702it changes the field value to @id{NULL}
5690to signal that the handle is closed. 5703to signal that the handle is closed.
@@ -5723,7 +5736,7 @@ void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
5723@apii{0,1,m} 5736@apii{0,1,m}
5724 5737
5725Creates and pushes a traceback of the stack @id{L1}. 5738Creates and pushes a traceback of the stack @id{L1}.
5726If @id{msg} is not @id{NULL} it is appended 5739If @id{msg} is not @id{NULL}, it is appended
5727at the beginning of the traceback. 5740at the beginning of the traceback.
5728The @id{level} parameter tells at which level 5741The @id{level} parameter tells at which level
5729to start the traceback. 5742to start the traceback.
@@ -5735,7 +5748,7 @@ to start the traceback.
5735 const char *tname);| 5748 const char *tname);|
5736@apii{0,0,v} 5749@apii{0,0,v}
5737 5750
5738Raises a type error for argument @id{arg} 5751Raises a type error for the argument @id{arg}
5739of the @N{C function} that called it, 5752of the @N{C function} that called it,
5740using a standard message; 5753using a standard message;
5741@id{tname} is a @Q{name} for the expected type. 5754@id{tname} is a @Q{name} for the expected type.
@@ -5753,7 +5766,7 @@ Returns the name of the type of the value at the given index.
5753@APIEntry{void luaL_unref (lua_State *L, int t, int ref);| 5766@APIEntry{void luaL_unref (lua_State *L, int t, int ref);|
5754@apii{0,0,-} 5767@apii{0,0,-}
5755 5768
5756Releases reference @id{ref} from the table at index @id{t} 5769Releases the reference @id{ref} from the table at index @id{t}
5757@seeC{luaL_ref}. 5770@seeC{luaL_ref}.
5758The entry is removed from the table, 5771The entry is removed from the table,
5759so that the referred object can be collected. 5772so that the referred object can be collected.
@@ -5787,15 +5800,15 @@ This function is used to build a prefix for error messages.
5787 5800
5788 5801
5789@C{-------------------------------------------------------------------------} 5802@C{-------------------------------------------------------------------------}
5790@sect1{libraries| @title{Standard Libraries} 5803@sect1{libraries| @title{The Standard Libraries}
5791 5804
5792The standard Lua libraries provide useful functions 5805The standard Lua libraries provide useful functions
5793that are implemented directly through the @N{C API}. 5806that are implemented @N{in C} through the @N{C API}.
5794Some of these functions provide essential services to the language 5807Some of these functions provide essential services to the language
5795(e.g., @Lid{type} and @Lid{getmetatable}); 5808(e.g., @Lid{type} and @Lid{getmetatable});
5796others provide access to @Q{outside} services (e.g., I/O); 5809others provide access to outside services (e.g., I/O);
5797and others could be implemented in Lua itself, 5810and others could be implemented in Lua itself,
5798but are quite useful or have critical performance requirements that 5811but that for different reasons
5799deserve an implementation in C (e.g., @Lid{table.sort}). 5812deserve an implementation in C (e.g., @Lid{table.sort}).
5800 5813
5801All libraries are implemented through the official @N{C API} 5814All libraries are implemented through the official @N{C API}
@@ -5844,7 +5857,7 @@ the host program can open them individually by using
5844@defid{luaopen_package} (for the package library), 5857@defid{luaopen_package} (for the package library),
5845@defid{luaopen_coroutine} (for the coroutine library), 5858@defid{luaopen_coroutine} (for the coroutine library),
5846@defid{luaopen_string} (for the string library), 5859@defid{luaopen_string} (for the string library),
5847@defid{luaopen_utf8} (for the UTF8 library), 5860@defid{luaopen_utf8} (for the UTF-8 library),
5848@defid{luaopen_table} (for the table library), 5861@defid{luaopen_table} (for the table library),
5849@defid{luaopen_math} (for the mathematical library), 5862@defid{luaopen_math} (for the mathematical library),
5850@defid{luaopen_io} (for the I/O library), 5863@defid{luaopen_io} (for the I/O library),
@@ -5896,8 +5909,7 @@ restarts automatic execution of the garbage collector.
5896returns the total memory in use by Lua in Kbytes. 5909returns the total memory in use by Lua in Kbytes.
5897The value has a fractional part, 5910The value has a fractional part,
5898so that it multiplied by 1024 5911so that it multiplied by 1024
5899gives the exact number of bytes in use by Lua 5912gives the exact number of bytes in use by Lua.
5900(except for overflows).
5901} 5913}
5902 5914
5903@item{@St{step}| 5915@item{@St{step}|
@@ -5938,6 +5950,8 @@ returns a boolean that tells whether the collector is running
5938} 5950}
5939 5951
5940} 5952}
5953See @See{GC} for more details about garbage collection
5954and some of these options.
5941 5955
5942} 5956}
5943 5957
@@ -5947,14 +5961,15 @@ When called without arguments,
5947@id{dofile} executes the contents of the standard input (@id{stdin}). 5961@id{dofile} executes the contents of the standard input (@id{stdin}).
5948Returns all values returned by the chunk. 5962Returns all values returned by the chunk.
5949In case of errors, @id{dofile} propagates the error 5963In case of errors, @id{dofile} propagates the error
5950to its caller (that is, @id{dofile} does not run in protected mode). 5964to its caller.
5965(That is, @id{dofile} does not run in protected mode.)
5951 5966
5952} 5967}
5953 5968
5954@LibEntry{error (message [, level])| 5969@LibEntry{error (message [, level])|
5955Terminates the last protected function called 5970Terminates the last protected function called
5956and returns @id{message} as the error object. 5971and returns @id{message} as the error object.
5957Function @id{error} never returns. 5972This function never returns.
5958 5973
5959Usually, @id{error} adds some information about the error position 5974Usually, @id{error} adds some information about the error position
5960at the beginning of the message, if the message is a string. 5975at the beginning of the message, if the message is a string.
@@ -6066,7 +6081,7 @@ if no file name is given.
6066Allows a program to traverse all fields of a table. 6081Allows a program to traverse all fields of a table.
6067Its first argument is a table and its second argument 6082Its first argument is a table and its second argument
6068is an index in this table. 6083is an index in this table.
6069@id{next} returns the next index of the table 6084A call to @id{next} returns the next index of the table
6070and its associated value. 6085and its associated value.
6071When called with @nil as its second argument, 6086When called with @nil as its second argument,
6072@id{next} returns an initial index 6087@id{next} returns an initial index
@@ -6112,7 +6127,7 @@ the table during its traversal.
6112 6127
6113@LibEntry{pcall (f [, arg1, @Cdots])| 6128@LibEntry{pcall (f [, arg1, @Cdots])|
6114 6129
6115Calls function @id{f} with 6130Calls the function @id{f} with
6116the given arguments in @def{protected mode}. 6131the given arguments in @def{protected mode}.
6117This means that any error @N{inside @T{f}} is not propagated; 6132This means that any error @N{inside @T{f}} is not propagated;
6118instead, @id{pcall} catches the error 6133instead, @id{pcall} catches the error
@@ -6121,7 +6136,7 @@ Its first result is the status code (a boolean),
6121which is true if the call succeeds without errors. 6136which is true if the call succeeds without errors.
6122In such case, @id{pcall} also returns all results from the call, 6137In such case, @id{pcall} also returns all results from the call,
6123after this first result. 6138after this first result.
6124In case of any error, @id{pcall} returns @false plus the error message. 6139In case of any error, @id{pcall} returns @false plus the error object.
6125 6140
6126} 6141}
6127 6142
@@ -6184,8 +6199,6 @@ and @id{select} returns the total number of extra arguments it received.
6184@LibEntry{setmetatable (table, metatable)| 6199@LibEntry{setmetatable (table, metatable)|
6185 6200
6186Sets the metatable for the given table. 6201Sets the metatable for the given table.
6187(To change the metatable of other types from Lua code,
6188you must use the @link{debuglib|debug library}.)
6189If @id{metatable} is @nil, 6202If @id{metatable} is @nil,
6190removes the metatable of the given table. 6203removes the metatable of the given table.
6191If the original metatable has a @idx{__metatable} field, 6204If the original metatable has a @idx{__metatable} field,
@@ -6193,6 +6206,9 @@ raises an error.
6193 6206
6194This function returns @id{table}. 6207This function returns @id{table}.
6195 6208
6209To change the metatable of other types from Lua code,
6210you must use the @link{debuglib|debug library}.
6211
6196} 6212}
6197 6213
6198@LibEntry{tonumber (e [, base])| 6214@LibEntry{tonumber (e [, base])|
@@ -6206,7 +6222,7 @@ otherwise, it returns @nil.
6206 6222
6207The conversion of strings can result in integers or floats, 6223The conversion of strings can result in integers or floats,
6208according to the lexical conventions of Lua @see{lexical}. 6224according to the lexical conventions of Lua @see{lexical}.
6209(The string may have leading and trailing spaces and a sign.) 6225The string may have leading and trailing spaces and a sign.
6210 6226
6211When called with @id{base}, 6227When called with @id{base},
6212then @id{e} must be a string to be interpreted as 6228then @id{e} must be a string to be interpreted as
@@ -6298,7 +6314,7 @@ it is not inside a non-yieldable @N{C function}.
6298 6314
6299} 6315}
6300 6316
6301@LibEntry{coroutine.kill(co)| 6317@LibEntry{coroutine.kill (co)|
6302 6318
6303Kills coroutine @id{co}, 6319Kills coroutine @id{co},
6304closing all its pending to-be-closed variables 6320closing all its pending to-be-closed variables
@@ -6339,7 +6355,7 @@ true when the running coroutine is the main one.
6339 6355
6340@LibEntry{coroutine.status (co)| 6356@LibEntry{coroutine.status (co)|
6341 6357
6342Returns the status of coroutine @id{co}, as a string: 6358Returns the status of the coroutine @id{co}, as a string:
6343@T{"running"}, 6359@T{"running"},
6344if the coroutine is running (that is, it called @id{status}); 6360if the coroutine is running (that is, it called @id{status});
6345@T{"suspended"}, if the coroutine is suspended in a call to @id{yield}, 6361@T{"suspended"}, if the coroutine is suspended in a call to @id{yield},
@@ -6353,7 +6369,7 @@ or if it has stopped with an error.
6353 6369
6354@LibEntry{coroutine.wrap (f)| 6370@LibEntry{coroutine.wrap (f)|
6355 6371
6356Creates a new coroutine, with body @id{f}. 6372Creates a new coroutine, with body @id{f};
6357@id{f} must be a function. 6373@id{f} must be a function.
6358Returns a function that resumes the coroutine each time it is called. 6374Returns a function that resumes the coroutine each time it is called.
6359Any arguments passed to the function behave as the 6375Any arguments passed to the function behave as the
@@ -6379,7 +6395,7 @@ The package library provides basic
6379facilities for loading modules in Lua. 6395facilities for loading modules in Lua.
6380It exports one function directly in the global environment: 6396It exports one function directly in the global environment:
6381@Lid{require}. 6397@Lid{require}.
6382Everything else is exported in a table @defid{package}. 6398Everything else is exported in the table @defid{package}.
6383 6399
6384 6400
6385@LibEntry{require (modname)| 6401@LibEntry{require (modname)|
@@ -6729,7 +6745,8 @@ after the two indices.
6729@LibEntry{string.format (formatstring, @Cdots)| 6745@LibEntry{string.format (formatstring, @Cdots)|
6730 6746
6731Returns a formatted version of its variable number of arguments 6747Returns a formatted version of its variable number of arguments
6732following the description given in its first argument (which must be a string). 6748following the description given in its first argument,
6749which must be a string.
6733The format string follows the same rules as the @ANSI{sprintf}. 6750The format string follows the same rules as the @ANSI{sprintf}.
6734The only differences are that the conversion specifiers and modifiers 6751The only differences are that the conversion specifiers and modifiers
6735@T{*}, @id{h}, @id{L}, @id{l}, and @id{n} are not supported 6752@T{*}, @id{h}, @id{L}, @id{l}, and @id{n} are not supported
@@ -6830,9 +6847,9 @@ If @id{repl} is a string, then its value is used for replacement.
6830The @N{character @T{%}} works as an escape character: 6847The @N{character @T{%}} works as an escape character:
6831any sequence in @id{repl} of the form @T{%@rep{d}}, 6848any sequence in @id{repl} of the form @T{%@rep{d}},
6832with @rep{d} between 1 and 9, 6849with @rep{d} between 1 and 9,
6833stands for the value of the @rep{d}-th captured substring. 6850stands for the value of the @rep{d}-th captured substring;
6834The sequence @T{%0} stands for the whole match. 6851the sequence @T{%0} stands for the whole match;
6835The sequence @T{%%} stands for a @N{single @T{%}}. 6852the sequence @T{%%} stands for a @N{single @T{%}}.
6836 6853
6837If @id{repl} is a table, then the table is queried for every match, 6854If @id{repl} is a table, then the table is queried for every match,
6838using the first capture as the key. 6855using the first capture as the key.
@@ -6899,7 +6916,7 @@ The definition of what an uppercase letter is depends on the current locale.
6899@LibEntry{string.match (s, pattern [, init])| 6916@LibEntry{string.match (s, pattern [, init])|
6900 6917
6901Looks for the first @emph{match} of 6918Looks for the first @emph{match} of
6902@id{pattern} @see{pm} in the string @id{s}. 6919the @id{pattern} @see{pm} in the string @id{s}.
6903If it finds one, then @id{match} returns 6920If it finds one, then @id{match} returns
6904the captures from the pattern; 6921the captures from the pattern;
6905otherwise it returns @nil. 6922otherwise it returns @nil.
@@ -6914,7 +6931,7 @@ its default value @N{is 1} and can be negative.
6914@LibEntry{string.pack (fmt, v1, v2, @Cdots)| 6931@LibEntry{string.pack (fmt, v1, v2, @Cdots)|
6915 6932
6916Returns a binary string containing the values @id{v1}, @id{v2}, etc. 6933Returns a binary string containing the values @id{v1}, @id{v2}, etc.
6917packed (that is, serialized in binary form) 6934serialized in binary form (packed)
6918according to the format string @id{fmt} @see{pack}. 6935according to the format string @id{fmt} @see{pack}.
6919 6936
6920} 6937}
@@ -7042,8 +7059,7 @@ represents the character @rep{x}.
7042This is the standard way to escape the magic characters. 7059This is the standard way to escape the magic characters.
7043Any non-alphanumeric character 7060Any non-alphanumeric character
7044(including all punctuation characters, even the non-magical) 7061(including all punctuation characters, even the non-magical)
7045can be preceded by a @Char{%} 7062can be preceded by a @Char{%} to represent itself in a pattern.
7046when used to represent itself in a pattern.
7047} 7063}
7048 7064
7049@item{@T{[@rep{set}]}| 7065@item{@T{[@rep{set}]}|
@@ -7099,19 +7115,19 @@ which matches any single character in the class;
7099 7115
7100@item{ 7116@item{
7101a single character class followed by @Char{*}, 7117a single character class followed by @Char{*},
7102which matches zero or more repetitions of characters in the class. 7118which matches sequences of zero or more characters in the class.
7103These repetition items will always match the longest possible sequence; 7119These repetition items will always match the longest possible sequence;
7104} 7120}
7105 7121
7106@item{ 7122@item{
7107a single character class followed by @Char{+}, 7123a single character class followed by @Char{+},
7108which matches one or more repetitions of characters in the class. 7124which matches sequences of one or more characters in the class.
7109These repetition items will always match the longest possible sequence; 7125These repetition items will always match the longest possible sequence;
7110} 7126}
7111 7127
7112@item{ 7128@item{
7113a single character class followed by @Char{-}, 7129a single character class followed by @Char{-},
7114which also matches zero or more repetitions of characters in the class. 7130which also matches sequences of zero or more characters in the class.
7115Unlike @Char{*}, 7131Unlike @Char{*},
7116these repetition items will always match the shortest possible sequence; 7132these repetition items will always match the shortest possible sequence;
7117} 7133}
@@ -7172,7 +7188,7 @@ that match captures are stored (@emph{captured}) for future use.
7172Captures are numbered according to their left parentheses. 7188Captures are numbered according to their left parentheses.
7173For instance, in the pattern @T{"(a*(.)%w(%s*))"}, 7189For instance, in the pattern @T{"(a*(.)%w(%s*))"},
7174the part of the string matching @T{"a*(.)%w(%s*)"} is 7190the part of the string matching @T{"a*(.)%w(%s*)"} is
7175stored as the first capture (and therefore has @N{number 1}); 7191stored as the first capture, and therefore has @N{number 1};
7176the character matching @St{.} is captured with @N{number 2}, 7192the character matching @St{.} is captured with @N{number 2},
7177and the part matching @St{%s*} has @N{number 3}. 7193and the part matching @St{%s*} has @N{number 3}.
7178 7194
@@ -7188,7 +7204,7 @@ The function @Lid{string.gsub} and the iterator @Lid{string.gmatch}
7188match multiple occurrences of the given pattern in the subject. 7204match multiple occurrences of the given pattern in the subject.
7189For these functions, 7205For these functions,
7190a new match is considered valid only 7206a new match is considered valid only
7191if it ends at least one byte after the previous match. 7207if it ends at least one byte after the end of the previous match.
7192In other words, the pattern machine never accepts the 7208In other words, the pattern machine never accepts the
7193empty string as a match immediately after another match. 7209empty string as a match immediately after another match.
7194As an example, 7210As an example,
@@ -7253,14 +7269,16 @@ according to option @id{op}
7253(A @St{[@rep{n}]} means an optional integral numeral.) 7269(A @St{[@rep{n}]} means an optional integral numeral.)
7254Except for padding, spaces, and configurations 7270Except for padding, spaces, and configurations
7255(options @St{xX <=>!}), 7271(options @St{xX <=>!}),
7256each option corresponds to an argument (in @Lid{string.pack}) 7272each option corresponds to an argument in @Lid{string.pack}
7257or a result (in @Lid{string.unpack}). 7273or a result in @Lid{string.unpack}.
7258 7274
7259For options @St{!@rep{n}}, @St{s@rep{n}}, @St{i@rep{n}}, and @St{I@rep{n}}, 7275For options @St{!@rep{n}}, @St{s@rep{n}}, @St{i@rep{n}}, and @St{I@rep{n}},
7260@id{n} can be any integer between 1 and 16. 7276@id{n} can be any integer between 1 and 16.
7261All integral options check overflows; 7277All integral options check overflows;
7262@Lid{string.pack} checks whether the given value fits in the given size; 7278@Lid{string.pack} checks whether the given value fits in the given size;
7263@Lid{string.unpack} checks whether the read value fits in a Lua integer. 7279@Lid{string.unpack} checks whether the read value fits in a Lua integer.
7280For the unsigned options,
7281Lua integers are treated as unsigned values too.
7264 7282
7265Any format string starts as if prefixed by @St{!1=}, 7283Any format string starts as if prefixed by @St{!1=},
7266that is, 7284that is,
@@ -7283,7 +7301,7 @@ option @St{s} follows the alignment of its starting integer.
7283 7301
7284 7302
7285All padding is filled with zeros by @Lid{string.pack} 7303All padding is filled with zeros by @Lid{string.pack}
7286(and ignored by @Lid{string.unpack}). 7304and ignored by @Lid{string.unpack}.
7287 7305
7288} 7306}
7289 7307
@@ -7344,7 +7362,7 @@ Returns values so that the construction
7344@verbatim{ 7362@verbatim{
7345for p, c in utf8.codes(s) do @rep{body} end 7363for p, c in utf8.codes(s) do @rep{body} end
7346} 7364}
7347will iterate over all characters in string @id{s}, 7365will iterate over all UTF-8 characters in string @id{s},
7348with @id{p} being the position (in bytes) and @id{c} the code point 7366with @id{p} being the position (in bytes) and @id{c} the code point
7349of each character. 7367of each character.
7350It raises an error if it meets any invalid byte sequence. 7368It raises an error if it meets any invalid byte sequence.
@@ -7353,7 +7371,7 @@ It raises an error if it meets any invalid byte sequence.
7353 7371
7354@LibEntry{utf8.codepoint (s [, i [, j [, lax]]])| 7372@LibEntry{utf8.codepoint (s [, i [, j [, lax]]])|
7355 7373
7356Returns the codepoints (as integers) from all characters in @id{s} 7374Returns the code points (as integers) from all characters in @id{s}
7357that start between byte position @id{i} and @id{j} (both included). 7375that start between byte position @id{i} and @id{j} (both included).
7358The default for @id{i} is 1 and for @id{j} is @id{i}. 7376The default for @id{i} is 1 and for @id{j} is @id{i}.
7359It raises an error if it meets any invalid byte sequence. 7377It raises an error if it meets any invalid byte sequence.
@@ -7423,13 +7441,13 @@ shifting up the elements
7423@T{list[pos], list[pos+1], @Cdots, list[#list]}. 7441@T{list[pos], list[pos+1], @Cdots, list[#list]}.
7424The default value for @id{pos} is @T{#list+1}, 7442The default value for @id{pos} is @T{#list+1},
7425so that a call @T{table.insert(t,x)} inserts @id{x} at the end 7443so that a call @T{table.insert(t,x)} inserts @id{x} at the end
7426of list @id{t}. 7444of the list @id{t}.
7427 7445
7428} 7446}
7429 7447
7430@LibEntry{table.move (a1, f, e, t [,a2])| 7448@LibEntry{table.move (a1, f, e, t [,a2])|
7431 7449
7432Moves elements from table @id{a1} to table @id{a2}, 7450Moves elements from the table @id{a1} to the table @id{a2},
7433performing the equivalent to the following 7451performing the equivalent to the following
7434multiple assignment: 7452multiple assignment:
7435@T{a2[t],@Cdots = a1[f],@Cdots,a1[e]}. 7453@T{a2[t],@Cdots = a1[f],@Cdots,a1[e]}.
@@ -7463,13 +7481,13 @@ or @T{#list + 1}.
7463 7481
7464The default value for @id{pos} is @T{#list}, 7482The default value for @id{pos} is @T{#list},
7465so that a call @T{table.remove(l)} removes the last element 7483so that a call @T{table.remove(l)} removes the last element
7466of list @id{l}. 7484of the list @id{l}.
7467 7485
7468} 7486}
7469 7487
7470@LibEntry{table.sort (list [, comp])| 7488@LibEntry{table.sort (list [, comp])|
7471 7489
7472Sorts list elements in a given order, @emph{in-place}, 7490Sorts the list elements in a given order, @emph{in-place},
7473from @T{list[1]} to @T{list[#list]}. 7491from @T{list[1]} to @T{list[#list]}.
7474If @id{comp} is given, 7492If @id{comp} is given,
7475then it must be a function that receives two list elements 7493then it must be a function that receives two list elements
@@ -7511,8 +7529,8 @@ It provides all its functions and constants inside the table @defid{math}.
7511Functions with the annotation @St{integer/float} give 7529Functions with the annotation @St{integer/float} give
7512integer results for integer arguments 7530integer results for integer arguments
7513and float results for float (or mixed) arguments. 7531and float results for float (or mixed) arguments.
7514Rounding functions 7532the rounding functions
7515(@Lid{math.ceil}, @Lid{math.floor}, and @Lid{math.modf}) 7533@Lid{math.ceil}, @Lid{math.floor}, and @Lid{math.modf}
7516return an integer when the result fits in the range of an integer, 7534return an integer when the result fits in the range of an integer,
7517or a float otherwise. 7535or a float otherwise.
7518 7536
@@ -7540,7 +7558,7 @@ Returns the arc sine of @id{x} (in radians).
7540Returns the arc tangent of @T{y/x} (in radians), 7558Returns the arc tangent of @T{y/x} (in radians),
7541but uses the signs of both arguments to find the 7559but uses the signs of both arguments to find the
7542quadrant of the result. 7560quadrant of the result.
7543(It also handles correctly the case of @id{x} being zero.) 7561It also handles correctly the case of @id{x} being zero.
7544 7562
7545The default value for @id{x} is 1, 7563The default value for @id{x} is 1,
7546so that the call @T{math.atan(y)} 7564so that the call @T{math.atan(y)}
@@ -7604,7 +7622,7 @@ The default for @id{base} is @M{e}
7604@LibEntry{math.max (x, @Cdots)| 7622@LibEntry{math.max (x, @Cdots)|
7605 7623
7606Returns the argument with the maximum value, 7624Returns the argument with the maximum value,
7607according to the Lua operator @T{<}. (integer/float) 7625according to the Lua operator @T{<}.
7608 7626
7609} 7627}
7610 7628
@@ -7616,7 +7634,7 @@ An integer with the maximum value for an integer.
7616@LibEntry{math.min (x, @Cdots)| 7634@LibEntry{math.min (x, @Cdots)|
7617 7635
7618Returns the argument with the minimum value, 7636Returns the argument with the minimum value,
7619according to the Lua operator @T{<}. (integer/float) 7637according to the Lua operator @T{<}.
7620 7638
7621} 7639}
7622 7640
@@ -7674,7 +7692,7 @@ some number of previous results.)
7674 7692
7675When called with at least one argument, 7693When called with at least one argument,
7676the integer parameters @id{x} and @id{y} are 7694the integer parameters @id{x} and @id{y} are
7677concatenated into a 128-bit @emphx{seed} that 7695joined into a 128-bit @emphx{seed} that
7678is used to reinitialize the pseudo-random generator; 7696is used to reinitialize the pseudo-random generator;
7679equal seeds produce equal sequences of numbers. 7697equal seeds produce equal sequences of numbers.
7680The default for @id{y} is zero. 7698The default for @id{y} is zero.
@@ -7741,7 +7759,7 @@ The I/O library provides two different styles for file manipulation.
7741The first one uses implicit file handles; 7759The first one uses implicit file handles;
7742that is, there are operations to set a default input file and a 7760that is, there are operations to set a default input file and a
7743default output file, 7761default output file,
7744and all input/output operations are over these default files. 7762and all input/output operations are done over these default files.
7745The second style uses explicit file handles. 7763The second style uses explicit file handles.
7746 7764
7747When using implicit file handles, 7765When using implicit file handles,
@@ -7750,18 +7768,19 @@ When using explicit file handles,
7750the operation @Lid{io.open} returns a file handle 7768the operation @Lid{io.open} returns a file handle
7751and then all operations are supplied as methods of the file handle. 7769and then all operations are supplied as methods of the file handle.
7752 7770
7771The metatable for file handles provides metamethods
7772for @idx{__gc} and @idx{__close} that try
7773to close the file when called.
7774
7753The table @id{io} also provides 7775The table @id{io} also provides
7754three predefined file handles with their usual meanings from C: 7776three predefined file handles with their usual meanings from C:
7755@defid{io.stdin}, @defid{io.stdout}, and @defid{io.stderr}. 7777@defid{io.stdin}, @defid{io.stdout}, and @defid{io.stderr}.
7756The I/O library never closes these files. 7778The I/O library never closes these files.
7757The metatable for file handles provides metamethods
7758for @idx{__gc} and @idx{__close} that try
7759to close the file when called.
7760 7779
7761Unless otherwise stated, 7780Unless otherwise stated,
7762all I/O functions return @nil on failure 7781all I/O functions return @nil on failure,
7763(plus an error message as a second result and 7782plus an error message as a second result and
7764a system-dependent error code as a third result) 7783a system-dependent error code as a third result,
7765and some value different from @nil on success. 7784and some value different from @nil on success.
7766On non-POSIX systems, 7785On non-POSIX systems,
7767the computation of the error message and error code 7786the computation of the error message and error code
@@ -7854,7 +7873,7 @@ Similar to @Lid{io.input}, but operates over the default output file.
7854This function is system dependent and is not available 7873This function is system dependent and is not available
7855on all platforms. 7874on all platforms.
7856 7875
7857Starts program @id{prog} in a separated process and returns 7876Starts the program @id{prog} in a separated process and returns
7858a file handle that you can use to read data from this program 7877a file handle that you can use to read data from this program
7859(if @id{mode} is @T{"r"}, the default) 7878(if @id{mode} is @T{"r"}, the default)
7860or to write data to this program 7879or to write data to this program
@@ -8097,10 +8116,9 @@ If @id{format} is not @St{*t},
8097then @id{date} returns the date as a string, 8116then @id{date} returns the date as a string,
8098formatted according to the same rules as the @ANSI{strftime}. 8117formatted according to the same rules as the @ANSI{strftime}.
8099 8118
8100When called without arguments, 8119If @id{format} is absent, it defaults to @St{%c},
8101@id{date} returns a reasonable date and time representation that depends on 8120which gives a reasonable date and time representation
8102the host system and on the current locale. 8121using the current locale.
8103(More specifically, @T{os.date()} is equivalent to @T{os.date("%c")}.)
8104 8122
8105On non-POSIX systems, 8123On non-POSIX systems,
8106this function may be not @x{thread safe} 8124this function may be not @x{thread safe}
@@ -8314,8 +8332,8 @@ within any function and so have no direct access to local variables.
8314 8332
8315Returns the current hook settings of the thread, as three values: 8333Returns the current hook settings of the thread, as three values:
8316the current hook function, the current hook mask, 8334the current hook function, the current hook mask,
8317and the current hook count 8335and the current hook count,
8318(as set by the @Lid{debug.sethook} function). 8336as set by the @Lid{debug.sethook} function.
8319 8337
8320} 8338}
8321 8339
@@ -8359,7 +8377,7 @@ about the @Lid{print} function.
8359This function returns the name and the value of the local variable 8377This function returns the name and the value of the local variable
8360with index @id{local} of the function at level @id{f} of the stack. 8378with index @id{local} of the function at level @id{f} of the stack.
8361This function accesses not only explicit local variables, 8379This function accesses not only explicit local variables,
8362but also parameters, temporaries, etc. 8380but also parameters and temporary values.
8363 8381
8364The first parameter or local variable has @N{index 1}, and so on, 8382The first parameter or local variable has @N{index 1}, and so on,
8365following the order that they are declared in the code, 8383following the order that they are declared in the code,
@@ -8416,7 +8434,7 @@ to the userdata @id{u} plus a boolean,
8416 8434
8417@LibEntry{debug.sethook ([thread,] hook, mask [, count])| 8435@LibEntry{debug.sethook ([thread,] hook, mask [, count])|
8418 8436
8419Sets the given function as a hook. 8437Sets the given function as the debug hook.
8420The string @id{mask} and the number @id{count} describe 8438The string @id{mask} and the number @id{count} describe
8421when the hook will be called. 8439when the hook will be called.
8422The string mask may have any combination of the following characters, 8440The string mask may have any combination of the following characters,
@@ -8435,16 +8453,15 @@ When called without arguments,
8435 8453
8436When the hook is called, its first parameter is a string 8454When the hook is called, its first parameter is a string
8437describing the event that has triggered its call: 8455describing the event that has triggered its call:
8438@T{"call"} (or @T{"tail call"}), 8456@T{"call"}, @T{"tail call"}, @T{"return"},
8439@T{"return"},
8440@T{"line"}, and @T{"count"}. 8457@T{"line"}, and @T{"count"}.
8441For line events, 8458For line events,
8442the hook also gets the new line number as its second parameter. 8459the hook also gets the new line number as its second parameter.
8443Inside a hook, 8460Inside a hook,
8444you can call @id{getinfo} with @N{level 2} to get more information about 8461you can call @id{getinfo} with @N{level 2} to get more information about
8445the running function 8462the running function.
8446(@N{level 0} is the @id{getinfo} function, 8463(@N{Level 0} is the @id{getinfo} function,
8447and @N{level 1} is the hook function). 8464and @N{level 1} is the hook function.)
8448 8465
8449} 8466}
8450 8467
@@ -8542,7 +8559,7 @@ An interpreter for Lua as a standalone language,
8542called simply @id{lua}, 8559called simply @id{lua},
8543is provided with the standard distribution. 8560is provided with the standard distribution.
8544The @x{standalone interpreter} includes 8561The @x{standalone interpreter} includes
8545all standard libraries, including the debug library. 8562all standard libraries.
8546Its usage is: 8563Its usage is:
8547@verbatim{ 8564@verbatim{
8548lua [options] [script [args]] 8565lua [options] [script [args]]
@@ -8564,7 +8581,7 @@ When called without arguments,
8564when the standard input (@id{stdin}) is a terminal, 8581when the standard input (@id{stdin}) is a terminal,
8565and as @T{lua -} otherwise. 8582and as @T{lua -} otherwise.
8566 8583
8567When called without option @T{-E}, 8584When called without the option @T{-E},
8568the interpreter checks for an environment variable @defid{LUA_INIT_5_4} 8585the interpreter checks for an environment variable @defid{LUA_INIT_5_4}
8569(or @defid{LUA_INIT} if the versioned name is not defined) 8586(or @defid{LUA_INIT} if the versioned name is not defined)
8570before running any argument. 8587before running any argument.
@@ -8572,7 +8589,7 @@ If the variable content has the format @T{@At@rep{filename}},
8572then @id{lua} executes the file. 8589then @id{lua} executes the file.
8573Otherwise, @id{lua} executes the string itself. 8590Otherwise, @id{lua} executes the string itself.
8574 8591
8575When called with option @T{-E}, 8592When called with the option @T{-E},
8576besides ignoring @id{LUA_INIT}, 8593besides ignoring @id{LUA_INIT},
8577Lua also ignores 8594Lua also ignores
8578the values of @id{LUA_PATH} and @id{LUA_CPATH}, 8595the values of @id{LUA_PATH} and @id{LUA_CPATH},
@@ -8619,8 +8636,8 @@ will print @St{-e}.
8619If there is a script, 8636If there is a script,
8620the script is called with arguments 8637the script is called with arguments
8621@T{arg[1]}, @Cdots, @T{arg[#arg]}. 8638@T{arg[1]}, @Cdots, @T{arg[#arg]}.
8622(Like all chunks in Lua, 8639Like all chunks in Lua,
8623the script is compiled as a vararg function.) 8640the script is compiled as a vararg function.
8624 8641
8625In interactive mode, 8642In interactive mode,
8626Lua repeatedly prompts and waits for a line. 8643Lua repeatedly prompts and waits for a line.
@@ -8645,6 +8662,7 @@ has a metamethod @idx{__tostring},
8645the interpreter calls this metamethod to produce the final message. 8662the interpreter calls this metamethod to produce the final message.
8646Otherwise, the interpreter converts the error object to a string 8663Otherwise, the interpreter converts the error object to a string
8647and adds a stack traceback to it. 8664and adds a stack traceback to it.
8665Warnings are simply printed in the standard error output.
8648 8666
8649When finishing normally, 8667When finishing normally,
8650the interpreter closes its main Lua state 8668the interpreter closes its main Lua state
@@ -8654,22 +8672,21 @@ calling @Lid{os.exit} to terminate.
8654 8672
8655To allow the use of Lua as a 8673To allow the use of Lua as a
8656script interpreter in Unix systems, 8674script interpreter in Unix systems,
8657the standalone interpreter skips 8675Lua skips the first line of a file chunk if it starts with @T{#}.
8658the first line of a chunk if it starts with @T{#}.
8659Therefore, Lua scripts can be made into executable programs 8676Therefore, Lua scripts can be made into executable programs
8660by using @T{chmod +x} and @N{the @T{#!}} form, 8677by using @T{chmod +x} and @N{the @T{#!}} form,
8661as in 8678as in
8662@verbatim{ 8679@verbatim{
8663#!/usr/local/bin/lua 8680#!/usr/local/bin/lua
8664} 8681}
8665(Of course, 8682Of course,
8666the location of the Lua interpreter may be different in your machine. 8683the location of the Lua interpreter may be different in your machine.
8667If @id{lua} is in your @id{PATH}, 8684If @id{lua} is in your @id{PATH},
8668then 8685then
8669@verbatim{ 8686@verbatim{
8670#!/usr/bin/env lua 8687#!/usr/bin/env lua
8671} 8688}
8672is a more portable solution.) 8689is a more portable solution.
8673 8690
8674} 8691}
8675 8692
@@ -8688,7 +8705,7 @@ do not imply source-code changes in a program,
8688such as the numeric values for constants 8705such as the numeric values for constants
8689or the implementation of functions as macros. 8706or the implementation of functions as macros.
8690Therefore, 8707Therefore,
8691you should not assume that binaries are compatible between 8708you should never assume that binaries are compatible between
8692different Lua versions. 8709different Lua versions.
8693Always recompile clients of the Lua API when 8710Always recompile clients of the Lua API when
8694using a new version. 8711using a new version.
@@ -8700,7 +8717,7 @@ precompiled chunks are not compatible between different Lua versions.
8700The standard paths in the official distribution may 8717The standard paths in the official distribution may
8701change between versions. 8718change between versions.
8702 8719
8703@sect2{@title{Changes in the Language} 8720@sect2{@title{Incompatibilities in the Language}
8704@itemize{ 8721@itemize{
8705 8722
8706@item{ 8723@item{
@@ -8752,7 +8769,7 @@ like any other error when calling a finalizer.)
8752 8769
8753} 8770}
8754 8771
8755@sect2{@title{Changes in the Libraries} 8772@sect2{@title{Incompatibilities in the Libraries}
8756@itemize{ 8773@itemize{
8757 8774
8758@item{ 8775@item{
@@ -8762,13 +8779,6 @@ Moreover, it uses a different algorithm.
8762} 8779}
8763 8780
8764@item{ 8781@item{
8765The function @Lid{io.lines} now returns three extra values,
8766besides the iterator function.
8767You can enclose the call in parentheses if you need to
8768discard these extra results.
8769}
8770
8771@item{
8772By default, the decoding functions in the @Lid{utf8} library 8782By default, the decoding functions in the @Lid{utf8} library
8773do not accept surrogates as valid code points. 8783do not accept surrogates as valid code points.
8774An extra parameter in these functions makes them more permissive. 8784An extra parameter in these functions makes them more permissive.
@@ -8778,7 +8788,7 @@ An extra parameter in these functions makes them more permissive.
8778 8788
8779} 8789}
8780 8790
8781@sect2{@title{Changes in the API} 8791@sect2{@title{Incompatibilities in the API}
8782 8792
8783@itemize{ 8793@itemize{
8784 8794
@@ -8792,8 +8802,8 @@ which have an extra argument.
8792 8802
8793For compatibility, the old names still work as macros assuming 8803For compatibility, the old names still work as macros assuming
8794one single user value. 8804one single user value.
8795Note, however, that the call @T{lua_newuserdatauv(L,size,0)} 8805Note, however, that userdata with zero user values
8796produces a smaller userdata. 8806are more efficient memory-wise.
8797} 8807}
8798 8808
8799@item{ 8809@item{
@@ -8807,10 +8817,10 @@ those values were the entire stack.)
8807@item{ 8817@item{
8808The function @Lid{lua_version} returns the version number, 8818The function @Lid{lua_version} returns the version number,
8809instead of an address of the version number. 8819instead of an address of the version number.
8810(The Lua core should work correctly with libraries using their 8820The Lua core should work correctly with libraries using their
8811own static copies of the same core, 8821own static copies of the same core,
8812so there is no need to check whether they are using the same 8822so there is no need to check whether they are using the same
8813address space.) 8823address space.
8814} 8824}
8815 8825
8816@item{ 8826@item{