History

Lua 5.0.1

Lua Team committed 22 years ago

Commit a985bf41 parent 488a64b15 files · +822 −155Browse files

Unified · Split

15 files
  1. DIFFS +623 −0
  2. UPDATE +24 −0
  3. doc/manual.html +115 −116
  4. etc/.exrc +0 −1
  5. include/lua.h +2 −2
  6. src/ldo.c +19 −6
  7. src/lgc.c +14 −9
  8. src/lgc.h +2 −2
  9. src/lib/lbaselib.c +2 −2
  10. src/lib/liolib.c +3 −3
  11. src/lparser.c +7 −3
  12. src/luac/Makefile +1 −1
  13. src/luac/luac.c +3 −1
  14. src/lvm.c +4 −6
  15. test/luac.lua +3 −3
DIFFS+623−0
@@ -0,0 +1,623 @@
1+diff -r lua-5.0/doc/manual.html lua-5.0.1/doc/manual.html
2+5c5
3+< <title>Lua 5.0 Reference Manual</title>
4+---
5+> <TITLE>Lua: 5.0 reference manual</TITLE>
6+12,14c12
7+< <a HREF="http://www.lua.org/home.html">
8+< <img SRC="logo.gif" ALT="[Lua logo]" BORDER=0>
9+< </a>
10+---
11+> <A HREF="http://www.lua.org/home.html"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
12+22c20
13+< &copy; 2003 TeCGraf, PUC-Rio. All rights reserved.
14+---
15+> &copy; 2003 Tecgraf, PUC-Rio. All rights reserved.
16+32c30
17+< <h1>1 - Introduction</h1>
18+---
19+> <a name="1"><h1>1 - Introduction</h1></a>
20+37c35
21+< It also offers good suport for object-oriented programming,
22+---
23+> It also offers good support for object-oriented programming,
24+54c52
25+< <p>The Lua distribuition includes a stand-alone embedding program,
26+---
27+> <p>The Lua distribution includes a stand-alone embedding program,
28+90c88
29+< <a name="language"><h1>2 - The Language</h1></a>
30+---
31+> <a name="language"><a name="2"><h1>2 - The Language</h1></a></a>
32+108c106
33+< <p><a name="lexical"><h2>2.1 - Lexical Conventions</h2></a>
34+---
35+> <p><a name="lexical"><a name="2.1"><h2>2.1 - Lexical Conventions</h2></a></a>
36+125,126c123
37+< repeat return then true until
38+< while
39+---
40+> repeat return then true until while
41+214c211
42+< <p><a name="TypesSec"><h2>2.2 - Values and Types</h2></a>
43+---
44+> <p><a name="TypesSec"><a name="2.2"><h2>2.2 - Values and Types</h2></a></a>
45+295c292
46+< <p><a name="coercion"><h3>2.2.1 - Coercion</h3></a>
47+---
48+> <p><a name="coercion"><a name="2.2.1"><h3>2.2.1 - Coercion</h3></a></a>
49+306c303
50+< <p><a name="variables"><h2>2.3 - Variables</h2></a>
51+---
52+> <p><a name="variables"><a name="2.3"><h2>2.3 - Variables</h2></a></a>
53+375c372
54+< <p><a name="stats"><h2>2.4 - Statements</h2></a>
55+---
56+> <p><a name="stats"><a name="2.4"><h2>2.4 - Statements</h2></a></a>
57+383c380
58+< <p><a name="chunks"><h3>2.4.1 - Chunks</h3></a>
59+---
60+> <p><a name="chunks"><a name="2.4.1"><h3>2.4.1 - Chunks</h3></a></a>
61+408c405
62+< <p><h3>2.4.2 - Blocks</h3>
63+---
64+> <p><a name="2.4.2"><h3>2.4.2 - Blocks</h3></a>
65+426c423
66+< <p><a name="assignment"><h3>2.4.3 - Assignment</h3></a>
67+---
68+> <p><a name="assignment"><a name="2.4.3"><h3>2.4.3 - Assignment</h3></a></a>
69+461c458
70+< before it is assigned 4.
71+---
72+> before it is assigned&nbsp;4.
73+488c485
74+< <p><a name="control"><h3>2.4.4 - Control Structures</h3></a>
75+---
76+> <p><a name="control"><a name="2.4.4"><h3>2.4.4 - Control Structures</h3></a></a>
77+519c516
78+< skiping to the next statement after the loop:
79+---
80+> skipping to the next statement after the loop:
81+539c536
82+< <p><a name="for"><h3>2.4.5 - For Statement</h3></a>
83+---
84+> <p><a name="for"><a name="2.4.5"><h3>2.4.5 - For Statement</h3></a></a>
85+626c623
86+< <p><a name="funcstat"><h3>2.4.6 - Function Calls as Statements</h3></a>
87+---
88+> <p><a name="funcstat"><a name="2.4.6"><h3>2.4.6 - Function Calls as Statements</h3></a></a>
89+635c632
90+< <p><a name="localvar"><h3>2.4.7 - Local Declarations</h3></a>
91+---
92+> <p><a name="localvar"><a name="2.4.7"><h3>2.4.7 - Local Declarations</h3></a></a>
93+652c649
94+< <p><a name="expressions"><h2>2.5 - Expressions</h2></a>
95+---
96+> <p><a name="expressions"><a name="2.5"><h2>2.5 - Expressions</h2></a></a>
97+683c680
98+< <p><h3>2.5.1 - Arithmetic Operators</h3>
99+---
100+> <p><a name="2.5.1"><h3>2.5.1 - Arithmetic Operators</h3></a>
101+698c695
102+< <p><a name="rel-ops"><h3>2.5.2 - Relational Operators</h3></a>
103+---
104+> <p><a name="rel-ops"><a name="2.5.2"><h3>2.5.2 - Relational Operators</h3></a></a>
105+734c731
106+< <p><h3>2.5.3 - Logical Operators</h3>
107+---
108+> <p><a name="2.5.3"><h3>2.5.3 - Logical Operators</h3></a>
109+767c764
110+< <p><a name="concat"><h3>2.5.4 - Concatenation</h3></a>
111+---
112+> <p><a name="concat"><a name="2.5.4"><h3>2.5.4 - Concatenation</h3></a></a>
113+774c771
114+< <p><h3>2.5.5 - Precedence</h3>
115+---
116+> <p><a name="2.5.5"><h3>2.5.5 - Precedence</h3></a>
117+787c784
118+< As usual, you can use parentheses to change the precedences of an expression.
119+---
120+> You can use parentheses to change the precedences in an expression.
121+792c789
122+< <p><a name="tableconstructor"><h3>2.5.6 - Table Constructors</h3></a>
123+---
124+> <p><a name="tableconstructor"><a name="2.5.6"><h3>2.5.6 - Table Constructors</h3></a></a>
125+842c839
126+< <p><a name="functioncall"><h3>2.5.7 - Function Calls</h3></a>
127+---
128+> <p><a name="functioncall"><a name="2.5.7"><h3>2.5.7 - Function Calls</h3></a></a>
129+947c944
130+< return x, f(x) -- adicional results
131+---
132+> return x, f(x) -- additional results
133+952c949
134+< <p><a name="func-def"><h3>2.5.8 - Function Definitions</h3></a>
135+---
136+> <p><a name="func-def"><a name="2.5.8"><h3>2.5.8 - Function Definitions</h3></a></a>
137+1061c1058
138+< <p><a name="visibility"><h2>2.6 - Visibility Rules</h2></a>
139+---
140+> <p><a name="visibility"><a name="2.6"><h2>2.6 - Visibility Rules</h2></a></a>
141+1118c1115
142+< <p><a name="error"><h2>2.7 - Error Handling</h2></a>
143+---
144+> <p><a name="error"><a name="2.7"><h2>2.7 - Error Handling</h2></a></a>
145+1133c1130
146+< <p><a name="metatable"><h2>2.8 - Metatables</h2></a>
147+---
148+> <p><a name="metatable"><a name="2.8"><h2>2.8 - Metatables</h2></a></a>
149+1315c1312
150+< if type(op1) ~= type(op2) then -- diferent types?
151+---
152+> if type(op1) ~= type(op2) then -- different types?
153+1443c1440
154+< <p><a name="GC"><h2>2.9 - Garbage Collection</h2></a>
155+---
156+> <p><a name="GC"><a name="2.9"><h2>2.9 - Garbage Collection</h2></a></a>
157+1474c1471
158+< <p><h3>2.9.1 - Garbage-Collection Metamethods</h3>
159+---
160+> <p><a name="2.9.1"><h3>2.9.1 - Garbage-Collection Metamethods</h3></a>
161+1506c1503
162+< <p><a name="weak-table"><h3>2.9.2 - Weak Tables</h3></a>
163+---
164+> <p><a name="weak-table"><a name="2.9.2"><h3>2.9.2 - Weak Tables</h3></a></a>
165+1524c1521
166+< If the <code>__mode</code> field is a string containing the character `<code>k</code>&acute;,
167+---
168+> If the <code>__mode</code> field is a string containing the character&nbsp;`<code>k</code>&acute;,
169+1534c1531
170+< <p><a name="coroutine"><h2>2.10 - Coroutines</h2></a>
171+---
172+> <p><a name="coroutine"><a name="2.10"><h2>2.10 - Coroutines</h2></a></a>
173+1552c1549
174+< passing as argument the thread returned by <code>coroutine.create</code>,
175+---
176+> passing as its first argument the thread returned by <code>coroutine.create</code>,
177+1633c1630
178+< <a name="API"><h1>3 - The Application Program Interface</h1></a>
179+---
180+> <a name="API"><a name="3"><h1>3 - The Application Program Interface</h1></a></a>
181+1648c1645
182+< <p><a name="mangstate"><h2>3.1 - States</h2></a>
183+---
184+> <p><a name="mangstate"><a name="3.1"><h2>3.1 - States</h2></a></a>
185+1684c1681
186+< <p><h2>3.2 - The Stack and Indices</h2>
187+---
188+> <p><a name="3.2"><h2>3.2 - The Stack and Indices</h2></a>
189+1694c1691
190+< and it is where the C function pushes its results (see <a href="#LuacallC">3.16</a>)
191+---
192+> and it is where the C function pushes its results to be returned to the caller (see <a href="#LuacallC">3.16</a>)
193+1739c1736
194+< it ensures that at least <code>LUA_MINSTACK</code> positions are available.
195+---
196+> it ensures that at least <code>LUA_MINSTACK</code> stack positions are available.
197+1763c1760
198+< <p><h2>3.3 - Stack Manipulation</h2>
199+---
200+> <p><a name="3.3"><h2>3.3 - Stack Manipulation</h2></a>
201+1816c1813
202+< <p><h2>3.4 - Querying the Stack</h2>
203+---
204+> <p><a name="3.4"><h2>3.4 - Querying the Stack</h2></a>
205+1890c1887
206+< <p><a name="lua-to"><h2>3.5 - Getting Values from the Stack</h2></a>
207+---
208+> <p><a name="lua-to"><a name="3.5"><h2>3.5 - Getting Values from the Stack</h2></a></a>
209+1969c1966
210+< <p><a name="pushing"><h2>3.6 - Pushing Values onto the Stack</h2></a>
211+---
212+> <p><a name="pushing"><a name="3.6"><h2>3.6 - Pushing Values onto the Stack</h2></a></a>
213+1999,2000c1996
214+< const char *lua_pushvfstring (lua_State *L, const char *fmt,
215+< va_list argp);
216+---
217+> const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
218+2028c2024
219+< If <code>n</code> is 1, the result is that single string
220+---
221+> If <code>n</code>&nbsp;is&nbsp;1, the result is that single string
222+2034c2030
223+< <p><a name="GC-API"><h2>3.7 - Controlling Garbage Collection</h2></a>
224+---
225+> <p><a name="GC-API"><a name="3.7"><h2>3.7 - Controlling Garbage Collection</h2></a></a>
226+2047c2043
227+< int lua_getgccount (lua_State *L);
228+---
229+> int lua_getgccount (lua_State *L);
230+2067c2063
231+< <p><a name="userdata"><h2>3.8 - Userdata</h2></a>
232+---
233+> <p><a name="userdata"><a name="3.8"><h2>3.8 - Userdata</h2></a></a>
234+2112c2108
235+< <p><h2>3.9 - Metatables</h2>
236+---
237+> <p><a name="3.9"><h2>3.9 - Metatables</h2></a>
238+2133c2129
239+< <p><h2>3.10 - Loading Lua Chunks</h2>
240+---
241+> <p><a name="3.10"><h2>3.10 - Loading Lua Chunks</h2></a>
242+2160c2156
243+< <p><code>lua_load</code> uses an user-supplied <em>reader</em> function to read the chunk.
244+---
245+> <p><code>lua_load</code> uses a user-supplied <em>reader</em> function to read the chunk.
246+2162c2158
247+< it calls the reader,
248+---
249+> <code>lua_load</code> calls the reader,
250+2182c2178
251+< <p><h2>3.11 - Manipulating Tables</h2>
252+---
253+> <p><a name="3.11"><h2>3.11 - Manipulating Tables</h2></a>
254+2263c2259
255+< <p><a name="globals"><h2>3.12 - Manipulating Environments</h2></a>
256+---
257+> <p><a name="globals"><a name="3.12"><h2>3.12 - Manipulating Environments</h2></a></a>
258+2295c2291
259+< <p><h2>3.13 - Using Tables as Arrays</h2>
260+---
261+> <p><a name="3.13"><h2>3.13 - Using Tables as Arrays</h2></a>
262+2312c2308
263+< <p><h2>3.14 - Calling Functions</h2>
264+---
265+> <p><a name="3.14"><h2>3.14 - Calling Functions</h2></a>
266+2367c2363
267+< <p><a name="lua_pcall"><h2>3.15 - Protected Calls</h2></a>
268+---
269+> <p><a name="lua_pcall"><a name="3.15"><h2>3.15 - Protected Calls</h2></a></a>
270+2414c2410
271+< <p><a name="LuacallC"><h2>3.16 - Defining C Functions</h2></a>
272+---
273+> <p><a name="LuacallC"><a name="3.16"><h2>3.16 - Defining C Functions</h2></a></a>
274+2482c2478
275+< <p><a name="c-closure"><h2>3.17 - Defining C Closures</h2></a>
276+---
277+> <p><a name="c-closure"><a name="3.17"><h2>3.17 - Defining C Closures</h2></a></a>
278+2517c2513
279+< <p><a name="registry"><h2>3.18 - Registry</h2></a>
280+---
281+> <p><a name="registry"><a name="3.18"><h2>3.18 - Registry</h2></a></a>
282+2535c2531
283+< <p><h2>3.19 - Error Handling in C</h2>
284+---
285+> <p><a name="3.19"><h2>3.19 - Error Handling in C</h2></a>
286+2542,2543c2538,2539
287+< to set a recover point,
288+< and any error jumps to the most recent active recover point.
289+---
290+> to set a recover point;
291+> any error jumps to the most recent active recover point.
292+2546c2542
293+< Lua calls a <em>panic function</em>,
294+---
295+> Lua calls a <em>panic function</em>
296+2553,2554c2549,2550
297+< never returning (e.g. doing a long jump).
298+< Nevertheless, the corresponding Lua will not be consistent;
299+---
300+> never returning (e.g., by doing a long jump).
301+> Nevertheless, the corresponding Lua state will not be consistent;
302+2578c2574
303+< Any value returned by <code>func</code> is dicarded.
304+---
305+> Any value returned by <code>func</code> is discarded.
306+2590c2586
307+< <p><h2>3.20 - Threads</h2>
308+---
309+> <p><a name="3.20"><h2>3.20 - Threads</h2></a>
310+2611,2616c2607,2609
311+< <p>You destroy threads with <code>lua_closethread</code>:
312+< <PRE>
313+< void lua_closethread (lua_State *L, lua_State *thread);
314+< </PRE>
315+< You cannot close the sole (or last) thread of a state.
316+< Instead, you must close the state itself.
317+---
318+> <p>There is no explicit function to close or to destroy a thread.
319+> Threads are subject to garbage collection,
320+> like any Lua object.
321+2622c2615
322+< int lua_yield (lua_State *L, int nresults);
323+---
324+> int lua_yield (lua_State *L, int nresults);
325+2632c2625
326+< <code>lua_resume</code> returns 0 if there is no errors running the coroutine,
327+---
328+> <code>lua_resume</code> returns 0 if there are no errors running the coroutine,
329+2660c2653
330+< <a name="debugI"><h1>4 - The Debug Interface</h1></a>
331+---
332+> <a name="debugI"><a name="4"><h1>4 - The Debug Interface</h1></a></a>
333+2669c2662
334+< <p><h2>4.1 - Stack and Function Information</h2>
335+---
336+> <p><a name="4.1"><h2>4.1 - Stack and Function Information</h2></a>
337+2681c2674
338+< When there is no errors, <code>lua_getstack</code> returns 1;
339+---
340+> When there are no errors, <code>lua_getstack</code> returns 1;
341+2789c2782
342+< <p><h2>4.2 - Manipulating Local Variables and Upvalues</h2>
343+---
344+> <p><a name="4.2"><h2>4.2 - Manipulating Local Variables and Upvalues</h2></a>
345+2866c2859
346+< <p><a name="sub-hooks"><h2>4.3 - Hooks</h2></a>
347+---
348+> <p><a name="sub-hooks"><a name="4.3"><h2>4.3 - Hooks</h2></a></a>
349+2942c2935
350+< <a name="libraries"><h1>5 - Standard Libraries</h1></a>
351+---
352+> <a name="libraries"><a name="5"><h1>5 - Standard Libraries</h1></a></a>
353+2985c2978
354+< <p><a name="predefined"><h2>5.1 - Basic Functions</h2></a>
355+---
356+> <p><a name="predefined"><a name="5.1"><h2>5.1 - Basic Functions</h2></a></a>
357+3018c3011
358+< Terminates the last protected function called,
359+---
360+> Terminates the last protected function called
361+3046c3039
362+< <p>if the environment has a <code>"__fenv"</code> field,
363+---
364+> <p>If the environment has a <code>"__fenv"</code> field,
365+3151c3144
366+< That means that any error inside <code>f</code> is not propagated;
367+---
368+> That means that any error inside&nbsp;<code>f</code> is not propagated;
369+3155c3148
370+< which is true if the call succeeds without errors.
371+---
372+> which is <B>true</B> if the call succeeds without errors.
373+3330c3323
374+< <p><h2>5.2 - Coroutine Manipulation</h2>
375+---
376+> <p><a name="5.2"><h2>5.2 - Coroutine Manipulation</h2></a>
377+3333c3326
378+< the basic library, and come inside the table .
379+---
380+> the basic library and come inside the table <code>coroutine</code>.
381+3388c3381
382+< <p><h2>5.3 - String Manipulation</h2>
383+---
384+> <p><a name="5.3"><h2>5.3 - String Manipulation</h2></a>
385+3595c3588
386+< a <em>character class</em> is used to represent a set of characters.
387+---
388+> A <em>character class</em> is used to represent a set of characters.
389+3651c3644
390+< a <em>pattern item</em> may be
391+---
392+> A <em>pattern item</em> may be
393+3688c3681
394+< a <em>pattern</em> is a sequence of pattern items.
395+---
396+> A <em>pattern</em> is a sequence of pattern items.
397+3715c3708
398+< <p><h2>5.4 - Table Manipulation</h2>
399+---
400+> <p><a name="5.4"><h2>5.4 - Table Manipulation</h2></a>
401+3824c3817
402+< <p><a name="mathlib"><h2>5.5 - Mathematical Functions</h2></a>
403+---
404+> <p><a name="mathlib"><a name="5.5"><h2>5.5 - Mathematical Functions</h2></a></a>
405+3879c3872
406+< <p><a name="libio"><h2>5.6 - Input and Output Facilities</h2></a>
407+---
408+> <p><a name="libio"><a name="5.6"><h2>5.6 - Input and Output Facilities</h2></a></a>
409+4072c4065
410+< <p><a name="libiosys"><h2>5.7 - Operating System Facilities</h2></a>
411+---
412+> <p><a name="libiosys"><a name="5.7"><h2>5.7 - Operating System Facilities</h2></a></a>
413+4098c4091
414+< <code>wday</code> (weekday, Sunday is 1),
415+---
416+> <code>wday</code> (weekday, Sunday is&nbsp;1),
417+4187c4180
418+< <p><h2>5.8 - The Reflexive Debug Interface</h2>
419+---
420+> <p><a name="5.8"><h2>5.8 - The Reflexive Debug Interface</h2></a>
421+4323c4316
422+< <a name="lua-sa"><h1>6 - Lua Stand-alone</h1></a>
423+---
424+> <a name="lua-sa"><a name="6"><h1>6 - Lua Stand-alone</h1></a></a>
425+4462c4455
426+< Vincent Penquerc'h,
427+---
428+> Vincent Penquerc'h.
429+4583c4576
430+< <p> exp ::= <b>nil</b> <b>false</b> <b>true</b> | Number | Literal | function | prefixexp | tableconstructor | exp binop exp | unop exp
431+---
432+> <p> exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | function | prefixexp | tableconstructor | exp binop exp | unop exp
433+4612c4605,4609
434+< </body></html>
435+---
436+> <HR>
437+> <SMALL>
438+> Last update:
439+> Tue Nov 25 16:08:37 BRST 2003
440+> </SMALL>
441+4613a4611,4612
442+> </BODY>
443+> </HTML>
444+diff -r lua-5.0/include/lua.h lua-5.0.1/include/lua.h
445+2c2
446+< ** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $
447+---
448+> ** $Id: lua.h,v 1.175a 2003/03/18 12:31:39 roberto Exp $
449+17c17
450+< #define LUA_VERSION "Lua 5.0"
451+---
452+> #define LUA_VERSION "Lua 5.0.1"
453+diff -r lua-5.0/src/ldo.c lua-5.0.1/src/ldo.c
454+2c2
455+< ** $Id: ldo.c,v 1.217 2003/04/03 13:35:34 roberto Exp $
456+---
457+> ** $Id: ldo.c,v 1.217a 2003/04/03 13:35:34 roberto Exp $
458+325,326c325
459+< if (nargs >= L->top - L->base)
460+< luaG_runerror(L, "cannot resume dead coroutine");
461+---
462+> lua_assert(nargs < L->top - L->base);
463+329c328,329
464+< else if (ci->state & CI_YIELD) { /* inside a yield? */
465+---
466+> else { /* inside a yield */
467+> lua_assert(ci->state & CI_YIELD);
468+344,345d343
469+< else
470+< luaG_runerror(L, "cannot resume non-suspended coroutine");
471+351a350,358
472+> static int resume_error (lua_State *L, const char *msg) {
473+> L->top = L->ci->base;
474+> setsvalue2s(L->top, luaS_new(L, msg));
475+> incr_top(L);
476+> lua_unlock(L);
477+> return LUA_ERRRUN;
478+> }
479+>
480+>
481+355a363,368
482+> if (L->ci == L->base_ci) {
483+> if (nargs >= L->top - L->base)
484+> return resume_error(L, "cannot resume dead coroutine");
485+> }
486+> else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */
487+> return resume_error(L, "cannot resume non-suspended coroutine");
488+diff -r lua-5.0/src/lgc.c lua-5.0.1/src/lgc.c
489+2c2
490+< ** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 roberto Exp $
491+---
492+> ** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
493+113c113,114
494+< void luaC_separateudata (lua_State *L) {
495+---
496+> size_t luaC_separateudata (lua_State *L) {
497+> size_t deadmem = 0;
498+127a129
499+> deadmem += sizeudata(gcotou(curr)->uv.len);
500+136a139
501+> return deadmem;
502+247c250
503+< if (!(ci->state & CI_C) && lim < ci->top)
504+---
505+> if (lim < ci->top)
506+390c393
507+< static void checkSizes (lua_State *L) {
508+---
509+> static void checkSizes (lua_State *L, size_t deadmem) {
510+400c403
511+< G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
512+---
513+> G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
514+454c457,458
515+< static void mark (lua_State *L) {
516+---
517+> static size_t mark (lua_State *L) {
518+> size_t deadmem;
519+467c471
520+< luaC_separateudata(L); /* separate userdata to be preserved */
521+---
522+> deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
523+475a480
524+> return deadmem;
525+480c485
526+< mark(L);
527+---
528+> size_t deadmem = mark(L);
529+482c487
530+< checkSizes(L);
531+---
532+> checkSizes(L, deadmem);
533+diff -r lua-5.0/src/lgc.h lua-5.0.1/src/lgc.h
534+2c2
535+< ** $Id: lgc.h,v 1.19 2003/02/28 19:45:15 roberto Exp $
536+---
537+> ** $Id: lgc.h,v 1.19a 2003/02/28 19:45:15 roberto Exp $
538+18c18
539+< void luaC_separateudata (lua_State *L);
540+---
541+> size_t luaC_separateudata (lua_State *L);
542+diff -r lua-5.0/src/lib/lbaselib.c lua-5.0.1/src/lib/lbaselib.c
543+2c2
544+< ** $Id: lbaselib.c,v 1.130 2003/04/03 13:35:34 roberto Exp $
545+---
546+> ** $Id: lbaselib.c,v 1.130a 2003/04/03 13:35:34 roberto Exp $
547+327c327
548+< char buff[64];
549+---
550+> char buff[128];
551+diff -r lua-5.0/src/lib/liolib.c lua-5.0.1/src/lib/liolib.c
552+2c2
553+< ** $Id: liolib.c,v 2.39 2003/03/19 21:16:12 roberto Exp $
554+---
555+> ** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
556+161c161
557+< if (lua_isnone(L, 1)) {
558+---
559+> if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
560+178c178
561+< char buff[32];
562+---
563+> char buff[128];
564+diff -r lua-5.0/src/lparser.c lua-5.0.1/src/lparser.c
565+2c2
566+< ** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp $
567+---
568+> ** $Id: lparser.c,v 1.208a 2003/04/03 13:35:34 roberto Exp $
569+1143a1144
570+> FuncState *fs = ls->fs;
571+1145c1146,1147
572+< init_exp(&v, VLOCAL, ls->fs->freereg++);
573+---
574+> init_exp(&v, VLOCAL, fs->freereg);
575+> luaK_reserveregs(fs, 1);
576+1148c1150,1152
577+< luaK_storevar(ls->fs, &v, &b);
578+---
579+> luaK_storevar(fs, &v, &b);
580+> /* debug information will only see the variable after this point! */
581+> getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
582+diff -r lua-5.0/src/luac/Makefile lua-5.0.1/src/luac/Makefile
583+16c16
584+< $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
585+---
586+> $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB)
587+diff -r lua-5.0/src/luac/luac.c lua-5.0.1/src/luac/luac.c
588+2c2
589+< ** $Id: luac.c,v 1.44 2003/04/07 20:34:20 lhf Exp $
590+---
591+> ** $Id: luac.c,v 1.44a 2003/04/07 20:34:20 lhf Exp $
592+184a185
593+> lua_lock(L);
594+185a187
595+> lua_unlock(L);
596+diff -r lua-5.0/src/lvm.c lua-5.0.1/src/lvm.c
597+2c2
598+< ** $Id: lvm.c,v 1.284 2003/04/03 13:35:34 roberto Exp $
599+---
600+> ** $Id: lvm.c,v 1.284a 2003/04/03 13:35:34 roberto Exp $
601+69c69
602+< if (mask > LUA_MASKLINE) { /* instruction-hook set? */
603+---
604+> if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
605+402d401
606+< L->ci->u.l.pc = &pc;
607+405a405
608+> L->ci->u.l.pc = &pc;
609+676,678c676
610+< lua_assert(ci->u.l.pc == &pc &&
611+< ttisfunction(ci->base - 1) &&
612+< (ci->state & CI_SAVEDPC));
613+---
614+> lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
615+diff -r lua-5.0/test/luac.lua lua-5.0.1/test/luac.lua
616+4,6c4,6
617+< assert(arg[1]~=nil,"usage: lua luac.lua file.lua")
618+< f=assert(io.open("luac.out","w"))
619+< f:write(string.dump(loadfile(arg[1])))
620+---
621+> assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
622+> f=assert(io.open("luac.out","wb"))
623+> f:write(string.dump(assert(loadfile(arg[1]))))
UPDATE+24−0
@@ -0,0 +1,24 @@
1+This is Lua 5.0.1, an update of Lua 5.0 that includes the following changes,
2+which fix all known bugs in Lua 5.0.
3+
4+src/ldo.c
5+ Attempt to resume running coroutine crashed Lua
6+src/lgc.c
7+ C functions also may have stacks larger than current top
8+ Userdata to be collected still counted into new GC threshold
9+src/lgc.h
10+ Userdata to be collected still counted into new GC threshold
11+src/lparser.c
12+ Syntax `local function' did not increment stack size
13+src/lvm.c
14+ `pc' address was invalidated when a coroutine was suspended
15+ Count hook might be called without being set
16+src/lib/lbaselib.c
17+ Buffer overflow for unusual %p representation
18+src/lib/liolib.c
19+ `file.close()' could not be called without arguments
20+ Buffer overflow for unusual %p representation
21+src/luac/luac.c
22+ Missing lock/unlock
23+
24+To use this update, simply open this tarball over the original Lua 5.0 source.
doc/manual.html+115−116
@@ -2,16 +2,14 @@ · 1 unmodified line
22 <html>
33
44 <head>
5−<title>Lua 5.0 Reference Manual</title>
5+<TITLE>Lua: 5.0 reference manual</TITLE>
66 </head>
77
88 <body BGCOLOR="#FFFFFF">
99
1010 <hr>
1111 <h1>
12−<a HREF="http://www.lua.org/home.html">
13−<img SRC="logo.gif" ALT="[Lua logo]" BORDER=0>
14−</a>
12+<A HREF="http://www.lua.org/home.html"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
1513 Lua 5.0 Reference Manual
1614 </h1>
1715
@@ -19,7 +17,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line
1917 <p>
2018 <small>
2119 <a HREF="http://www.lua.org/copyright.html">Copyright</a>
22−&copy; 2003 TeCGraf, PUC-Rio. All rights reserved.
20+&copy; 2003 Tecgraf, PUC-Rio. All rights reserved.
2321 </small>
2422 <hr>
2523
@@ -29,12 +27,12 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 3 unmodified lines
2927
3028
3129
32−<h1>1 - Introduction</h1>
30+<a name="1"><h1>1 - Introduction</h1></a>
3331
3432 <p>Lua is an extension programming language designed to support
3533 general procedural programming with data description
3634 facilities.
37−It also offers good suport for object-oriented programming,
35+It also offers good support for object-oriented programming,
3836 functional programming, and data-driven programming.
3937 Lua is intended to be used as a powerful, light-weight
4038 configuration language for any program that needs one.
@@ -51,7 +49,7 @@ Through the use of C&nbsp;functions, Lua can be augmented to cope with · 10 unmodified lines
5149 a wide range of different domains,
5250 thus creating customized programming languages sharing a syntactical framework.
5351
54−<p>The Lua distribuition includes a stand-alone embedding program,
52+<p>The Lua distribution includes a stand-alone embedding program,
5553 <code>lua</code>, that uses the Lua library to offer a complete Lua interpreter.
5654
5755 <p>Lua is free software,
@@ -87,7 +85,7 @@ The evolution of an extension language: a history of Lua, · 29 unmodified lines
8785 <p>Lua means "moon" in Portuguese and is pronounced LOO-ah.
8886
8987 <p>
90−<a name="language"><h1>2 - The Language</h1></a>
88+<a name="language"><a name="2"><h1>2 - The Language</h1></a></a>
9189
9290 <p>This section describes the lexis, the syntax, and the semantics of Lua.
9391 In other words,
@@ -105,7 +103,7 @@ keywords are shown in <b>bold</b>, · 11 unmodified lines
105103 and other terminal symbols are shown in <code>typewriter</code> font,
106104 enclosed in single quotes.
107105
108−<p><a name="lexical"><h2>2.1 - Lexical Conventions</h2></a>
106+<p><a name="lexical"><a name="2.1"><h2>2.1 - Lexical Conventions</h2></a></a>
109107
110108 <p><em>Identifiers</em> in Lua can be any string of letters,
111109 digits, and underscores,
@@ -122,8 +120,7 @@ and cannot be used as identifiers: · 10 unmodified lines
122120 and break do else elseif
123121 end false for function if
124122 in local nil not or
125− repeat return then true until
126− while
123+ repeat return then true until while
127124 </PRE>
128125
129126 <p>Lua is a case-sensitive language:
@@ -211,7 +208,7 @@ the first line of a chunk is skipped if it starts with <code>#</code>. · 81 unmodified lines
211208 This facility allows the use of Lua as a script interpreter
212209 in Unix systems (see <a href="#lua-sa">6</a>).
213210
214−<p><a name="TypesSec"><h2>2.2 - Values and Types</h2></a>
211+<p><a name="TypesSec"><a name="2.2"><h2>2.2 - Values and Types</h2></a></a>
215212
216213 <p>Lua is a <em>dynamically typed language</em>.
217214 That means that
@@ -292,7 +289,7 @@ these operations do not imply any kind of copy. · 74 unmodified lines
292289 <p>The library function <code>type</code> returns a string describing the type
293290 of a given value (see <a href="#pdf-type">5.1</a>).
294291
295−<p><a name="coercion"><h3>2.2.1 - Coercion</h3></a>
292+<p><a name="coercion"><a name="2.2.1"><h3>2.2.1 - Coercion</h3></a></a>
296293
297294 <p>Lua provides automatic conversion between
298295 string and number values at run time.
@@ -303,7 +300,7 @@ the number is converted to a string, in a reasonable format. · 4 unmodified lines
303300 For complete control of how numbers are converted to strings,
304301 use the <code>format</code> function from the string library (see <a href="#format">5.3</a>).
305302
306−<p><a name="variables"><h2>2.3 - Variables</h2></a>
303+<p><a name="variables"><a name="2.3"><h2>2.3 - Variables</h2></a></a>
307304
308305 <p>Variables are places that store values.
309306
@@ -372,7 +369,7 @@ where <code>_env</code> is the environment of the running function. · 62 unmodified lines
372369 (The <code>_env</code> variable is not defined in Lua.
373370 We use it here only for explanatory purposes.)
374371
375−<p><a name="stats"><h2>2.4 - Statements</h2></a>
372+<p><a name="stats"><a name="2.4"><h2>2.4 - Statements</h2></a></a>
376373
377374 <p>Lua supports an almost conventional set of statements,
378375 similar to those in Pascal or C.
@@ -380,7 +377,7 @@ This set includes · 1 unmodified line
380377 assignment, control structures, procedure calls,
381378 table constructors, and variable declarations.
382379
383−<p><a name="chunks"><h3>2.4.1 - Chunks</h3></a>
380+<p><a name="chunks"><a name="2.4.1"><h3>2.4.1 - Chunks</h3></a></a>
384381
385382 <p>The unit of execution of Lua is called a <em>chunk</em>.
386383 A chunk is simply a sequence of statements,
@@ -405,7 +402,7 @@ Programs in source and compiled forms are interchangeable; · 18 unmodified lines
405402 Lua automatically detects the file type and acts accordingly.
406403
407404
408−<p><h3>2.4.2 - Blocks</h3>
405+<p><a name="2.4.2"><h3>2.4.2 - Blocks</h3></a>
409406 A block is a list of statements;
410407 syntactically, a block is equal to a chunk:
411408 <pre>
@@ -423,7 +420,7 @@ add a <b>return</b> or <b>break</b> statement in the middle · 11 unmodified lines
423420 of another block (see <a href="#control">2.4.4</a>).
424421
425422
426−<p><a name="assignment"><h3>2.4.3 - Assignment</h3></a>
423+<p><a name="assignment"><a name="2.4.3"><h3>2.4.3 - Assignment</h3></a></a>
427424
428425 <p>Lua allows multiple assignment.
429426 Therefore, the syntax for assignment
@@ -458,7 +455,7 @@ Thus the code · 28 unmodified lines
458455 </PRE>
459456 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
460457 because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
461−before it is assigned 4.
458+before it is assigned&nbsp;4.
462459 Similarly, the line
463460 <PRE>
464461 x, y = y, x
@@ -485,7 +482,7 @@ where <code>_env</code> is the environment of the running function. · 20 unmodified lines
485482 (The <code>_env</code> variable is not defined in Lua.
486483 We use it here only for explanatory purposes.)
487484
488−<p><a name="control"><h3>2.4.4 - Control Structures</h3></a>
485+<p><a name="control"><a name="2.4.4"><h3>2.4.4 - Control Structures</h3></a></a>
489486 The control structures
490487 <b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and
491488 familiar syntax:
@@ -516,7 +513,7 @@ so the syntax for the <b>return</b> statement is · 24 unmodified lines
516513
517514 <p>The <b>break</b> statement can be used to terminate the execution of a
518515 <b>while</b>, <b>repeat</b>, or <b>for</b> loop,
519−skiping to the next statement after the loop:
516+skipping to the next statement after the loop:
520517
521518 <pre>
522519 stat ::= <b>break</b>
@@ -536,7 +533,7 @@ their (inner) blocks. · 13 unmodified lines
536533 In practice,
537534 those idioms are only used during debugging.
538535
539−<p><a name="for"><h3>2.4.5 - For Statement</h3></a>
536+<p><a name="for"><a name="2.4.5"><h3>2.4.5 - For Statement</h3></a></a>
540537
541538 <p>The <b>for</b> statement has two forms:
542539 one numeric and one generic.
@@ -623,7 +620,7 @@ If you need these values, · 80 unmodified lines
623620 then assign them to other variables before breaking or exiting the loop.
624621 </ul>
625622
626−<p><a name="funcstat"><h3>2.4.6 - Function Calls as Statements</h3></a>
623+<p><a name="funcstat"><a name="2.4.6"><h3>2.4.6 - Function Calls as Statements</h3></a></a>
627624 To allow possible side-effects,
628625 function calls can be executed as statements:
629626 <pre>
@@ -632,7 +629,7 @@ function calls can be executed as statements: · 2 unmodified lines
632629 In this case, all returned values are thrown away.
633630 Function calls are explained in <a href="#functioncall">2.5.7</a>.
634631
635−<p><a name="localvar"><h3>2.4.7 - Local Declarations</h3></a>
632+<p><a name="localvar"><a name="2.4.7"><h3>2.4.7 - Local Declarations</h3></a></a>
636633 Local variables may be declared anywhere inside a block.
637634 The declaration may include an initial assignment:
638635 <pre>
@@ -649,7 +646,7 @@ Such local variables die when the chunk ends. · 10 unmodified lines
649646
650647 <p>The visibility rules for local variables are explained in <a href="#visibility">2.6</a>.
651648
652−<p><a name="expressions"><h2>2.5 - Expressions</h2></a>
649+<p><a name="expressions"><a name="2.5"><h2>2.5 - Expressions</h2></a></a>
653650
654651 <p>
655652 The basic expressions in Lua are the following:
@@ -680,7 +677,7 @@ or <B>nil</B> if <code>f</code> does not return any values.) · 24 unmodified lines
680677 <p>Expressions can also be built with arithmetic operators, relational operators,
681678 and logical operators, all of which are explained below.
682679
683−<p><h3>2.5.1 - Arithmetic Operators</h3>
680+<p><a name="2.5.1"><h3>2.5.1 - Arithmetic Operators</h3></a>
684681 Lua supports the usual arithmetic operators:
685682 the binary <code>+</code> (addition),
686683 <code>-</code> (subtraction), <code>*</code> (multiplication),
@@ -695,7 +692,7 @@ The standard mathematical library defines function <code>__pow</code>, · 8 unmodified lines
695692 giving the expected meaning to exponentiation
696693 (see <a href="#mathlib">5.5</a>).
697694
698−<p><a name="rel-ops"><h3>2.5.2 - Relational Operators</h3></a>
695+<p><a name="rel-ops"><a name="2.5.2"><h3>2.5.2 - Relational Operators</h3></a></a>
699696 The relational operators in Lua are
700697 <PRE>
701698 == ~= &#060; > &#060;= >=
@@ -731,7 +728,7 @@ then their values are compared according to the current locale. · 29 unmodified lines
731728 Otherwise, Lua tries to call the "lt" or the "le"
732729 metamethod (see <a href="#metatable">2.8</a>).
733730
734−<p><h3>2.5.3 - Logical Operators</h3>
731+<p><a name="2.5.3"><h3>2.5.3 - Logical Operators</h3></a>
735732 The logical operators in Lua are
736733
737734 <PRE>
@@ -764,14 +761,14 @@ For example, · 26 unmodified lines
764761 10 and 20 -> 20
765762 </PRE>
766763
767−<p><a name="concat"><h3>2.5.4 - Concatenation</h3></a>
764+<p><a name="concat"><a name="2.5.4"><h3>2.5.4 - Concatenation</h3></a></a>
768765 The string concatenation operator in Lua is
769766 denoted by two dots (`<code>..</code>&acute;).
770767 If both operands are strings or numbers, then they are converted to
771768 strings according to the rules mentioned in <a href="#coercion">2.2.1</a>.
772769 Otherwise, the "concat" metamethod is called (see <a href="#metatable">2.8</a>).
773770
774−<p><h3>2.5.5 - Precedence</h3>
771+<p><a name="2.5.5"><h3>2.5.5 - Precedence</h3></a>
775772 Operator precedence in Lua follows the table below,
776773 from lower to higher priority:
777774 <PRE>
@@ -784,12 +781,12 @@ from lower to higher priority: · 6 unmodified lines
784781 not - (unary)
785782 ^
786783 </PRE>
787−As usual, you can use parentheses to change the precedences of an expression.
784+You can use parentheses to change the precedences in an expression.
788785 The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)
789786 operators are right associative.
790787 All other binary operators are left associative.
791788
792−<p><a name="tableconstructor"><h3>2.5.6 - Table Constructors</h3></a>
789+<p><a name="tableconstructor"><a name="2.5.6"><h3>2.5.6 - Table Constructors</h3></a></a>
793790 Table constructors are expressions that create tables.
794791 Every time a constructor is evaluated, a new table is created.
795792 Constructors can be used to create empty tables,
@@ -839,7 +836,7 @@ enclose the function call in parentheses (see <a href="#expressions">2.5</a>). · 43 unmodified lines
839836 <p>The field list may have an optional trailing separator,
840837 as a convenience for machine-generated code.
841838
842−<p><a name="functioncall"><h3>2.5.7 - Function Calls</h3></a>
839+<p><a name="functioncall"><a name="2.5.7"><h3>2.5.7 - Function Calls</h3></a></a>
843840 A function call in Lua has the following syntax:
844841 <pre>
845842 functioncall ::= prefixexp args
@@ -944,12 +941,12 @@ So, all the following examples are not tails calls: · 98 unmodified lines
944941 <PRE>
945942 return (f(x)) -- results adjusted to 1
946943 return 2 * f(x)
947− return x, f(x) -- adicional results
944+ return x, f(x) -- additional results
948945 f(x); return -- results discarded
949946 return x or f(x) -- results adjusted to 1
950947 </PRE>
951948
952−<p><a name="func-def"><h3>2.5.8 - Function Definitions</h3></a>
949+<p><a name="func-def"><a name="2.5.8"><h3>2.5.8 - Function Definitions</h3></a></a>
953950
954951 <p>The syntax for function definition is
955952 <pre>
@@ -1058,7 +1055,7 @@ is syntactic sugar for · 102 unmodified lines
10581055 t.a.b.c.f = function (self, ...) ... end
10591056 </PRE>
10601057
1061−<p><a name="visibility"><h2>2.6 - Visibility Rules</h2></a>
1058+<p><a name="visibility"><a name="2.6"><h2>2.6 - Visibility Rules</h2></a></a>
10621059
10631060
10641061 <p>Lua is a lexically scoped language.
@@ -1115,7 +1112,7 @@ The loop creates ten closures · 50 unmodified lines
11151112 Each of these closures uses a different <code>y</code> variable,
11161113 while all of them share the same <code>x</code>.
11171114
1118−<p><a name="error"><h2>2.7 - Error Handling</h2></a>
1115+<p><a name="error"><a name="2.7"><h2>2.7 - Error Handling</h2></a></a>
11191116
11201117 <p>Because Lua is an extension language,
11211118 all Lua actions start from C&nbsp;code in the host program
@@ -1130,7 +1127,7 @@ which can take appropriate measures · 8 unmodified lines
11301127 If you need to catch errors in Lua,
11311128 you can use the <code>pcall</code> function (see <a href="#pdf-pcall">5.1</a>).
11321129
1133−<p><a name="metatable"><h2>2.8 - Metatables</h2></a>
1130+<p><a name="metatable"><a name="2.8"><h2>2.8 - Metatables</h2></a></a>
11341131
11351132 <p>Every table and userdata object in Lua may have a <em>metatable</em>.
11361133 This <em>metatable</em> is an ordinary Lua table
@@ -1312,7 +1309,7 @@ and the same metamethod for the selected operation. · 175 unmodified lines
13121309 The "eq" event is defined as follows:
13131310 <PRE>
13141311 function eq_event (op1, op2)
1315− if type(op1) ~= type(op2) then -- diferent types?
1312+ if type(op1) ~= type(op2) then -- different types?
13161313 return false -- different objects
13171314 end
13181315 if op1 == op2 then -- primitive equal?
@@ -1440,7 +1437,7 @@ called when Lua calls a value. · 121 unmodified lines
14401437
14411438 <p></ul>
14421439
1443−<p><a name="GC"><h2>2.9 - Garbage Collection</h2></a>
1440+<p><a name="GC"><a name="2.9"><h2>2.9 - Garbage Collection</h2></a></a>
14441441
14451442 <p>Lua does automatic memory management.
14461443 That means that
@@ -1471,7 +1468,7 @@ Using Lua code you have a more limited control over garbage-collection cycles, · 24 unmodified lines
14711468 through the <code>gcinfo</code> and <code>collectgarbage</code> functions
14721469 (see <a href="#predefined">5.1</a>).
14731470
1474−<p><h3>2.9.1 - Garbage-Collection Metamethods</h3>
1471+<p><a name="2.9.1"><h3>2.9.1 - Garbage-Collection Metamethods</h3></a>
14751472
14761473 <p>Using the C&nbsp;API,
14771474 you can set garbage-collector metamethods for userdata (see <a href="#metatable">2.8</a>).
@@ -1503,7 +1500,7 @@ among those collected in that cycle. · 25 unmodified lines
15031500 That is, the first finalizer to be called is the one associated
15041501 with the userdata created last in the program.
15051502
1506−<p><a name="weak-table"><h3>2.9.2 - Weak Tables</h3></a>
1503+<p><a name="weak-table"><a name="2.9.2"><h3>2.9.2 - Weak Tables</h3></a></a>
15071504
15081505 <p>A <em>weak table</em> is a table whose elements are
15091506 <em>weak references</em>.
@@ -1521,7 +1518,7 @@ In any case, if either the key or the value is collected, · 11 unmodified lines
15211518 the whole pair is removed from the table.
15221519 The weakness of a table is controlled by the value of the
15231520 <code>__mode</code> field of its metatable.
1524−If the <code>__mode</code> field is a string containing the character `<code>k</code>&acute;,
1521+If the <code>__mode</code> field is a string containing the character&nbsp;`<code>k</code>&acute;,
15251522 the keys in the table are weak.
15261523 If <code>__mode</code> contains `<code>v</code>&acute;,
15271524 the values in the table are weak.
@@ -1531,7 +1528,7 @@ you should not change the value of its field <code>__mode</code>. · 3 unmodified lines
15311528 Otherwise, the weak behavior of the tables controlled by this
15321529 metatable is undefined.
15331530
1534−<p><a name="coroutine"><h2>2.10 - Coroutines</h2></a>
1531+<p><a name="coroutine"><a name="2.10"><h2>2.10 - Coroutines</h2></a></a>
15351532
15361533 <p>Lua supports coroutines,
15371534 also called <em>semi-coroutines</em>
@@ -1549,7 +1546,7 @@ returns a handle to it (an object of type <em>thread</em>); · 11 unmodified lines
15491546 it does not start the coroutine execution.
15501547
15511548 <p>When you first call <code>coroutine.resume</code>,
1552−passing as argument the thread returned by <code>coroutine.create</code>,
1549+passing as its first argument the thread returned by <code>coroutine.create</code>,
15531550 the coroutine starts its execution,
15541551 at the first line of its main function.
15551552 Extra arguments passed to <code>coroutine.resume</code> are given as
@@ -1630,7 +1627,7 @@ main false cannot resume dead coroutine · 74 unmodified lines
16301627 </PRE>
16311628
16321629 <p>
1633−<a name="API"><h1>3 - The Application Program Interface</h1></a>
1630+<a name="API"><a name="3"><h1>3 - The Application Program Interface</h1></a></a>
16341631
16351632
16361633 <p>This section describes the C API for Lua, that is,
@@ -1645,7 +1642,7 @@ All such macros use each of its arguments exactly once · 8 unmodified lines
16451642 (except for the first argument, which is always a Lua state),
16461643 and so do not generate hidden side-effects.
16471644
1648−<p><a name="mangstate"><h2>3.1 - States</h2></a>
1645+<p><a name="mangstate"><a name="3.1"><h2>3.1 - States</h2></a></a>
16491646
16501647 <p>The Lua library is fully reentrant:
16511648 it has no global variables.
@@ -1681,7 +1678,7 @@ such as a daemon or a web server, · 29 unmodified lines
16811678 might need to release states as soon as they are not needed,
16821679 to avoid growing too large.
16831680
1684−<p><h2>3.2 - The Stack and Indices</h2>
1681+<p><a name="3.2"><h2>3.2 - The Stack and Indices</h2></a>
16851682
16861683 <p>Lua uses a <em>virtual stack</em> to pass values to and from C.
16871684 Each element in this stack represents a Lua value
@@ -1691,7 +1688,7 @@ Each element in this stack represents a Lua value · 3 unmodified lines
16911688 which is independent of previous stacks and of stacks of
16921689 C functions that are still active.
16931690 That stack initially contains any arguments to the C function,
1694−and it is where the C function pushes its results (see <a href="#LuacallC">3.16</a>)
1691+and it is where the C function pushes its results to be returned to the caller (see <a href="#LuacallC">3.16</a>)
16951692 to be returned to the caller.
16961693
16971694 <p>For convenience,
@@ -1736,7 +1733,7 @@ if the stack is already larger than the new size, · 38 unmodified lines
17361733 it is left unchanged.
17371734
17381735 <p>Whenever Lua calls C,
1739−it ensures that at least <code>LUA_MINSTACK</code> positions are available.
1736+it ensures that at least <code>LUA_MINSTACK</code> stack positions are available.
17401737 <code>LUA_MINSTACK</code> is defined in <code>lua.h</code> as 20,
17411738 so that usually you do not have to worry about stack space
17421739 unless your code has loops pushing elements onto the stack.
@@ -1760,7 +1757,7 @@ but are not in the stack. · 17 unmodified lines
17601757 Pseudo-indices are used to access the global environment,
17611758 the registry, and the upvalues of a C&nbsp;function (see <a href="#c-closure">3.17</a>).
17621759
1763−<p><h2>3.3 - Stack Manipulation</h2>
1760+<p><a name="3.3"><h2>3.3 - Stack Manipulation</h2></a>
17641761 The API offers the following functions for basic stack manipulation:
17651762 <PRE>
17661763 void lua_settop (lua_State *L, int index);
@@ -1813,7 +1810,7 @@ then · 46 unmodified lines
18131810 lua_settop(L, 6) --> 30 40 nil nil nil nil*
18141811 </PRE>
18151812
1816−<p><h2>3.4 - Querying the Stack</h2>
1813+<p><a name="3.4"><h2>3.4 - Querying the Stack</h2></a>
18171814
18181815 <p>To check the type of a stack element,
18191816 the following functions are available:
@@ -1887,7 +1884,7 @@ are equivalent to their counterparts in Lua (see <a href="#rel-ops">2.5.2</a>). · 67 unmodified lines
18871884 without metamethods.
18881885 These functions return 0 (false) if any of the indices are non-valid.
18891886
1890−<p><a name="lua-to"><h2>3.5 - Getting Values from the Stack</h2></a>
1887+<p><a name="lua-to"><a name="3.5"><h2>3.5 - Getting Values from the Stack</h2></a></a>
18911888
18921889 <p>To translate a value in the stack to a specific C&nbsp;type,
18931890 you can use the following conversion functions:
@@ -1966,7 +1963,7 @@ Typically this function is used for debug information. · 72 unmodified lines
19661963
19671964 <p><code>lua_touserdata</code> is explained in <a href="#userdata">3.8</a>.
19681965
1969−<p><a name="pushing"><h2>3.6 - Pushing Values onto the Stack</h2></a>
1966+<p><a name="pushing"><a name="3.6"><h2>3.6 - Pushing Values onto the Stack</h2></a></a>
19701967
19711968 <p>The API has the following functions to
19721969 push C&nbsp;values onto the stack:
@@ -1996,8 +1993,7 @@ which accepts an explicit size. · 23 unmodified lines
19961993 <p>You can also push "formatted" strings:
19971994 <PRE>
19981995 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
1999− const char *lua_pushvfstring (lua_State *L, const char *fmt,
2000− va_list argp);
1996+ const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
20011997 </PRE>
20021998
20031999 These functions push onto the stack a formatted string
@@ -2025,13 +2021,13 @@ The conversion specifiers can be simply · 21 unmodified lines
20252021
20262022 concatenates the <code>n</code> values at the top of the stack,
20272023 pops them, and leaves the result at the top.
2028−If <code>n</code> is 1, the result is that single string
2024+If <code>n</code>&nbsp;is&nbsp;1, the result is that single string
20292025 (that is, the function does nothing);
20302026 if <code>n</code> is 0, the result is the empty string.
20312027 Concatenation is done following the usual semantics of Lua
20322028 (see <a href="#concat">2.5.4</a>).
20332029
2034−<p><a name="GC-API"><h2>3.7 - Controlling Garbage Collection</h2></a>
2030+<p><a name="GC-API"><a name="3.7"><h2>3.7 - Controlling Garbage Collection</h2></a></a>
20352031
20362032 <p>Lua uses two numbers to control its garbage collection:
20372033 the <em>count</em> and the <em>threshold</em> (see <a href="#GC">2.9</a>).
@@ -2044,7 +2040,7 @@ and the threshold is set to twice the count value. · 6 unmodified lines
20442040 <p>You can access the current values of these two numbers through the
20452041 following functions:
20462042 <PRE>
2047− int lua_getgccount (lua_State *L);
2043+ int lua_getgccount (lua_State *L);
20482044 int lua_getgcthreshold (lua_State *L);
20492045 </PRE>
20502046
@@ -2064,7 +2060,7 @@ In particular · 13 unmodified lines
20642060 After the collection,
20652061 a new threshold is set according to the previous rule.
20662062
2067−<p><a name="userdata"><h2>3.8 - Userdata</h2></a>
2063+<p><a name="userdata"><a name="3.8"><h2>3.8 - Userdata</h2></a></a>
20682064
20692065 <p>Userdata represents C values in Lua.
20702066 Lua supports two types of userdata:
@@ -2109,7 +2105,7 @@ when applied on a non-userdata value, it returns <code>NULL</code>. · 38 unmodified lines
21092105 it calls the userdata's <code>gc</code> metamethod, if any,
21102106 and then it frees the userdata's corresponding memory.
21112107
2112−<p><h2>3.9 - Metatables</h2>
2108+<p><a name="3.9"><h2>3.9 - Metatables</h2></a>
21132109
21142110 <p>The following functions allow you to manipulate the metatables
21152111 of an object:
@@ -2130,7 +2126,7 @@ set the metatable of the given object · 14 unmodified lines
21302126 (that is, when the object is neither a userdata nor a table);
21312127 even then it pops the table from the stack.
21322128
2133−<p><h2>3.10 - Loading Lua Chunks</h2>
2129+<p><a name="3.10"><h2>3.10 - Loading Lua Chunks</h2></a>
21342130
21352131 <p>You can load a Lua chunk with <code>lua_load</code>:
21362132 <PRE>
@@ -2157,9 +2153,9 @@ Otherwise, it pushes an error message. · 20 unmodified lines
21572153 <p><code>lua_load</code> automatically detects whether the chunk is text or binary,
21582154 and loads it accordingly (see program <code>luac</code>).
21592155
2160−<p><code>lua_load</code> uses an user-supplied <em>reader</em> function to read the chunk.
2156+<p><code>lua_load</code> uses a user-supplied <em>reader</em> function to read the chunk.
21612157 Everytime it needs another piece of the chunk,
2162−it calls the reader,
2158+<code>lua_load</code> calls the reader,
21632159 passing along its <code>data</code> parameter.
21642160 The reader must return a pointer to a block of memory
21652161 with a new piece of the chunk
@@ -2179,7 +2175,7 @@ for examples of how to use <code>lua_load</code> · 13 unmodified lines
21792175 and for some ready-to-use functions to load chunks
21802176 from files and strings.
21812177
2182−<p><h2>3.11 - Manipulating Tables</h2>
2178+<p><a name="3.11"><h2>3.11 - Manipulating Tables</h2></a>
21832179
21842180 <p>Tables are created by calling
21852181 the function
@@ -2260,7 +2256,7 @@ unless you know that the key is actually a string. · 74 unmodified lines
22602256 Recall that <code>lua_tostring</code> <em>changes</em> the value at the given index;
22612257 this confuses the next call to <code>lua_next</code>.
22622258
2263−<p><a name="globals"><h2>3.12 - Manipulating Environments</h2></a>
2259+<p><a name="globals"><a name="3.12"><h2>3.12 - Manipulating Environments</h2></a></a>
22642260
22652261 <p>All global variables are kept in ordinary Lua tables,
22662262 called environments.
@@ -2292,7 +2288,7 @@ the new environment for the function at index <code>index</code> in the stack. · 25 unmodified lines
22922288 If the object at the given index is not a Lua function,
22932289 <code>lua_setfenv</code> returns 0.
22942290
2295−<p><h2>3.13 - Using Tables as Arrays</h2>
2291+<p><a name="3.13"><h2>3.13 - Using Tables as Arrays</h2></a>
22962292 The API has functions that help to use Lua tables as arrays,
22972293 that is,
22982294 tables indexed by numbers only:
@@ -2309,7 +2305,7 @@ at stack position <code>index</code>. · 10 unmodified lines
23092305 at stack position <code>index</code> to the value at the top of the stack,
23102306 removing this value from the stack.
23112307
2312−<p><h2>3.14 - Calling Functions</h2>
2308+<p><a name="3.14"><h2>3.14 - Calling Functions</h2></a>
23132309
23142310 <p>Functions defined in Lua
23152311 and C&nbsp;functions registered in Lua
@@ -2364,7 +2360,7 @@ Usually programmers define and use several macros and auxiliary functions · 48 unmodified lines
23642360 that provide higher level access to Lua.
23652361 See the source code of the standard libraries for examples.)
23662362
2367−<p><a name="lua_pcall"><h2>3.15 - Protected Calls</h2></a>
2363+<p><a name="lua_pcall"><a name="3.15"><h2>3.15 - Protected Calls</h2></a></a>
23682364
23692365 <p>When you call a function with <code>lua_call</code>,
23702366 any error inside the called function is propagated upwards
@@ -2411,7 +2407,7 @@ For such errors, Lua does not call the error handler function. · 40 unmodified lines
24112407 error while running the error handler function.
24122408 </ul>
24132409
2414−<p><a name="LuacallC"><h2>3.16 - Defining C Functions</h2></a>
2410+<p><a name="LuacallC"><a name="3.16"><h2>3.16 - Defining C Functions</h2></a></a>
24152411
24162412 <p>Lua can be extended with functions written in&nbsp;C.
24172413 These functions must be of type <code>lua_CFunction</code>,
@@ -2479,7 +2475,7 @@ the C&nbsp;function <code>foo</code> above may be registered in Lua as · 61 unmodified lines
24792475 lua_register(L, "average", foo);
24802476 </PRE>
24812477
2482−<p><a name="c-closure"><h2>3.17 - Defining C Closures</h2></a>
2478+<p><a name="c-closure"><a name="3.17"><h2>3.17 - Defining C Closures</h2></a></a>
24832479
24842480 <p>When a C&nbsp;function is created,
24852481 it is possible to associate some values with it,
@@ -2514,7 +2510,7 @@ produces an acceptable (but invalid) index. · 28 unmodified lines
25142510 see the standard libraries in the official Lua distribution
25152511 (<code>src/lib/*.c</code>).
25162512
2517−<p><a name="registry"><h2>3.18 - Registry</h2></a>
2513+<p><a name="registry"><a name="3.18"><h2>3.18 - Registry</h2></a></a>
25182514
25192515 <p>Lua provides a registry,
25202516 a pre-defined table that can be used by any C&nbsp;code to
@@ -2532,26 +2528,26 @@ or a light userdata with the address of a C object in your code. · 11 unmodified lines
25322528 implemented by the auxiliary library,
25332529 and therefore should not be used by other purposes.
25342530
2535−<p><h2>3.19 - Error Handling in C</h2>
2531+<p><a name="3.19"><h2>3.19 - Error Handling in C</h2></a>
25362532
25372533 <p>Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
25382534 When Lua faces any error
25392535 (such as memory allocation errors, type errors, syntax errors)
25402536 it <em>raises</em> an error, that is, it does a long jump.
25412537 A <em>protected environment</em> uses <code>setjmp</code>
2542−to set a recover point,
2543−and any error jumps to the most recent active recover point.
2538+to set a recover point;
2539+any error jumps to the most recent active recover point.
25442540
25452541 <p>If an error happens outside any protected environment,
2546−Lua calls a <em>panic function</em>,
2542+Lua calls a <em>panic function</em>
25472543 and then calls <code>exit(EXIT_FAILURE)</code>.
25482544 You can change the panic function with
25492545 <PRE>
25502546 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
25512547 </PRE>
25522548 Your new panic function may avoid the application exit by
2553−never returning (e.g. doing a long jump).
2554−Nevertheless, the corresponding Lua will not be consistent;
2549+never returning (e.g., by doing a long jump).
2550+Nevertheless, the corresponding Lua state will not be consistent;
25552551 the only safe operation with it is to close it.
25562552
25572553 <p>Almost any function in the API may raise an error,
@@ -2575,7 +2571,7 @@ In case of errors, · 17 unmodified lines
25752571 (see <a href="#lua_pcall">3.15</a>),
25762572 plus the error object on the top of the stack;
25772573 otherwise, it returns zero, and does not change the stack.
2578−Any value returned by <code>func</code> is dicarded.
2574+Any value returned by <code>func</code> is discarded.
25792575
25802576 <p>C code can generate a Lua error calling the function
25812577 <PRE>
@@ -2587,7 +2583,7 @@ must be on the stack top. · 5 unmodified lines
25872583 This function does a long jump,
25882584 and therefore never returns.
25892585
2590−<p><h2>3.20 - Threads</h2>
2586+<p><a name="3.20"><h2>3.20 - Threads</h2></a>
25912587
25922588 <p>Lua offers partial support for multiple threads of execution.
25932589 If you have a C&nbsp;library that offers multi-threading,
@@ -2608,18 +2604,15 @@ but has an independent run-time stack. · 14 unmodified lines
26082604 When you create a thread, this table is the same as that of the given state,
26092605 but you can change each one independently.
26102606
2611−<p>You destroy threads with <code>lua_closethread</code>:
2612−<PRE>
2613− void lua_closethread (lua_State *L, lua_State *thread);
2614−</PRE>
2615−You cannot close the sole (or last) thread of a state.
2616−Instead, you must close the state itself.
2607+<p>There is no explicit function to close or to destroy a thread.
2608+Threads are subject to garbage collection,
2609+like any Lua object.
26172610
26182611 <p>To manipulate threads as coroutines,
26192612 Lua offers the following functions:
26202613 <PRE>
26212614 int lua_resume (lua_State *L, int narg);
2622− int lua_yield (lua_State *L, int nresults);
2615+ int lua_yield (lua_State *L, int nresults);
26232616 </PRE>
26242617
26252618 To start a coroutine, you first create a new thread;
@@ -2629,7 +2622,7 @@ with <code>narg</code> being the number of arguments. · 3 unmodified lines
26292622 This call returns when the coroutine suspends or finishes its execution.
26302623 When it returns, the stack contains all values passed to <code>lua_yield</code>,
26312624 or all values returned by the body function.
2632−<code>lua_resume</code> returns 0 if there is no errors running the coroutine,
2625+<code>lua_resume</code> returns 0 if there are no errors running the coroutine,
26332626 or an error code (see <a href="#lua_pcall">3.15</a>).
26342627 In case of errors,
26352628 the stack contains only the error message.
@@ -2657,7 +2650,7 @@ It pops <code>n</code> values from the stack <code>from</code>, · 21 unmodified lines
26572650 and puhses them into the stack <code>to</code>.
26582651
26592652 <p>
2660−<a name="debugI"><h1>4 - The Debug Interface</h1></a>
2653+<a name="debugI"><a name="4"><h1>4 - The Debug Interface</h1></a></a>
26612654
26622655 <p>Lua has no built-in debugging facilities.
26632656 Instead, it offers a special interface
@@ -2666,7 +2659,7 @@ This interface allows the construction of different · 2 unmodified lines
26662659 kinds of debuggers, profilers, and other tools
26672660 that need "inside information" from the interpreter.
26682661
2669−<p><h2>4.1 - Stack and Function Information</h2>
2662+<p><a name="4.1"><h2>4.1 - Stack and Function Information</h2></a>
26702663
26712664 <p>The main function to get information about the interpreter runtime stack is
26722665 <PRE>
@@ -2678,7 +2671,7 @@ an identification of the <em>activation record</em> · 5 unmodified lines
26782671 of the function executing at a given level.
26792672 Level&nbsp;0 is the current running function,
26802673 whereas level <em>n+1</em> is the function that has called level <em>n</em>.
2681−When there is no errors, <code>lua_getstack</code> returns 1;
2674+When there are no errors, <code>lua_getstack</code> returns 1;
26822675 when called with a level greater than the stack depth,
26832676 it returns 0.
26842677
@@ -2786,7 +2779,7 @@ The number of upvalues of the function. · 101 unmodified lines
27862779
27872780 <p></ul>
27882781
2789−<p><h2>4.2 - Manipulating Local Variables and Upvalues</h2>
2782+<p><a name="4.2"><h2>4.2 - Manipulating Local Variables and Upvalues</h2></a>
27902783
27912784 <p>For the manipulation of local variables and upvalues,
27922785 the debug interface uses indices:
@@ -2863,7 +2856,7 @@ local variables and upvalues for a function at a given level of the stack: · 70 unmodified lines
28632856 }
28642857 </PRE>
28652858
2866−<p><a name="sub-hooks"><h2>4.3 - Hooks</h2></a>
2859+<p><a name="sub-hooks"><a name="4.3"><h2>4.3 - Hooks</h2></a></a>
28672860
28682861 <p>Lua offers a mechanism of hooks, which are
28692862 user-defined C functions that are called during the program execution.
@@ -2939,7 +2932,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 69 unmodified lines
29392932 that execution occurs without any calls to hooks.
29402933
29412934 <p>
2942−<a name="libraries"><h1>5 - Standard Libraries</h1></a>
2935+<a name="libraries"><a name="5"><h1>5 - Standard Libraries</h1></a></a>
29432936
29442937 <p>The standard libraries provide useful functions
29452938 that are implemented directly through the C API.
@@ -2982,7 +2975,7 @@ These functions are declared in <code>lualib.h</code>. · 36 unmodified lines
29822975
29832976
29842977
2985−<p><a name="predefined"><h2>5.1 - Basic Functions</h2></a>
2978+<p><a name="predefined"><a name="5.1"><h2>5.1 - Basic Functions</h2></a></a>
29862979
29872980 <p>The basic library provides some core functions to Lua.
29882981 If you do not include this library in your application,
@@ -3015,7 +3008,7 @@ to its caller (that is, it does not run in protected mode). · 26 unmodified lines
30153008
30163009 <p><a name="pdf-error"><h3><code>error (message [, level])</code></h3></a>
30173010
3018−Terminates the last protected function called,
3011+Terminates the last protected function called
30193012 and returns <code>message</code> as the error message.
30203013 Function <code>error</code> never returns.
30213014
@@ -3043,7 +3036,7 @@ or if <code>f</code> is 0, · 21 unmodified lines
30433036 <code>getfenv</code> returns the global environment.
30443037 The default for <code>f</code> is 1.
30453038
3046−<p>if the environment has a <code>"__fenv"</code> field,
3039+<p>If the environment has a <code>"__fenv"</code> field,
30473040 returns the associated value, instead of the environment.
30483041
30493042 <p><a name="pdf-getmetatable"><h3><code>getmetatable (object)</code></h3></a>
@@ -3148,11 +3141,11 @@ will iterate over all key-value pairs of table <code>t</code>. · 98 unmodified lines
31483141
31493142 <p>Calls function <code>f</code> with
31503143 the given arguments in protected mode.
3151−That means that any error inside <code>f</code> is not propagated;
3144+That means that any error inside&nbsp;<code>f</code> is not propagated;
31523145 instead, <code>pcall</code> catches the error
31533146 and returns a status code.
31543147 Its first result is the status code (a boolean),
3155−which is true if the call succeeds without errors.
3148+which is <B>true</B> if the call succeeds without errors.
31563149 In such case, <code>pcall</code> also returns all results from the call,
31573150 after this first result.
31583151 In case of any error, <code>pcall</code> returns <B>false</B> plus the error message.
@@ -3327,10 +3320,10 @@ after this first result. · 168 unmodified lines
33273320 In case of any error,
33283321 <code>xpcall</code> returns false plus the result from <code>err</code>.
33293322
3330−<p><h2>5.2 - Coroutine Manipulation</h2>
3323+<p><a name="5.2"><h2>5.2 - Coroutine Manipulation</h2></a>
33313324
33323325 <p>The operations related to coroutines comprise a sub-library of
3333−the basic library, and come inside the table .
3326+the basic library and come inside the table <code>coroutine</code>.
33343327 See <a href="#coroutine">2.10</a> for a general description of coroutines.
33353328
33363329 <p><h3><code>coroutine.create (f)</code></h3>
@@ -3385,7 +3378,7 @@ The coroutine cannot be running neither a C function, · 48 unmodified lines
33853378 nor a metamethod, nor an iterator.
33863379 Any arguments to <code>yield</code> go as extra results to <code>resume</code>.
33873380
3388−<p><h2>5.3 - String Manipulation</h2>
3381+<p><a name="5.3"><h2>5.3 - String Manipulation</h2></a>
33893382 This library provides generic functions for string manipulation,
33903383 such as finding and extracting substrings, and pattern matching.
33913384 When indexing a string in Lua, the first character is at position&nbsp;1
@@ -3592,7 +3585,7 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 200 unmodified lines
35923585 <p><a name="pm"><h3>Patterns</h3></a>
35933586
35943587 <p><p>
3595−a <em>character class</em> is used to represent a set of characters.
3588+A <em>character class</em> is used to represent a set of characters.
35963589 The following combinations are allowed in describing a character class:
35973590 <ul>
35983591 <li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters
@@ -3648,7 +3641,7 @@ In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</c · 49 unmodified lines
36483641 The second form should be preferred for portability.
36493642
36503643 <p><p>
3651−a <em>pattern item</em> may be
3644+A <em>pattern item</em> may be
36523645 <ul>
36533646 <li>
36543647 a single character class,
@@ -3685,7 +3678,7 @@ balanced parentheses. · 30 unmodified lines
36853678 </ul>
36863679
36873680 <p><p>
3688−a <em>pattern</em> is a sequence of pattern items.
3681+A <em>pattern</em> is a sequence of pattern items.
36893682 A `<code>^</code>&acute; at the beginning of a pattern anchors the match at the
36903683 beginning of the subject string.
36913684 A `<code>$</code>&acute; at the end of a pattern anchors the match at the
@@ -3712,7 +3705,7 @@ string <code>"flaaap"</code>, there will be two captures: 3 and 5. · 20 unmodified lines
37123705
37133706 <p>A pattern cannot contain embedded zeros. Use <code>%z</code> instead.
37143707
3715−<p><h2>5.4 - Table Manipulation</h2>
3708+<p><a name="5.4"><h2>5.4 - Table Manipulation</h2></a>
37163709 This library provides generic functions for table manipulation.
37173710 It provides all its functions inside the table <code>table</code>.
37183711
@@ -3821,7 +3814,7 @@ that value is changed to the given <code>n</code>. · 102 unmodified lines
38213814 Otherwise, it updates an internal state
38223815 so that subsequent calls to <code>table.getn(table)</code> return <code>n</code>.
38233816
3824−<p><a name="mathlib"><h2>5.5 - Mathematical Functions</h2></a>
3817+<p><a name="mathlib"><a name="5.5"><h2>5.5 - Mathematical Functions</h2></a></a>
38253818
38263819 <p>This library is an interface to most of the functions of the
38273820 standard C&nbsp;math library.
@@ -3876,7 +3869,7 @@ The <code>math.randomseed</code> function sets a "seed" · 48 unmodified lines
38763869 for the pseudo-random generator:
38773870 Equal seeds produce equal sequences of numbers.
38783871
3879−<p><a name="libio"><h2>5.6 - Input and Output Facilities</h2></a>
3872+<p><a name="libio"><a name="5.6"><h2>5.6 - Input and Output Facilities</h2></a></a>
38803873
38813874 <p>The I/O library provides two different styles for file manipulation.
38823875 The first one uses implicit file descriptors,
@@ -4069,7 +4062,7 @@ The arguments must be strings or numbers. · 186 unmodified lines
40694062 To write other values,
40704063 use <code>tostring</code> or <code>string.format</code> before <code>write</code>.
40714064
4072−<p><a name="libiosys"><h2>5.7 - Operating System Facilities</h2></a>
4065+<p><a name="libiosys"><a name="5.7"><h2>5.7 - Operating System Facilities</h2></a></a>
40734066
40744067 <p>This library is implemented through table <code>os</code>.
40754068
@@ -4095,7 +4088,7 @@ if <code>format</code> is <code>*t</code>, · 19 unmodified lines
40954088 then <code>date</code> returns a table with the following fields:
40964089 <code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),
40974090 <code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),
4098−<code>wday</code> (weekday, Sunday is 1),
4091+<code>wday</code> (weekday, Sunday is&nbsp;1),
40994092 <code>yday</code> (day of the year),
41004093 and <code>isdst</code> (daylight saving flag, a boolean).
41014094
@@ -4184,7 +4177,7 @@ and the time you open the file, · 82 unmodified lines
41844177 it is possible for another process
41854178 to create a file with the same name.
41864179
4187−<p><h2>5.8 - The Reflexive Debug Interface</h2>
4180+<p><a name="5.8"><h2>5.8 - The Reflexive Debug Interface</h2></a>
41884181
41894182 <p>The <code>debug</code> library provides
41904183 the functionality of the debug interface to Lua programs.
@@ -4320,7 +4313,7 @@ This function is typically used with <code>xpcall</code> to produce · 129 unmodified lines
43204313 better error messages.
43214314
43224315 <p>
4323−<a name="lua-sa"><h1>6 - Lua Stand-alone</h1></a>
4316+<a name="lua-sa"><a name="6"><h1>6 - Lua Stand-alone</h1></a></a>
43244317
43254318 <p>Although Lua has been designed as an extension language,
43264319 to be embedded in a host C&nbsp;program,
@@ -4459,7 +4452,7 @@ Stephan Herrmann, · 132 unmodified lines
44594452 Steve Dekorte,
44604453 Thatcher Ulrich,
44614454 Tom&#225;s Gorham,
4462−Vincent Penquerc'h,
4455+Vincent Penquerc'h.
44634456 Thank you!
44644457
44654458 <p><hr>
@@ -4580,7 +4573,7 @@ Use <code>lua_newuserdata</code> or <code>lua_pushlightuserdata</code> instead. · 114 unmodified lines
45804573
45814574 <p> explist1 ::= {exp `<b>,</b>&acute;} exp
45824575
4583−<p> exp ::= <b>nil</b> <b>false</b> <b>true</b> | Number | Literal | function | prefixexp | tableconstructor | exp binop exp | unop exp
4576+<p> exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | function | prefixexp | tableconstructor | exp binop exp | unop exp
45844577
45854578 <p> prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
45864579
@@ -4609,5 +4602,11 @@ Use <code>lua_newuserdata</code> or <code>lua_pushlightuserdata</code> instead. · 22 unmodified lines
46094602
46104603 <p>
46114604
4612−</body></html>
4605+<HR>
4606+<SMALL>
4607+Last update:
4608+Tue Nov 25 16:08:37 BRST 2003
4609+</SMALL>
46134610
4611+</BODY>
4612+</HTML>
etc/.exrc+0−1
@@ -1 +0,0 @@
1−/home/n/lhf/lib/vi/c
include/lua.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $
2+** $Id: lua.h,v 1.175a 2003/03/18 12:31:39 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
55 ** http://www.lua.org mailto:info@lua.org
@@ -14,7 +14,7 @@ · 8 unmodified lines
1414 #include <stddef.h>
1515
1616
17−#define LUA_VERSION "Lua 5.0"
17+#define LUA_VERSION "Lua 5.0.1"
1818 #define LUA_COPYRIGHT "Copyright (C) 1994-2003 Tecgraf, PUC-Rio"
1919 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2020
src/ldo.c+19−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 1.217 2003/04/03 13:35:34 roberto Exp $
2+** $Id: ldo.c,v 1.217a 2003/04/03 13:35:34 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -322,11 +322,11 @@ static void resume (lua_State *L, void *ud) { · 316 unmodified lines
322322 int nargs = *cast(int *, ud);
323323 CallInfo *ci = L->ci;
324324 if (ci == L->base_ci) { /* no activation record? */
325− if (nargs >= L->top - L->base)
326− luaG_runerror(L, "cannot resume dead coroutine");
325+ lua_assert(nargs < L->top - L->base);
327326 luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */
328327 }
329− else if (ci->state & CI_YIELD) { /* inside a yield? */
328+ else { /* inside a yield */
329+ lua_assert(ci->state & CI_YIELD);
330330 if (ci->state & CI_C) { /* `common' yield? */
331331 /* finish interrupted execution of `OP_CALL' */
332332 int nresults;
@@ -341,18 +341,31 @@ static void resume (lua_State *L, void *ud) { · 8 unmodified lines
341341 ci->state &= ~CI_YIELD;
342342 }
343343 }
344− else
345− luaG_runerror(L, "cannot resume non-suspended coroutine");
346344 firstResult = luaV_execute(L);
347345 if (firstResult != NULL) /* return? */
348346 luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */
349347 }
350348
351349
350+static int resume_error (lua_State *L, const char *msg) {
351+ L->top = L->ci->base;
352+ setsvalue2s(L->top, luaS_new(L, msg));
353+ incr_top(L);
354+ lua_unlock(L);
355+ return LUA_ERRRUN;
356+}
357+
358+
352359 LUA_API int lua_resume (lua_State *L, int nargs) {
353360 int status;
354361 lu_byte old_allowhooks;
355362 lua_lock(L);
363+ if (L->ci == L->base_ci) {
364+ if (nargs >= L->top - L->base)
365+ return resume_error(L, "cannot resume dead coroutine");
366+ }
367+ else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */
368+ return resume_error(L, "cannot resume non-suspended coroutine");
356369 old_allowhooks = L->allowhook;
357370 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
358371 status = luaD_rawrunprotected(L, resume, &nargs);
src/lgc.c+14−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -110,7 +110,8 @@ static void marktmu (GCState *st) { · 104 unmodified lines
110110
111111
112112 /* move `dead' udata that need finalization to list `tmudata' */
113−void luaC_separateudata (lua_State *L) {
113+size_t luaC_separateudata (lua_State *L) {
114+ size_t deadmem = 0;
114115 GCObject **p = &G(L)->rootudata;
115116 GCObject *curr;
116117 GCObject *collected = NULL; /* to collect udata with gc event */
@@ -125,6 +126,7 @@ void luaC_separateudata (lua_State *L) { · 8 unmodified lines
125126 p = &curr->gch.next;
126127 }
127128 else { /* must call its gc method */
129+ deadmem += sizeudata(gcotou(curr)->uv.len);
128130 *p = curr->gch.next;
129131 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
130132 *lastcollected = curr;
@@ -134,6 +136,7 @@ void luaC_separateudata (lua_State *L) { · 3 unmodified lines
134136 /* insert collected udata with gc event into `tmudata' list */
135137 *lastcollected = G(L)->tmudata;
136138 G(L)->tmudata = collected;
139+ return deadmem;
137140 }
138141
139142
@@ -244,7 +247,7 @@ static void traversestack (GCState *st, lua_State *L1) { · 104 unmodified lines
244247 for (ci = L1->base_ci; ci <= L1->ci; ci++) {
245248 lua_assert(ci->top <= L1->stack_last);
246249 lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
247− if (!(ci->state & CI_C) && lim < ci->top)
250+ if (lim < ci->top)
248251 lim = ci->top;
249252 }
250253 for (o = L1->stack; o < L1->top; o++)
@@ -387,7 +390,7 @@ static void sweepstrings (lua_State *L, int all) { · 136 unmodified lines
387390 }
388391
389392
390−static void checkSizes (lua_State *L) {
393+static void checkSizes (lua_State *L, size_t deadmem) {
391394 /* check size of string hash */
392395 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
393396 G(L)->strt.size > MINSTRTABSIZE*2)
@@ -397,7 +400,7 @@ static void checkSizes (lua_State *L) { · 3 unmodified lines
397400 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
398401 luaZ_resizebuffer(L, &G(L)->buff, newsize);
399402 }
400− G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
403+ G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
401404 }
402405
403406
@@ -451,7 +454,8 @@ static void markroot (GCState *st, lua_State *L) { · 47 unmodified lines
451454 }
452455
453456
454−static void mark (lua_State *L) {
457+static size_t mark (lua_State *L) {
458+ size_t deadmem;
455459 GCState st;
456460 GCObject *wkv;
457461 st.g = G(L);
@@ -464,7 +468,7 @@ static void mark (lua_State *L) { · 6 unmodified lines
464468 wkv = st.wkv; /* keys must be cleared after preserving udata */
465469 st.wkv = NULL;
466470 st.wv = NULL;
467− luaC_separateudata(L); /* separate userdata to be preserved */
471+ deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
468472 marktmu(&st); /* mark `preserved' userdata */
469473 propagatemarks(&st); /* remark, to propagate `preserveness' */
470474 cleartablekeys(wkv);
@@ -473,13 +477,14 @@ static void mark (lua_State *L) { · 2 unmodified lines
473477 cleartablevalues(st.wv);
474478 cleartablekeys(st.wkv);
475479 cleartablevalues(st.wkv);
480+ return deadmem;
476481 }
477482
478483
479484 void luaC_collectgarbage (lua_State *L) {
480− mark(L);
485+ size_t deadmem = mark(L);
481486 luaC_sweep(L, 0);
482− checkSizes(L);
487+ checkSizes(L, deadmem);
483488 luaC_callGCTM(L);
484489 }
485490
src/lgc.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.h,v 1.19 2003/02/28 19:45:15 roberto Exp $
2+** $Id: lgc.h,v 1.19a 2003/02/28 19:45:15 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -15,7 +15,7 @@ · 9 unmodified lines
1515 if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }
1616
1717
18−void luaC_separateudata (lua_State *L);
18+size_t luaC_separateudata (lua_State *L);
1919 void luaC_callGCTM (lua_State *L);
2020 void luaC_sweep (lua_State *L, int all);
2121 void luaC_collectgarbage (lua_State *L);
src/lib/lbaselib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.130 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lbaselib.c,v 1.130a 2003/04/03 13:35:34 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -324,7 +324,7 @@ static int luaB_xpcall (lua_State *L) { · 318 unmodified lines
324324
325325
326326 static int luaB_tostring (lua_State *L) {
327− char buff[64];
327+ char buff[128];
328328 luaL_checkany(L, 1);
329329 if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
330330 return 1; /* use its value */
src/lib/liolib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.39 2003/03/19 21:16:12 roberto Exp $
2+** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -158,7 +158,7 @@ static int aux_close (lua_State *L) { · 152 unmodified lines
158158
159159
160160 static int io_close (lua_State *L) {
161− if (lua_isnone(L, 1)) {
161+ if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
162162 lua_pushstring(L, IO_OUTPUT);
163163 lua_rawget(L, lua_upvalueindex(1));
164164 }
@@ -175,7 +175,7 @@ static int io_gc (lua_State *L) { · 10 unmodified lines
175175
176176
177177 static int io_tostring (lua_State *L) {
178− char buff[32];
178+ char buff[128];
179179 FILE **f = topfile(L, 1);
180180 if (*f == NULL)
181181 strcpy(buff, "closed");
src/lparser.c+7−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lparser.c,v 1.208a 2003/04/03 13:35:34 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -1141,11 +1141,15 @@ static void ifstat (LexState *ls, int line) { · 1135 unmodified lines
11411141
11421142 static void localfunc (LexState *ls) {
11431143 expdesc v, b;
1144+ FuncState *fs = ls->fs;
11441145 new_localvar(ls, str_checkname(ls), 0);
1145− init_exp(&v, VLOCAL, ls->fs->freereg++);
1146+ init_exp(&v, VLOCAL, fs->freereg);
1147+ luaK_reserveregs(fs, 1);
11461148 adjustlocalvars(ls, 1);
11471149 body(ls, &b, 0, ls->linenumber);
1148− luaK_storevar(ls->fs, &v, &b);
1150+ luaK_storevar(fs, &v, &b);
1151+ /* debug information will only see the variable after this point! */
1152+ getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
11491153 }
11501154
11511155
src/luac/Makefile+1−1
@@ -13,7 +13,7 @@ T= $(BIN)/luac · 12 unmodified lines
1313 all: $T
1414
1515 $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
16− $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
16+ $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB)
1717
1818 # print.c needs opcode names from lopcodes.c
1919 lopcodes.o: ../lopcodes.c ../lopcodes.h
src/luac/luac.c+3−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luac.c,v 1.44 2003/04/07 20:34:20 lhf Exp $
2+** $Id: luac.c,v 1.44a 2003/04/07 20:34:20 lhf Exp $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -182,7 +182,9 @@ int main(int argc, char* argv[]) · 176 unmodified lines
182182 FILE* D=fopen(output,"wb");
183183 if (D==NULL) cannot(output,"open","out");
184184 if (stripping) strip(L,f);
185+ lua_lock(L);
185186 luaU_dump(L,f,writer,D);
187+ lua_unlock(L);
186188 if (ferror(D)) cannot(output,"write","out");
187189 fclose(D);
188190 }
src/lvm.c+4−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 1.284 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lvm.c,v 1.284a 2003/04/03 13:35:34 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -66,7 +66,7 @@ int luaV_tostring (lua_State *L, StkId obj) { · 60 unmodified lines
6666
6767 static void traceexec (lua_State *L) {
6868 lu_byte mask = L->hookmask;
69− if (mask > LUA_MASKLINE) { /* instruction-hook set? */
69+ if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
7070 if (L->hookcount == 0) {
7171 resethookcount(L);
7272 luaD_callhook(L, LUA_HOOKCOUNT, -1);
@@ -399,10 +399,10 @@ StkId luaV_execute (lua_State *L) { · 326 unmodified lines
399399 TObject *k;
400400 const Instruction *pc;
401401 callentry: /* entry point when calling new functions */
402− L->ci->u.l.pc = &pc;
403402 if (L->hookmask & LUA_MASKCALL)
404403 luaD_callhook(L, LUA_HOOKCALL, -1);
405404 retentry: /* entry point when returning to old functions */
405+ L->ci->u.l.pc = &pc;
406406 lua_assert(L->ci->state == CI_SAVEDPC ||
407407 L->ci->state == (CI_SAVEDPC | CI_CALLING));
408408 L->ci->state = CI_HASFRAME; /* activate frame */
@@ -673,9 +673,7 @@ StkId luaV_execute (lua_State *L) { · 264 unmodified lines
673673 }
674674 else { /* yes: continue its execution */
675675 int nresults;
676− lua_assert(ci->u.l.pc == &pc &&
677− ttisfunction(ci->base - 1) &&
678− (ci->state & CI_SAVEDPC));
676+ lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
679677 lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);
680678 nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;
681679 luaD_poscall(L, nresults, ra);
test/luac.lua+3−3
@@ -1,7 +1,7 @@
11 -- bare-bones luac in Lua
22 -- usage: lua luac.lua file.lua
33
4−assert(arg[1]~=nil,"usage: lua luac.lua file.lua")
5−f=assert(io.open("luac.out","w"))
6−f:write(string.dump(loadfile(arg[1])))
4+assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
5+f=assert(io.open("luac.out","wb"))
6+f:write(string.dump(assert(loadfile(arg[1]))))
77 io.close(f)