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 @@
1diff -r lua-5.0/doc/manual.html lua-5.0.1/doc/manual.html
25c5
3< <title>Lua 5.0 Reference Manual</title>
4---
5> <TITLE>Lua: 5.0 reference manual</TITLE>
612,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>
1222c20
13< &copy; 2003 TeCGraf, PUC-Rio. All rights reserved.
14---
15> &copy; 2003 Tecgraf, PUC-Rio. All rights reserved.
1632c30
17< <h1>1 - Introduction</h1>
18---
19> <a name="1"><h1>1 - Introduction</h1></a>
2037c35
21< It also offers good suport for object-oriented programming,
22---
23> It also offers good support for object-oriented programming,
2454c52
25< <p>The Lua distribuition includes a stand-alone embedding program,
26---
27> <p>The Lua distribution includes a stand-alone embedding program,
2890c88
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>
32108c106
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>
36125,126c123
37< repeat return then true until
38< while
39---
40> repeat return then true until while
41214c211
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>
45295c292
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>
49306c303
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>
53375c372
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>
57383c380
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>
61408c405
62< <p><h3>2.4.2 - Blocks</h3>
63---
64> <p><a name="2.4.2"><h3>2.4.2 - Blocks</h3></a>
65426c423
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>
69461c458
70< before it is assigned 4.
71---
72> before it is assigned&nbsp;4.
73488c485
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>
77519c516
78< skiping to the next statement after the loop:
79---
80> skipping to the next statement after the loop:
81539c536
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>
85626c623
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>
89635c632
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>
93652c649
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>
97683c680
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>
101698c695
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>
105734c731
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>
109767c764
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>
113774c771
114< <p><h3>2.5.5 - Precedence</h3>
115---
116> <p><a name="2.5.5"><h3>2.5.5 - Precedence</h3></a>
117787c784
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.
121792c789
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>
125842c839
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>
129947c944
130< return x, f(x) -- adicional results
131---
132> return x, f(x) -- additional results
133952c949
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>
1371061c1058
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>
1411118c1115
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>
1451133c1130
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>
1491315c1312
150< if type(op1) ~= type(op2) then -- diferent types?
151---
152> if type(op1) ~= type(op2) then -- different types?
1531443c1440
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>
1571474c1471
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>
1611506c1503
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>
1651524c1521
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;,
1691534c1531
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>
1731552c1549
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>,
1771633c1630
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>
1811648c1645
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>
1851684c1681
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>
1891694c1691
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>)
1931739c1736
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.
1971763c1760
198< <p><h2>3.3 - Stack Manipulation</h2>
199---
200> <p><a name="3.3"><h2>3.3 - Stack Manipulation</h2></a>
2011816c1813
202< <p><h2>3.4 - Querying the Stack</h2>
203---
204> <p><a name="3.4"><h2>3.4 - Querying the Stack</h2></a>
2051890c1887
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>
2091969c1966
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>
2131999,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);
2182028c2024
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
2222034c2030
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>
2262047c2043
227< int lua_getgccount (lua_State *L);
228---
229> int lua_getgccount (lua_State *L);
2302067c2063
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>
2342112c2108
235< <p><h2>3.9 - Metatables</h2>
236---
237> <p><a name="3.9"><h2>3.9 - Metatables</h2></a>
2382133c2129
239< <p><h2>3.10 - Loading Lua Chunks</h2>
240---
241> <p><a name="3.10"><h2>3.10 - Loading Lua Chunks</h2></a>
2422160c2156
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.
2462162c2158
247< it calls the reader,
248---
249> <code>lua_load</code> calls the reader,
2502182c2178
251< <p><h2>3.11 - Manipulating Tables</h2>
252---
253> <p><a name="3.11"><h2>3.11 - Manipulating Tables</h2></a>
2542263c2259
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>
2582295c2291
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>
2622312c2308
263< <p><h2>3.14 - Calling Functions</h2>
264---
265> <p><a name="3.14"><h2>3.14 - Calling Functions</h2></a>
2662367c2363
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>
2702414c2410
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>
2742482c2478
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>
2782517c2513
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>
2822535c2531
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>
2862542,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.
2922546c2542
293< Lua calls a <em>panic function</em>,
294---
295> Lua calls a <em>panic function</em>
2962553,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;
3022578c2574
303< Any value returned by <code>func</code> is dicarded.
304---
305> Any value returned by <code>func</code> is discarded.
3062590c2586
307< <p><h2>3.20 - Threads</h2>
308---
309> <p><a name="3.20"><h2>3.20 - Threads</h2></a>
3102611,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.
3212622c2615
322< int lua_yield (lua_State *L, int nresults);
323---
324> int lua_yield (lua_State *L, int nresults);
3252632c2625
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,
3292660c2653
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>
3332669c2662
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>
3372681c2674
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;
3412789c2782
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>
3452866c2859
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>
3492942c2935
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>
3532985c2978
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>
3573018c3011
358< Terminates the last protected function called,
359---
360> Terminates the last protected function called
3613046c3039
362< <p>if the environment has a <code>"__fenv"</code> field,
363---
364> <p>If the environment has a <code>"__fenv"</code> field,
3653151c3144
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;
3693155c3148
370< which is true if the call succeeds without errors.
371---
372> which is <B>true</B> if the call succeeds without errors.
3733330c3323
374< <p><h2>5.2 - Coroutine Manipulation</h2>
375---
376> <p><a name="5.2"><h2>5.2 - Coroutine Manipulation</h2></a>
3773333c3326
378< the basic library, and come inside the table .
379---
380> the basic library and come inside the table <code>coroutine</code>.
3813388c3381
382< <p><h2>5.3 - String Manipulation</h2>
383---
384> <p><a name="5.3"><h2>5.3 - String Manipulation</h2></a>
3853595c3588
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.
3893651c3644
390< a <em>pattern item</em> may be
391---
392> A <em>pattern item</em> may be
3933688c3681
394< a <em>pattern</em> is a sequence of pattern items.
395---
396> A <em>pattern</em> is a sequence of pattern items.
3973715c3708
398< <p><h2>5.4 - Table Manipulation</h2>
399---
400> <p><a name="5.4"><h2>5.4 - Table Manipulation</h2></a>
4013824c3817
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>
4053879c3872
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>
4094072c4065
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>
4134098c4091
414< <code>wday</code> (weekday, Sunday is 1),
415---
416> <code>wday</code> (weekday, Sunday is&nbsp;1),
4174187c4180
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>
4214323c4316
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>
4254462c4455
426< Vincent Penquerc'h,
427---
428> Vincent Penquerc'h.
4294583c4576
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
4334612c4605,4609
434< </body></html>
435---
436> <HR>
437> <SMALL>
438> Last update:
439> Tue Nov 25 16:08:37 BRST 2003
440> </SMALL>
4414613a4611,4612
442> </BODY>
443> </HTML>
444diff -r lua-5.0/include/lua.h lua-5.0.1/include/lua.h
4452c2
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 $
44917c17
450< #define LUA_VERSION "Lua 5.0"
451---
452> #define LUA_VERSION "Lua 5.0.1"
453diff -r lua-5.0/src/ldo.c lua-5.0.1/src/ldo.c
4542c2
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 $
458325,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);
463329c328,329
464< else if (ci->state & CI_YIELD) { /* inside a yield? */
465---
466> else { /* inside a yield */
467> lua_assert(ci->state & CI_YIELD);
468344,345d343
469< else
470< luaG_runerror(L, "cannot resume non-suspended coroutine");
471351a350,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>
481355a363,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");
488diff -r lua-5.0/src/lgc.c lua-5.0.1/src/lgc.c
4892c2
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 $
493113c113,114
494< void luaC_separateudata (lua_State *L) {
495---
496> size_t luaC_separateudata (lua_State *L) {
497> size_t deadmem = 0;
498127a129
499> deadmem += sizeudata(gcotou(curr)->uv.len);
500136a139
501> return deadmem;
502247c250
503< if (!(ci->state & CI_C) && lim < ci->top)
504---
505> if (lim < ci->top)
506390c393
507< static void checkSizes (lua_State *L) {
508---
509> static void checkSizes (lua_State *L, size_t deadmem) {
510400c403
511< G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
512---
513> G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
514454c457,458
515< static void mark (lua_State *L) {
516---
517> static size_t mark (lua_State *L) {
518> size_t deadmem;
519467c471
520< luaC_separateudata(L); /* separate userdata to be preserved */
521---
522> deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
523475a480
524> return deadmem;
525480c485
526< mark(L);
527---
528> size_t deadmem = mark(L);
529482c487
530< checkSizes(L);
531---
532> checkSizes(L, deadmem);
533diff -r lua-5.0/src/lgc.h lua-5.0.1/src/lgc.h
5342c2
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 $
53818c18
539< void luaC_separateudata (lua_State *L);
540---
541> size_t luaC_separateudata (lua_State *L);
542diff -r lua-5.0/src/lib/lbaselib.c lua-5.0.1/src/lib/lbaselib.c
5432c2
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 $
547327c327
548< char buff[64];
549---
550> char buff[128];
551diff -r lua-5.0/src/lib/liolib.c lua-5.0.1/src/lib/liolib.c
5522c2
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 $
556161c161
557< if (lua_isnone(L, 1)) {
558---
559> if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
560178c178
561< char buff[32];
562---
563> char buff[128];
564diff -r lua-5.0/src/lparser.c lua-5.0.1/src/lparser.c
5652c2
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 $
5691143a1144
570> FuncState *fs = ls->fs;
5711145c1146,1147
572< init_exp(&v, VLOCAL, ls->fs->freereg++);
573---
574> init_exp(&v, VLOCAL, fs->freereg);
575> luaK_reserveregs(fs, 1);
5761148c1150,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;
582diff -r lua-5.0/src/luac/Makefile lua-5.0.1/src/luac/Makefile
58316c16
584< $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
585---
586> $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB)
587diff -r lua-5.0/src/luac/luac.c lua-5.0.1/src/luac/luac.c
5882c2
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 $
592184a185
593> lua_lock(L);
594185a187
595> lua_unlock(L);
596diff -r lua-5.0/src/lvm.c lua-5.0.1/src/lvm.c
5972c2
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 $
60169c69
602< if (mask > LUA_MASKLINE) { /* instruction-hook set? */
603---
604> if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
605402d401
606< L->ci->u.l.pc = &pc;
607405a405
608> L->ci->u.l.pc = &pc;
609676,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));
615diff -r lua-5.0/test/luac.lua lua-5.0.1/test/luac.lua
6164,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 @@
1This is Lua 5.0.1, an update of Lua 5.0 that includes the following changes,
2which fix all known bugs in Lua 5.0.
3
4src/ldo.c
5 Attempt to resume running coroutine crashed Lua
6src/lgc.c
7 C functions also may have stacks larger than current top
8 Userdata to be collected still counted into new GC threshold
9src/lgc.h
10 Userdata to be collected still counted into new GC threshold
11src/lparser.c
12 Syntax `local function' did not increment stack size
13src/lvm.c
14 `pc' address was invalidated when a coroutine was suspended
15 Count hook might be called without being set
16src/lib/lbaselib.c
17 Buffer overflow for unusual %p representation
18src/lib/liolib.c
19 `file.close()' could not be called without arguments
20 Buffer overflow for unusual %p representation
21src/luac/luac.c
22 Missing lock/unlock
23
24To 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
2<html>2<html>
3 3
4<head>4<head>
5<title>Lua 5.0 Reference Manual</title>5<TITLE>Lua: 5.0 reference manual</TITLE>
6</head>6</head>
7 7
8<body BGCOLOR="#FFFFFF">8<body BGCOLOR="#FFFFFF">
9 9
10<hr>10<hr>
11<h1>11<h1>
12<a HREF="http://www.lua.org/home.html">12<A HREF="http://www.lua.org/home.html"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
13<img SRC="logo.gif" ALT="[Lua logo]" BORDER=0>
14</a>
15Lua 5.0 Reference Manual13Lua 5.0 Reference Manual
16</h1>14</h1>
17 15
@@ -19,7 +17,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line
19<p>17<p>
20<small>18<small>
21<a HREF="http://www.lua.org/copyright.html">Copyright</a>19<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.
23</small>21</small>
24<hr>22<hr>
25 23
@@ -29,12 +27,12 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 3 unmodified lines
29 27
30 28
31 29
32<h1>1 - Introduction</h1>30<a name="1"><h1>1 - Introduction</h1></a>
33 31
34<p>Lua is an extension programming language designed to support32<p>Lua is an extension programming language designed to support
35general procedural programming with data description33general procedural programming with data description
36facilities.34facilities.
37It also offers good suport for object-oriented programming,35It also offers good support for object-oriented programming,
38functional programming, and data-driven programming.36functional programming, and data-driven programming.
39Lua is intended to be used as a powerful, light-weight37Lua is intended to be used as a powerful, light-weight
40configuration language for any program that needs one.38configuration 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
51a wide range of different domains,49a wide range of different domains,
52thus creating customized programming languages sharing a syntactical framework.50thus creating customized programming languages sharing a syntactical framework.
53 51
54<p>The Lua distribuition includes a stand-alone embedding program,52<p>The Lua distribution includes a stand-alone embedding program,
55<code>lua</code>, that uses the Lua library to offer a complete Lua interpreter.53<code>lua</code>, that uses the Lua library to offer a complete Lua interpreter.
56 54
57<p>Lua is free software,55<p>Lua is free software,
@@ -87,7 +85,7 @@ The evolution of an extension language: a history of Lua, · 29 unmodified lines
87<p>Lua means "moon" in Portuguese and is pronounced LOO-ah.85<p>Lua means "moon" in Portuguese and is pronounced LOO-ah.
88 86
89<p>87<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>
91 89
92<p>This section describes the lexis, the syntax, and the semantics of Lua.90<p>This section describes the lexis, the syntax, and the semantics of Lua.
93In other words,91In other words,
@@ -105,7 +103,7 @@ keywords are shown in <b>bold</b>, · 11 unmodified lines
105and other terminal symbols are shown in <code>typewriter</code> font,103and other terminal symbols are shown in <code>typewriter</code> font,
106enclosed in single quotes.104enclosed in single quotes.
107 105
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>
109 107
110<p><em>Identifiers</em> in Lua can be any string of letters,108<p><em>Identifiers</em> in Lua can be any string of letters,
111digits, and underscores,109digits, and underscores,
@@ -122,8 +120,7 @@ and cannot be used as identifiers: · 10 unmodified lines
122 and break do else elseif120 and break do else elseif
123 end false for function if121 end false for function if
124 in local nil not or122 in local nil not or
125 repeat return then true until123 repeat return then true until while
126 while
127</PRE>124</PRE>
128 125
129<p>Lua is a case-sensitive language:126<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
211This facility allows the use of Lua as a script interpreter208This facility allows the use of Lua as a script interpreter
212in Unix systems (see <a href="#lua-sa">6</a>).209in Unix systems (see <a href="#lua-sa">6</a>).
213 210
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>
215 212
216<p>Lua is a <em>dynamically typed language</em>.213<p>Lua is a <em>dynamically typed language</em>.
217That means that214That means that
@@ -292,7 +289,7 @@ these operations do not imply any kind of copy. · 74 unmodified lines
292<p>The library function <code>type</code> returns a string describing the type289<p>The library function <code>type</code> returns a string describing the type
293of a given value (see <a href="#pdf-type">5.1</a>).290of a given value (see <a href="#pdf-type">5.1</a>).
294 291
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>
296 293
297<p>Lua provides automatic conversion between294<p>Lua provides automatic conversion between
298string and number values at run time.295string and number values at run time.
@@ -303,7 +300,7 @@ the number is converted to a string, in a reasonable format. · 4 unmodified lines
303For complete control of how numbers are converted to strings,300For complete control of how numbers are converted to strings,
304use the <code>format</code> function from the string library (see <a href="#format">5.3</a>).301use the <code>format</code> function from the string library (see <a href="#format">5.3</a>).
305 302
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>
307 304
308<p>Variables are places that store values.305<p>Variables are places that store values.
309 306
@@ -372,7 +369,7 @@ where <code>_env</code> is the environment of the running function. · 62 unmodified lines
372(The <code>_env</code> variable is not defined in Lua.369(The <code>_env</code> variable is not defined in Lua.
373We use it here only for explanatory purposes.)370We use it here only for explanatory purposes.)
374 371
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>
376 373
377<p>Lua supports an almost conventional set of statements,374<p>Lua supports an almost conventional set of statements,
378similar to those in Pascal or C.375similar to those in Pascal or C.
@@ -380,7 +377,7 @@ This set includes · 1 unmodified line
380assignment, control structures, procedure calls,377assignment, control structures, procedure calls,
381table constructors, and variable declarations.378table constructors, and variable declarations.
382 379
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>
384 381
385<p>The unit of execution of Lua is called a <em>chunk</em>.382<p>The unit of execution of Lua is called a <em>chunk</em>.
386A chunk is simply a sequence of statements,383A chunk is simply a sequence of statements,
@@ -405,7 +402,7 @@ Programs in source and compiled forms are interchangeable; · 18 unmodified lines
405Lua automatically detects the file type and acts accordingly.402Lua automatically detects the file type and acts accordingly.
406 403
407 404
408<p><h3>2.4.2 - Blocks</h3>405<p><a name="2.4.2"><h3>2.4.2 - Blocks</h3></a>
409A block is a list of statements;406A block is a list of statements;
410syntactically, a block is equal to a chunk:407syntactically, a block is equal to a chunk:
411<pre>408<pre>
@@ -423,7 +420,7 @@ add a <b>return</b> or <b>break</b> statement in the middle · 11 unmodified lines
423of another block (see <a href="#control">2.4.4</a>).420of another block (see <a href="#control">2.4.4</a>).
424 421
425 422
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>
427 424
428<p>Lua allows multiple assignment.425<p>Lua allows multiple assignment.
429Therefore, the syntax for assignment426Therefore, the syntax for assignment
@@ -458,7 +455,7 @@ Thus the code · 28 unmodified lines
458</PRE>455</PRE>
459sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>456sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
460because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)457because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
461before it is assigned 4.458before it is assigned&nbsp;4.
462Similarly, the line459Similarly, the line
463<PRE>460<PRE>
464 x, y = y, x461 x, y = y, x
@@ -485,7 +482,7 @@ where <code>_env</code> is the environment of the running function. · 20 unmodified lines
485(The <code>_env</code> variable is not defined in Lua.482(The <code>_env</code> variable is not defined in Lua.
486We use it here only for explanatory purposes.)483We use it here only for explanatory purposes.)
487 484
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>
489The control structures486The control structures
490<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and487<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and
491familiar syntax:488familiar syntax:
@@ -516,7 +513,7 @@ so the syntax for the <b>return</b> statement is · 24 unmodified lines
516 513
517<p>The <b>break</b> statement can be used to terminate the execution of a514<p>The <b>break</b> statement can be used to terminate the execution of a
518<b>while</b>, <b>repeat</b>, or <b>for</b> loop,515<b>while</b>, <b>repeat</b>, or <b>for</b> loop,
519skiping to the next statement after the loop:516skipping to the next statement after the loop:
520 517
521<pre>518<pre>
522 stat ::= <b>break</b>519 stat ::= <b>break</b>
@@ -536,7 +533,7 @@ their (inner) blocks. · 13 unmodified lines
536In practice,533In practice,
537those idioms are only used during debugging.534those idioms are only used during debugging.
538 535
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>
540 537
541<p>The <b>for</b> statement has two forms:538<p>The <b>for</b> statement has two forms:
542one numeric and one generic.539one numeric and one generic.
@@ -623,7 +620,7 @@ If you need these values, · 80 unmodified lines
623then assign them to other variables before breaking or exiting the loop.620then assign them to other variables before breaking or exiting the loop.
624</ul>621</ul>
625 622
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>
627To allow possible side-effects,624To allow possible side-effects,
628function calls can be executed as statements:625function calls can be executed as statements:
629<pre>626<pre>
@@ -632,7 +629,7 @@ function calls can be executed as statements: · 2 unmodified lines
632In this case, all returned values are thrown away.629In this case, all returned values are thrown away.
633Function calls are explained in <a href="#functioncall">2.5.7</a>.630Function calls are explained in <a href="#functioncall">2.5.7</a>.
634 631
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>
636Local variables may be declared anywhere inside a block.633Local variables may be declared anywhere inside a block.
637The declaration may include an initial assignment:634The declaration may include an initial assignment:
638<pre>635<pre>
@@ -649,7 +646,7 @@ Such local variables die when the chunk ends. · 10 unmodified lines
649 646
650<p>The visibility rules for local variables are explained in <a href="#visibility">2.6</a>.647<p>The visibility rules for local variables are explained in <a href="#visibility">2.6</a>.
651 648
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>
653 650
654<p>651<p>
655The basic expressions in Lua are the following:652The 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
680<p>Expressions can also be built with arithmetic operators, relational operators,677<p>Expressions can also be built with arithmetic operators, relational operators,
681and logical operators, all of which are explained below.678and logical operators, all of which are explained below.
682 679
683<p><h3>2.5.1 - Arithmetic Operators</h3>680<p><a name="2.5.1"><h3>2.5.1 - Arithmetic Operators</h3></a>
684Lua supports the usual arithmetic operators:681Lua supports the usual arithmetic operators:
685the binary <code>+</code> (addition),682the binary <code>+</code> (addition),
686<code>-</code> (subtraction), <code>*</code> (multiplication),683<code>-</code> (subtraction), <code>*</code> (multiplication),
@@ -695,7 +692,7 @@ The standard mathematical library defines function <code>__pow</code>, · 8 unmodified lines
695giving the expected meaning to exponentiation692giving the expected meaning to exponentiation
696(see <a href="#mathlib">5.5</a>).693(see <a href="#mathlib">5.5</a>).
697 694
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>
699The relational operators in Lua are696The relational operators in Lua are
700<PRE>697<PRE>
701 == ~= &#060; > &#060;= >=698 == ~= &#060; > &#060;= >=
@@ -731,7 +728,7 @@ then their values are compared according to the current locale. · 29 unmodified lines
731Otherwise, Lua tries to call the "lt" or the "le"728Otherwise, Lua tries to call the "lt" or the "le"
732metamethod (see <a href="#metatable">2.8</a>).729metamethod (see <a href="#metatable">2.8</a>).
733 730
734<p><h3>2.5.3 - Logical Operators</h3>731<p><a name="2.5.3"><h3>2.5.3 - Logical Operators</h3></a>
735The logical operators in Lua are732The logical operators in Lua are
736 733
737<PRE>734<PRE>
@@ -764,14 +761,14 @@ For example, · 26 unmodified lines
764 10 and 20 -> 20761 10 and 20 -> 20
765</PRE>762</PRE>
766 763
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>
768The string concatenation operator in Lua is765The string concatenation operator in Lua is
769denoted by two dots (`<code>..</code>&acute;).766denoted by two dots (`<code>..</code>&acute;).
770If both operands are strings or numbers, then they are converted to767If both operands are strings or numbers, then they are converted to
771strings according to the rules mentioned in <a href="#coercion">2.2.1</a>.768strings according to the rules mentioned in <a href="#coercion">2.2.1</a>.
772Otherwise, the "concat" metamethod is called (see <a href="#metatable">2.8</a>).769Otherwise, the "concat" metamethod is called (see <a href="#metatable">2.8</a>).
773 770
774<p><h3>2.5.5 - Precedence</h3>771<p><a name="2.5.5"><h3>2.5.5 - Precedence</h3></a>
775Operator precedence in Lua follows the table below,772Operator precedence in Lua follows the table below,
776from lower to higher priority:773from lower to higher priority:
777<PRE>774<PRE>
@@ -784,12 +781,12 @@ from lower to higher priority: · 6 unmodified lines
784 not - (unary)781 not - (unary)
785 ^782 ^
786</PRE>783</PRE>
787As usual, you can use parentheses to change the precedences of an expression.784You can use parentheses to change the precedences in an expression.
788The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)785The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)
789operators are right associative.786operators are right associative.
790All other binary operators are left associative.787All other binary operators are left associative.
791 788
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>
793Table constructors are expressions that create tables.790Table constructors are expressions that create tables.
794Every time a constructor is evaluated, a new table is created.791Every time a constructor is evaluated, a new table is created.
795Constructors can be used to create empty tables,792Constructors 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
839<p>The field list may have an optional trailing separator,836<p>The field list may have an optional trailing separator,
840as a convenience for machine-generated code.837as a convenience for machine-generated code.
841 838
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>
843A function call in Lua has the following syntax:840A function call in Lua has the following syntax:
844<pre>841<pre>
845 functioncall ::= prefixexp args842 functioncall ::= prefixexp args
@@ -944,12 +941,12 @@ So, all the following examples are not tails calls: · 98 unmodified lines
944<PRE>941<PRE>
945 return (f(x)) -- results adjusted to 1942 return (f(x)) -- results adjusted to 1
946 return 2 * f(x)943 return 2 * f(x)
947 return x, f(x) -- adicional results944 return x, f(x) -- additional results
948 f(x); return -- results discarded945 f(x); return -- results discarded
949 return x or f(x) -- results adjusted to 1946 return x or f(x) -- results adjusted to 1
950</PRE>947</PRE>
951 948
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>
953 950
954<p>The syntax for function definition is951<p>The syntax for function definition is
955<pre>952<pre>
@@ -1058,7 +1055,7 @@ is syntactic sugar for · 102 unmodified lines
1058 t.a.b.c.f = function (self, ...) ... end1055 t.a.b.c.f = function (self, ...) ... end
1059</PRE>1056</PRE>
1060 1057
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>
1062 1059
1063 1060
1064<p>Lua is a lexically scoped language.1061<p>Lua is a lexically scoped language.
@@ -1115,7 +1112,7 @@ The loop creates ten closures · 50 unmodified lines
1115Each of these closures uses a different <code>y</code> variable,1112Each of these closures uses a different <code>y</code> variable,
1116while all of them share the same <code>x</code>.1113while all of them share the same <code>x</code>.
1117 1114
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>
1119 1116
1120<p>Because Lua is an extension language,1117<p>Because Lua is an extension language,
1121all Lua actions start from C&nbsp;code in the host program1118all Lua actions start from C&nbsp;code in the host program
@@ -1130,7 +1127,7 @@ which can take appropriate measures · 8 unmodified lines
1130If you need to catch errors in Lua,1127If you need to catch errors in Lua,
1131you can use the <code>pcall</code> function (see <a href="#pdf-pcall">5.1</a>).1128you can use the <code>pcall</code> function (see <a href="#pdf-pcall">5.1</a>).
1132 1129
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>
1134 1131
1135<p>Every table and userdata object in Lua may have a <em>metatable</em>.1132<p>Every table and userdata object in Lua may have a <em>metatable</em>.
1136This <em>metatable</em> is an ordinary Lua table1133This <em>metatable</em> is an ordinary Lua table
@@ -1312,7 +1309,7 @@ and the same metamethod for the selected operation. · 175 unmodified lines
1312The "eq" event is defined as follows:1309The "eq" event is defined as follows:
1313<PRE>1310<PRE>
1314 function eq_event (op1, op2)1311 function eq_event (op1, op2)
1315 if type(op1) ~= type(op2) then -- diferent types?1312 if type(op1) ~= type(op2) then -- different types?
1316 return false -- different objects1313 return false -- different objects
1317 end1314 end
1318 if op1 == op2 then -- primitive equal?1315 if op1 == op2 then -- primitive equal?
@@ -1440,7 +1437,7 @@ called when Lua calls a value. · 121 unmodified lines
1440 1437
1441<p></ul>1438<p></ul>
1442 1439
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>
1444 1441
1445<p>Lua does automatic memory management.1442<p>Lua does automatic memory management.
1446That means that1443That means that
@@ -1471,7 +1468,7 @@ Using Lua code you have a more limited control over garbage-collection cycles, · 24 unmodified lines
1471through the <code>gcinfo</code> and <code>collectgarbage</code> functions1468through the <code>gcinfo</code> and <code>collectgarbage</code> functions
1472(see <a href="#predefined">5.1</a>).1469(see <a href="#predefined">5.1</a>).
1473 1470
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>
1475 1472
1476<p>Using the C&nbsp;API,1473<p>Using the C&nbsp;API,
1477you can set garbage-collector metamethods for userdata (see <a href="#metatable">2.8</a>).1474you 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
1503That is, the first finalizer to be called is the one associated1500That is, the first finalizer to be called is the one associated
1504with the userdata created last in the program.1501with the userdata created last in the program.
1505 1502
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>
1507 1504
1508<p>A <em>weak table</em> is a table whose elements are1505<p>A <em>weak table</em> is a table whose elements are
1509<em>weak references</em>.1506<em>weak references</em>.
@@ -1521,7 +1518,7 @@ In any case, if either the key or the value is collected, · 11 unmodified lines
1521the whole pair is removed from the table.1518the whole pair is removed from the table.
1522The weakness of a table is controlled by the value of the1519The weakness of a table is controlled by the value of the
1523<code>__mode</code> field of its metatable.1520<code>__mode</code> field of its metatable.
1524If the <code>__mode</code> field is a string containing the character `<code>k</code>&acute;,1521If the <code>__mode</code> field is a string containing the character&nbsp;`<code>k</code>&acute;,
1525the keys in the table are weak.1522the keys in the table are weak.
1526If <code>__mode</code> contains `<code>v</code>&acute;,1523If <code>__mode</code> contains `<code>v</code>&acute;,
1527the values in the table are weak.1524the 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
1531Otherwise, the weak behavior of the tables controlled by this1528Otherwise, the weak behavior of the tables controlled by this
1532metatable is undefined.1529metatable is undefined.
1533 1530
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>
1535 1532
1536<p>Lua supports coroutines,1533<p>Lua supports coroutines,
1537also called <em>semi-coroutines</em>1534also called <em>semi-coroutines</em>
@@ -1549,7 +1546,7 @@ returns a handle to it (an object of type <em>thread</em>); · 11 unmodified lines
1549it does not start the coroutine execution.1546it does not start the coroutine execution.
1550 1547
1551<p>When you first call <code>coroutine.resume</code>,1548<p>When you first call <code>coroutine.resume</code>,
1552passing as argument the thread returned by <code>coroutine.create</code>,1549passing as its first argument the thread returned by <code>coroutine.create</code>,
1553the coroutine starts its execution,1550the coroutine starts its execution,
1554at the first line of its main function.1551at the first line of its main function.
1555Extra arguments passed to <code>coroutine.resume</code> are given as1552Extra arguments passed to <code>coroutine.resume</code> are given as
@@ -1630,7 +1627,7 @@ main false cannot resume dead coroutine · 74 unmodified lines
1630</PRE>1627</PRE>
1631 1628
1632<p>1629<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>
1634 1631
1635 1632
1636<p>This section describes the C API for Lua, that is,1633<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
1645(except for the first argument, which is always a Lua state),1642(except for the first argument, which is always a Lua state),
1646and so do not generate hidden side-effects.1643and so do not generate hidden side-effects.
1647 1644
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>
1649 1646
1650<p>The Lua library is fully reentrant:1647<p>The Lua library is fully reentrant:
1651it has no global variables.1648it has no global variables.
@@ -1681,7 +1678,7 @@ such as a daemon or a web server, · 29 unmodified lines
1681might need to release states as soon as they are not needed,1678might need to release states as soon as they are not needed,
1682to avoid growing too large.1679to avoid growing too large.
1683 1680
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>
1685 1682
1686<p>Lua uses a <em>virtual stack</em> to pass values to and from C.1683<p>Lua uses a <em>virtual stack</em> to pass values to and from C.
1687Each element in this stack represents a Lua value1684Each element in this stack represents a Lua value
@@ -1691,7 +1688,7 @@ Each element in this stack represents a Lua value · 3 unmodified lines
1691which is independent of previous stacks and of stacks of1688which is independent of previous stacks and of stacks of
1692C functions that are still active.1689C functions that are still active.
1693That stack initially contains any arguments to the C function,1690That stack initially contains any arguments to the C function,
1694and it is where the C function pushes its results (see <a href="#LuacallC">3.16</a>)1691and it is where the C function pushes its results to be returned to the caller (see <a href="#LuacallC">3.16</a>)
1695to be returned to the caller.1692to be returned to the caller.
1696 1693
1697<p>For convenience,1694<p>For convenience,
@@ -1736,7 +1733,7 @@ if the stack is already larger than the new size, · 38 unmodified lines
1736it is left unchanged.1733it is left unchanged.
1737 1734
1738<p>Whenever Lua calls C, 1735<p>Whenever Lua calls C,
1739it ensures that at least <code>LUA_MINSTACK</code> positions are available.1736it ensures that at least <code>LUA_MINSTACK</code> stack positions are available.
1740<code>LUA_MINSTACK</code> is defined in <code>lua.h</code> as 20,1737<code>LUA_MINSTACK</code> is defined in <code>lua.h</code> as 20,
1741so that usually you do not have to worry about stack space1738so that usually you do not have to worry about stack space
1742unless your code has loops pushing elements onto the stack.1739unless your code has loops pushing elements onto the stack.
@@ -1760,7 +1757,7 @@ but are not in the stack. · 17 unmodified lines
1760Pseudo-indices are used to access the global environment,1757Pseudo-indices are used to access the global environment,
1761the registry, and the upvalues of a C&nbsp;function (see <a href="#c-closure">3.17</a>).1758the registry, and the upvalues of a C&nbsp;function (see <a href="#c-closure">3.17</a>).
1762 1759
1763<p><h2>3.3 - Stack Manipulation</h2>1760<p><a name="3.3"><h2>3.3 - Stack Manipulation</h2></a>
1764The API offers the following functions for basic stack manipulation:1761The API offers the following functions for basic stack manipulation:
1765<PRE>1762<PRE>
1766 void lua_settop (lua_State *L, int index);1763 void lua_settop (lua_State *L, int index);
@@ -1813,7 +1810,7 @@ then · 46 unmodified lines
1813 lua_settop(L, 6) --> 30 40 nil nil nil nil*1810 lua_settop(L, 6) --> 30 40 nil nil nil nil*
1814</PRE>1811</PRE>
1815 1812
1816<p><h2>3.4 - Querying the Stack</h2>1813<p><a name="3.4"><h2>3.4 - Querying the Stack</h2></a>
1817 1814
1818<p>To check the type of a stack element,1815<p>To check the type of a stack element,
1819the following functions are available:1816the 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
1887without metamethods.1884without metamethods.
1888These functions return 0 (false) if any of the indices are non-valid.1885These functions return 0 (false) if any of the indices are non-valid.
1889 1886
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>
1891 1888
1892<p>To translate a value in the stack to a specific C&nbsp;type,1889<p>To translate a value in the stack to a specific C&nbsp;type,
1893you can use the following conversion functions:1890you can use the following conversion functions:
@@ -1966,7 +1963,7 @@ Typically this function is used for debug information. · 72 unmodified lines
1966 1963
1967<p><code>lua_touserdata</code> is explained in <a href="#userdata">3.8</a>.1964<p><code>lua_touserdata</code> is explained in <a href="#userdata">3.8</a>.
1968 1965
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>
1970 1967
1971<p>The API has the following functions to1968<p>The API has the following functions to
1972push C&nbsp;values onto the stack:1969push C&nbsp;values onto the stack:
@@ -1996,8 +1993,7 @@ which accepts an explicit size. · 23 unmodified lines
1996<p>You can also push "formatted" strings:1993<p>You can also push "formatted" strings:
1997<PRE>1994<PRE>
1998 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);1995 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
1999 const char *lua_pushvfstring (lua_State *L, const char *fmt,1996 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
2000 va_list argp);
2001</PRE>1997</PRE>
2002 1998
2003These functions push onto the stack a formatted string1999These functions push onto the stack a formatted string
@@ -2025,13 +2021,13 @@ The conversion specifiers can be simply · 21 unmodified lines
2025 2021
2026concatenates the <code>n</code> values at the top of the stack,2022concatenates the <code>n</code> values at the top of the stack,
2027pops them, and leaves the result at the top.2023pops them, and leaves the result at the top.
2028If <code>n</code> is 1, the result is that single string2024If <code>n</code>&nbsp;is&nbsp;1, the result is that single string
2029(that is, the function does nothing);2025(that is, the function does nothing);
2030if <code>n</code> is 0, the result is the empty string.2026if <code>n</code> is 0, the result is the empty string.
2031Concatenation is done following the usual semantics of Lua2027Concatenation is done following the usual semantics of Lua
2032(see <a href="#concat">2.5.4</a>).2028(see <a href="#concat">2.5.4</a>).
2033 2029
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>
2035 2031
2036<p>Lua uses two numbers to control its garbage collection:2032<p>Lua uses two numbers to control its garbage collection:
2037the <em>count</em> and the <em>threshold</em> (see <a href="#GC">2.9</a>).2033the <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
2044<p>You can access the current values of these two numbers through the2040<p>You can access the current values of these two numbers through the
2045following functions:2041following functions:
2046<PRE>2042<PRE>
2047 int lua_getgccount (lua_State *L);2043 int lua_getgccount (lua_State *L);
2048 int lua_getgcthreshold (lua_State *L);2044 int lua_getgcthreshold (lua_State *L);
2049</PRE>2045</PRE>
2050 2046
@@ -2064,7 +2060,7 @@ In particular · 13 unmodified lines
2064After the collection,2060After the collection,
2065a new threshold is set according to the previous rule.2061a new threshold is set according to the previous rule.
2066 2062
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>
2068 2064
2069<p>Userdata represents C values in Lua.2065<p>Userdata represents C values in Lua.
2070Lua supports two types of userdata:2066Lua supports two types of userdata:
@@ -2109,7 +2105,7 @@ when applied on a non-userdata value, it returns <code>NULL</code>. · 38 unmodified lines
2109it calls the userdata's <code>gc</code> metamethod, if any,2105it calls the userdata's <code>gc</code> metamethod, if any,
2110and then it frees the userdata's corresponding memory.2106and then it frees the userdata's corresponding memory.
2111 2107
2112<p><h2>3.9 - Metatables</h2>2108<p><a name="3.9"><h2>3.9 - Metatables</h2></a>
2113 2109
2114<p>The following functions allow you to manipulate the metatables2110<p>The following functions allow you to manipulate the metatables
2115of an object:2111of an object:
@@ -2130,7 +2126,7 @@ set the metatable of the given object · 14 unmodified lines
2130(that is, when the object is neither a userdata nor a table);2126(that is, when the object is neither a userdata nor a table);
2131even then it pops the table from the stack.2127even then it pops the table from the stack.
2132 2128
2133<p><h2>3.10 - Loading Lua Chunks</h2>2129<p><a name="3.10"><h2>3.10 - Loading Lua Chunks</h2></a>
2134 2130
2135<p>You can load a Lua chunk with <code>lua_load</code>:2131<p>You can load a Lua chunk with <code>lua_load</code>:
2136<PRE>2132<PRE>
@@ -2157,9 +2153,9 @@ Otherwise, it pushes an error message. · 20 unmodified lines
2157<p><code>lua_load</code> automatically detects whether the chunk is text or binary,2153<p><code>lua_load</code> automatically detects whether the chunk is text or binary,
2158and loads it accordingly (see program <code>luac</code>).2154and loads it accordingly (see program <code>luac</code>).
2159 2155
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.
2161Everytime it needs another piece of the chunk,2157Everytime it needs another piece of the chunk,
2162it calls the reader,2158<code>lua_load</code> calls the reader,
2163passing along its <code>data</code> parameter.2159passing along its <code>data</code> parameter.
2164The reader must return a pointer to a block of memory2160The reader must return a pointer to a block of memory
2165with a new piece of the chunk2161with a new piece of the chunk
@@ -2179,7 +2175,7 @@ for examples of how to use <code>lua_load</code> · 13 unmodified lines
2179and for some ready-to-use functions to load chunks2175and for some ready-to-use functions to load chunks
2180from files and strings.2176from files and strings.
2181 2177
2182<p><h2>3.11 - Manipulating Tables</h2>2178<p><a name="3.11"><h2>3.11 - Manipulating Tables</h2></a>
2183 2179
2184<p>Tables are created by calling2180<p>Tables are created by calling
2185the function2181the function
@@ -2260,7 +2256,7 @@ unless you know that the key is actually a string. · 74 unmodified lines
2260Recall that <code>lua_tostring</code> <em>changes</em> the value at the given index;2256Recall that <code>lua_tostring</code> <em>changes</em> the value at the given index;
2261this confuses the next call to <code>lua_next</code>.2257this confuses the next call to <code>lua_next</code>.
2262 2258
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>
2264 2260
2265<p>All global variables are kept in ordinary Lua tables,2261<p>All global variables are kept in ordinary Lua tables,
2266called environments.2262called environments.
@@ -2292,7 +2288,7 @@ the new environment for the function at index <code>index</code> in the stack. · 25 unmodified lines
2292If the object at the given index is not a Lua function,2288If the object at the given index is not a Lua function,
2293<code>lua_setfenv</code> returns 0.2289<code>lua_setfenv</code> returns 0.
2294 2290
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>
2296The API has functions that help to use Lua tables as arrays,2292The API has functions that help to use Lua tables as arrays,
2297that is,2293that is,
2298tables indexed by numbers only:2294tables indexed by numbers only:
@@ -2309,7 +2305,7 @@ at stack position <code>index</code>. · 10 unmodified lines
2309at stack position <code>index</code> to the value at the top of the stack,2305at stack position <code>index</code> to the value at the top of the stack,
2310removing this value from the stack.2306removing this value from the stack.
2311 2307
2312<p><h2>3.14 - Calling Functions</h2>2308<p><a name="3.14"><h2>3.14 - Calling Functions</h2></a>
2313 2309
2314<p>Functions defined in Lua2310<p>Functions defined in Lua
2315and C&nbsp;functions registered in Lua2311and C&nbsp;functions registered in Lua
@@ -2364,7 +2360,7 @@ Usually programmers define and use several macros and auxiliary functions · 48 unmodified lines
2364that provide higher level access to Lua.2360that provide higher level access to Lua.
2365See the source code of the standard libraries for examples.)2361See the source code of the standard libraries for examples.)
2366 2362
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>
2368 2364
2369<p>When you call a function with <code>lua_call</code>,2365<p>When you call a function with <code>lua_call</code>,
2370any error inside the called function is propagated upwards2366any 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
2411error while running the error handler function.2407error while running the error handler function.
2412</ul>2408</ul>
2413 2409
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>
2415 2411
2416<p>Lua can be extended with functions written in&nbsp;C.2412<p>Lua can be extended with functions written in&nbsp;C.
2417These functions must be of type <code>lua_CFunction</code>,2413These 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
2479 lua_register(L, "average", foo);2475 lua_register(L, "average", foo);
2480</PRE>2476</PRE>
2481 2477
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>
2483 2479
2484<p>When a C&nbsp;function is created,2480<p>When a C&nbsp;function is created,
2485it is possible to associate some values with it,2481it is possible to associate some values with it,
@@ -2514,7 +2510,7 @@ produces an acceptable (but invalid) index. · 28 unmodified lines
2514see the standard libraries in the official Lua distribution2510see the standard libraries in the official Lua distribution
2515(<code>src/lib/*.c</code>).2511(<code>src/lib/*.c</code>).
2516 2512
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>
2518 2514
2519<p>Lua provides a registry,2515<p>Lua provides a registry,
2520a pre-defined table that can be used by any C&nbsp;code to2516a 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
2532implemented by the auxiliary library,2528implemented by the auxiliary library,
2533and therefore should not be used by other purposes.2529and therefore should not be used by other purposes.
2534 2530
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>
2536 2532
2537<p>Internally, Lua uses the C <code>longjmp</code> facility to handle errors.2533<p>Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
2538When Lua faces any error2534When Lua faces any error
2539(such as memory allocation errors, type errors, syntax errors)2535(such as memory allocation errors, type errors, syntax errors)
2540it <em>raises</em> an error, that is, it does a long jump.2536it <em>raises</em> an error, that is, it does a long jump.
2541A <em>protected environment</em> uses <code>setjmp</code>2537A <em>protected environment</em> uses <code>setjmp</code>
2542to set a recover point,2538to set a recover point;
2543and any error jumps to the most recent active recover point.2539any error jumps to the most recent active recover point.
2544 2540
2545<p>If an error happens outside any protected environment,2541<p>If an error happens outside any protected environment,
2546Lua calls a <em>panic function</em>,2542Lua calls a <em>panic function</em>
2547and then calls <code>exit(EXIT_FAILURE)</code>.2543and then calls <code>exit(EXIT_FAILURE)</code>.
2548You can change the panic function with2544You can change the panic function with
2549<PRE>2545<PRE>
2550 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);2546 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
2551</PRE>2547</PRE>
2552Your new panic function may avoid the application exit by2548Your new panic function may avoid the application exit by
2553never returning (e.g. doing a long jump).2549never returning (e.g., by doing a long jump).
2554Nevertheless, the corresponding Lua will not be consistent;2550Nevertheless, the corresponding Lua state will not be consistent;
2555the only safe operation with it is to close it.2551the only safe operation with it is to close it.
2556 2552
2557<p>Almost any function in the API may raise an error,2553<p>Almost any function in the API may raise an error,
@@ -2575,7 +2571,7 @@ In case of errors, · 17 unmodified lines
2575(see <a href="#lua_pcall">3.15</a>),2571(see <a href="#lua_pcall">3.15</a>),
2576plus the error object on the top of the stack;2572plus the error object on the top of the stack;
2577otherwise, it returns zero, and does not change the stack.2573otherwise, it returns zero, and does not change the stack.
2578Any value returned by <code>func</code> is dicarded.2574Any value returned by <code>func</code> is discarded.
2579 2575
2580<p>C code can generate a Lua error calling the function2576<p>C code can generate a Lua error calling the function
2581<PRE>2577<PRE>
@@ -2587,7 +2583,7 @@ must be on the stack top. · 5 unmodified lines
2587This function does a long jump,2583This function does a long jump,
2588and therefore never returns.2584and therefore never returns.
2589 2585
2590<p><h2>3.20 - Threads</h2>2586<p><a name="3.20"><h2>3.20 - Threads</h2></a>
2591 2587
2592<p>Lua offers partial support for multiple threads of execution.2588<p>Lua offers partial support for multiple threads of execution.
2593If you have a C&nbsp;library that offers multi-threading, 2589If you have a C&nbsp;library that offers multi-threading,
@@ -2608,18 +2604,15 @@ but has an independent run-time stack. · 14 unmodified lines
2608When you create a thread, this table is the same as that of the given state,2604When you create a thread, this table is the same as that of the given state,
2609but you can change each one independently.2605but you can change each one independently.
2610 2606
2611<p>You destroy threads with <code>lua_closethread</code>:2607<p>There is no explicit function to close or to destroy a thread.
2612<PRE>2608Threads are subject to garbage collection,
2613 void lua_closethread (lua_State *L, lua_State *thread);2609like any Lua object.
2614</PRE>
2615You cannot close the sole (or last) thread of a state.
2616Instead, you must close the state itself.
2617 2610
2618<p>To manipulate threads as coroutines,2611<p>To manipulate threads as coroutines,
2619Lua offers the following functions:2612Lua offers the following functions:
2620<PRE>2613<PRE>
2621 int lua_resume (lua_State *L, int narg);2614 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);
2623</PRE>2616</PRE>
2624 2617
2625To start a coroutine, you first create a new thread;2618To 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
2629This call returns when the coroutine suspends or finishes its execution.2622This call returns when the coroutine suspends or finishes its execution.
2630When it returns, the stack contains all values passed to <code>lua_yield</code>,2623When it returns, the stack contains all values passed to <code>lua_yield</code>,
2631or all values returned by the body function.2624or 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,
2633or an error code (see <a href="#lua_pcall">3.15</a>).2626or an error code (see <a href="#lua_pcall">3.15</a>).
2634In case of errors,2627In case of errors,
2635the stack contains only the error message.2628the 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
2657and puhses them into the stack <code>to</code>.2650and puhses them into the stack <code>to</code>.
2658 2651
2659<p>2652<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>
2661 2654
2662<p>Lua has no built-in debugging facilities.2655<p>Lua has no built-in debugging facilities.
2663Instead, it offers a special interface2656Instead, it offers a special interface
@@ -2666,7 +2659,7 @@ This interface allows the construction of different · 2 unmodified lines
2666kinds of debuggers, profilers, and other tools2659kinds of debuggers, profilers, and other tools
2667that need "inside information" from the interpreter.2660that need "inside information" from the interpreter.
2668 2661
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>
2670 2663
2671<p>The main function to get information about the interpreter runtime stack is2664<p>The main function to get information about the interpreter runtime stack is
2672<PRE>2665<PRE>
@@ -2678,7 +2671,7 @@ an identification of the <em>activation record</em> · 5 unmodified lines
2678of the function executing at a given level.2671of the function executing at a given level.
2679Level&nbsp;0 is the current running function,2672Level&nbsp;0 is the current running function,
2680whereas level <em>n+1</em> is the function that has called level <em>n</em>.2673whereas level <em>n+1</em> is the function that has called level <em>n</em>.
2681When there is no errors, <code>lua_getstack</code> returns 1;2674When there are no errors, <code>lua_getstack</code> returns 1;
2682when called with a level greater than the stack depth,2675when called with a level greater than the stack depth,
2683it returns 0.2676it returns 0.
2684 2677
@@ -2786,7 +2779,7 @@ The number of upvalues of the function. · 101 unmodified lines
2786 2779
2787<p></ul>2780<p></ul>
2788 2781
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>
2790 2783
2791<p>For the manipulation of local variables and upvalues,2784<p>For the manipulation of local variables and upvalues,
2792the debug interface uses indices:2785the 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
2863 }2856 }
2864</PRE>2857</PRE>
2865 2858
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>
2867 2860
2868<p>Lua offers a mechanism of hooks, which are2861<p>Lua offers a mechanism of hooks, which are
2869user-defined C functions that are called during the program execution.2862user-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
2939that execution occurs without any calls to hooks.2932that execution occurs without any calls to hooks.
2940 2933
2941<p>2934<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>
2943 2936
2944<p>The standard libraries provide useful functions2937<p>The standard libraries provide useful functions
2945that are implemented directly through the C API.2938that are implemented directly through the C API.
@@ -2982,7 +2975,7 @@ These functions are declared in <code>lualib.h</code>. · 36 unmodified lines
2982 2975
2983 2976
2984 2977
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>
2986 2979
2987<p>The basic library provides some core functions to Lua.2980<p>The basic library provides some core functions to Lua.
2988If you do not include this library in your application,2981If 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
3015 3008
3016<p><a name="pdf-error"><h3><code>error (message [, level])</code></h3></a>3009<p><a name="pdf-error"><h3><code>error (message [, level])</code></h3></a>
3017 3010
3018Terminates the last protected function called,3011Terminates the last protected function called
3019and returns <code>message</code> as the error message.3012and returns <code>message</code> as the error message.
3020Function <code>error</code> never returns.3013Function <code>error</code> never returns.
3021 3014
@@ -3043,7 +3036,7 @@ or if <code>f</code> is 0, · 21 unmodified lines
3043<code>getfenv</code> returns the global environment.3036<code>getfenv</code> returns the global environment.
3044The default for <code>f</code> is 1.3037The default for <code>f</code> is 1.
3045 3038
3046<p>if the environment has a <code>"__fenv"</code> field,3039<p>If the environment has a <code>"__fenv"</code> field,
3047returns the associated value, instead of the environment.3040returns the associated value, instead of the environment.
3048 3041
3049<p><a name="pdf-getmetatable"><h3><code>getmetatable (object)</code></h3></a>3042<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
3148 3141
3149<p>Calls function <code>f</code> with3142<p>Calls function <code>f</code> with
3150the given arguments in protected mode.3143the given arguments in protected mode.
3151That means that any error inside <code>f</code> is not propagated;3144That means that any error inside&nbsp;<code>f</code> is not propagated;
3152instead, <code>pcall</code> catches the error3145instead, <code>pcall</code> catches the error
3153and returns a status code.3146and returns a status code.
3154Its first result is the status code (a boolean),3147Its first result is the status code (a boolean),
3155which is true if the call succeeds without errors.3148which is <B>true</B> if the call succeeds without errors.
3156In such case, <code>pcall</code> also returns all results from the call,3149In such case, <code>pcall</code> also returns all results from the call,
3157after this first result.3150after this first result.
3158In case of any error, <code>pcall</code> returns <B>false</B> plus the error message.3151In 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
3327In case of any error,3320In case of any error,
3328<code>xpcall</code> returns false plus the result from <code>err</code>.3321<code>xpcall</code> returns false plus the result from <code>err</code>.
3329 3322
3330<p><h2>5.2 - Coroutine Manipulation</h2>3323<p><a name="5.2"><h2>5.2 - Coroutine Manipulation</h2></a>
3331 3324
3332<p>The operations related to coroutines comprise a sub-library of3325<p>The operations related to coroutines comprise a sub-library of
3333the basic library, and come inside the table .3326the basic library and come inside the table <code>coroutine</code>.
3334See <a href="#coroutine">2.10</a> for a general description of coroutines.3327See <a href="#coroutine">2.10</a> for a general description of coroutines.
3335 3328
3336<p><h3><code>coroutine.create (f)</code></h3>3329<p><h3><code>coroutine.create (f)</code></h3>
@@ -3385,7 +3378,7 @@ The coroutine cannot be running neither a C function, · 48 unmodified lines
3385nor a metamethod, nor an iterator.3378nor a metamethod, nor an iterator.
3386Any arguments to <code>yield</code> go as extra results to <code>resume</code>.3379Any arguments to <code>yield</code> go as extra results to <code>resume</code>.
3387 3380
3388<p><h2>5.3 - String Manipulation</h2>3381<p><a name="5.3"><h2>5.3 - String Manipulation</h2></a>
3389This library provides generic functions for string manipulation,3382This library provides generic functions for string manipulation,
3390such as finding and extracting substrings, and pattern matching.3383such as finding and extracting substrings, and pattern matching.
3391When indexing a string in Lua, the first character is at position&nbsp;13384When 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
3592<p><a name="pm"><h3>Patterns</h3></a>3585<p><a name="pm"><h3>Patterns</h3></a>
3593 3586
3594<p><p>3587<p><p>
3595a <em>character class</em> is used to represent a set of characters.3588A <em>character class</em> is used to represent a set of characters.
3596The following combinations are allowed in describing a character class:3589The following combinations are allowed in describing a character class:
3597<ul>3590<ul>
3598<li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters3591<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
3648The second form should be preferred for portability.3641The second form should be preferred for portability.
3649 3642
3650<p><p>3643<p><p>
3651a <em>pattern item</em> may be3644A <em>pattern item</em> may be
3652<ul>3645<ul>
3653<li> 3646<li>
3654a single character class,3647a single character class,
@@ -3685,7 +3678,7 @@ balanced parentheses. · 30 unmodified lines
3685</ul>3678</ul>
3686 3679
3687<p><p>3680<p><p>
3688a <em>pattern</em> is a sequence of pattern items.3681A <em>pattern</em> is a sequence of pattern items.
3689A `<code>^</code>&acute; at the beginning of a pattern anchors the match at the3682A `<code>^</code>&acute; at the beginning of a pattern anchors the match at the
3690beginning of the subject string.3683beginning of the subject string.
3691A `<code>$</code>&acute; at the end of a pattern anchors the match at the3684A `<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
3712 3705
3713<p>A pattern cannot contain embedded zeros. Use <code>%z</code> instead.3706<p>A pattern cannot contain embedded zeros. Use <code>%z</code> instead.
3714 3707
3715<p><h2>5.4 - Table Manipulation</h2>3708<p><a name="5.4"><h2>5.4 - Table Manipulation</h2></a>
3716This library provides generic functions for table manipulation.3709This library provides generic functions for table manipulation.
3717It provides all its functions inside the table <code>table</code>.3710It provides all its functions inside the table <code>table</code>.
3718 3711
@@ -3821,7 +3814,7 @@ that value is changed to the given <code>n</code>. · 102 unmodified lines
3821Otherwise, it updates an internal state3814Otherwise, it updates an internal state
3822so that subsequent calls to <code>table.getn(table)</code> return <code>n</code>.3815so that subsequent calls to <code>table.getn(table)</code> return <code>n</code>.
3823 3816
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>
3825 3818
3826<p>This library is an interface to most of the functions of the3819<p>This library is an interface to most of the functions of the
3827standard C&nbsp;math library.3820standard C&nbsp;math library.
@@ -3876,7 +3869,7 @@ The <code>math.randomseed</code> function sets a "seed" · 48 unmodified lines
3876for the pseudo-random generator:3869for the pseudo-random generator:
3877Equal seeds produce equal sequences of numbers.3870Equal seeds produce equal sequences of numbers.
3878 3871
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>
3880 3873
3881<p>The I/O library provides two different styles for file manipulation.3874<p>The I/O library provides two different styles for file manipulation.
3882The first one uses implicit file descriptors,3875The first one uses implicit file descriptors,
@@ -4069,7 +4062,7 @@ The arguments must be strings or numbers. · 186 unmodified lines
4069To write other values,4062To write other values,
4070use <code>tostring</code> or <code>string.format</code> before <code>write</code>.4063use <code>tostring</code> or <code>string.format</code> before <code>write</code>.
4071 4064
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>
4073 4066
4074<p>This library is implemented through table <code>os</code>.4067<p>This library is implemented through table <code>os</code>.
4075 4068
@@ -4095,7 +4088,7 @@ if <code>format</code> is <code>*t</code>, · 19 unmodified lines
4095then <code>date</code> returns a table with the following fields:4088then <code>date</code> returns a table with the following fields:
4096<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),4089<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),
4097<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),4090<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),
4099<code>yday</code> (day of the year),4092<code>yday</code> (day of the year),
4100and <code>isdst</code> (daylight saving flag, a boolean).4093and <code>isdst</code> (daylight saving flag, a boolean).
4101 4094
@@ -4184,7 +4177,7 @@ and the time you open the file, · 82 unmodified lines
4184it is possible for another process4177it is possible for another process
4185to create a file with the same name.4178to create a file with the same name.
4186 4179
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>
4188 4181
4189<p>The <code>debug</code> library provides4182<p>The <code>debug</code> library provides
4190the functionality of the debug interface to Lua programs.4183the 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
4320better error messages.4313better error messages.
4321 4314
4322<p>4315<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>
4324 4317
4325<p>Although Lua has been designed as an extension language,4318<p>Although Lua has been designed as an extension language,
4326to be embedded in a host C&nbsp;program,4319to be embedded in a host C&nbsp;program,
@@ -4459,7 +4452,7 @@ Stephan Herrmann, · 132 unmodified lines
4459Steve Dekorte,4452Steve Dekorte,
4460Thatcher Ulrich,4453Thatcher Ulrich,
4461Tom&#225;s Gorham,4454Tom&#225;s Gorham,
4462Vincent Penquerc'h,4455Vincent Penquerc'h.
4463Thank you!4456Thank you!
4464 4457
4465<p><hr>4458<p><hr>
@@ -4580,7 +4573,7 @@ Use <code>lua_newuserdata</code> or <code>lua_pushlightuserdata</code> instead. · 114 unmodified lines
4580 4573
4581<p> explist1 ::= {exp `<b>,</b>&acute;} exp4574<p> explist1 ::= {exp `<b>,</b>&acute;} exp
4582 4575
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
4584 4577
4585<p> prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;4578<p> prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
4586 4579
@@ -4609,5 +4602,11 @@ Use <code>lua_newuserdata</code> or <code>lua_pushlightuserdata</code> instead. · 22 unmodified lines
4609 4602
4610<p>4603<p>
4611 4604
4612</body></html>4605<HR>
4606<SMALL>
4607Last update:
4608Tue Nov 25 16:08:37 BRST 2003
4609</SMALL>
4613 4610
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 @@
1/*1/*
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 $
3** Lua - An Extensible Extension Language3** Lua - An Extensible Extension Language
4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
5** http://www.lua.org mailto:info@lua.org5** http://www.lua.org mailto:info@lua.org
@@ -14,7 +14,7 @@ · 8 unmodified lines
14#include <stddef.h>14#include <stddef.h>
15 15
16 16
17#define LUA_VERSION "Lua 5.0"17#define LUA_VERSION "Lua 5.0.1"
18#define LUA_COPYRIGHT "Copyright (C) 1994-2003 Tecgraf, PUC-Rio"18#define LUA_COPYRIGHT "Copyright (C) 1994-2003 Tecgraf, PUC-Rio"
19#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"19#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
20 20
src/ldo.c+19−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Stack and Call structure of Lua3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -322,11 +322,11 @@ static void resume (lua_State *L, void *ud) { · 316 unmodified lines
322 int nargs = *cast(int *, ud);322 int nargs = *cast(int *, ud);
323 CallInfo *ci = L->ci;323 CallInfo *ci = L->ci;
324 if (ci == L->base_ci) { /* no activation record? */324 if (ci == L->base_ci) { /* no activation record? */
325 if (nargs >= L->top - L->base)325 lua_assert(nargs < L->top - L->base);
326 luaG_runerror(L, "cannot resume dead coroutine");
327 luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */326 luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */
328 }327 }
329 else if (ci->state & CI_YIELD) { /* inside a yield? */328 else { /* inside a yield */
329 lua_assert(ci->state & CI_YIELD);
330 if (ci->state & CI_C) { /* `common' yield? */330 if (ci->state & CI_C) { /* `common' yield? */
331 /* finish interrupted execution of `OP_CALL' */331 /* finish interrupted execution of `OP_CALL' */
332 int nresults;332 int nresults;
@@ -341,18 +341,31 @@ static void resume (lua_State *L, void *ud) { · 8 unmodified lines
341 ci->state &= ~CI_YIELD;341 ci->state &= ~CI_YIELD;
342 }342 }
343 }343 }
344 else
345 luaG_runerror(L, "cannot resume non-suspended coroutine");
346 firstResult = luaV_execute(L);344 firstResult = luaV_execute(L);
347 if (firstResult != NULL) /* return? */345 if (firstResult != NULL) /* return? */
348 luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */346 luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */
349}347}
350 348
351 349
350static 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
352LUA_API int lua_resume (lua_State *L, int nargs) {359LUA_API int lua_resume (lua_State *L, int nargs) {
353 int status;360 int status;
354 lu_byte old_allowhooks;361 lu_byte old_allowhooks;
355 lua_lock(L);362 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");
356 old_allowhooks = L->allowhook;369 old_allowhooks = L->allowhook;
357 lua_assert(L->errfunc == 0 && L->nCcalls == 0);370 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
358 status = luaD_rawrunprotected(L, resume, &nargs);371 status = luaD_rawrunprotected(L, resume, &nargs);
src/lgc.c+14−9
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -110,7 +110,8 @@ static void marktmu (GCState *st) { · 104 unmodified lines
110 110
111 111
112/* move `dead' udata that need finalization to list `tmudata' */112/* move `dead' udata that need finalization to list `tmudata' */
113void luaC_separateudata (lua_State *L) {113size_t luaC_separateudata (lua_State *L) {
114 size_t deadmem = 0;
114 GCObject **p = &G(L)->rootudata;115 GCObject **p = &G(L)->rootudata;
115 GCObject *curr;116 GCObject *curr;
116 GCObject *collected = NULL; /* to collect udata with gc event */117 GCObject *collected = NULL; /* to collect udata with gc event */
@@ -125,6 +126,7 @@ void luaC_separateudata (lua_State *L) { · 8 unmodified lines
125 p = &curr->gch.next;126 p = &curr->gch.next;
126 }127 }
127 else { /* must call its gc method */128 else { /* must call its gc method */
129 deadmem += sizeudata(gcotou(curr)->uv.len);
128 *p = curr->gch.next;130 *p = curr->gch.next;
129 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */131 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
130 *lastcollected = curr;132 *lastcollected = curr;
@@ -134,6 +136,7 @@ void luaC_separateudata (lua_State *L) { · 3 unmodified lines
134 /* insert collected udata with gc event into `tmudata' list */136 /* insert collected udata with gc event into `tmudata' list */
135 *lastcollected = G(L)->tmudata;137 *lastcollected = G(L)->tmudata;
136 G(L)->tmudata = collected;138 G(L)->tmudata = collected;
139 return deadmem;
137}140}
138 141
139 142
@@ -244,7 +247,7 @@ static void traversestack (GCState *st, lua_State *L1) { · 104 unmodified lines
244 for (ci = L1->base_ci; ci <= L1->ci; ci++) {247 for (ci = L1->base_ci; ci <= L1->ci; ci++) {
245 lua_assert(ci->top <= L1->stack_last);248 lua_assert(ci->top <= L1->stack_last);
246 lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));249 lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
247 if (!(ci->state & CI_C) && lim < ci->top)250 if (lim < ci->top)
248 lim = ci->top;251 lim = ci->top;
249 }252 }
250 for (o = L1->stack; o < L1->top; o++)253 for (o = L1->stack; o < L1->top; o++)
@@ -387,7 +390,7 @@ static void sweepstrings (lua_State *L, int all) { · 136 unmodified lines
387}390}
388 391
389 392
390static void checkSizes (lua_State *L) {393static void checkSizes (lua_State *L, size_t deadmem) {
391 /* check size of string hash */394 /* check size of string hash */
392 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&395 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
393 G(L)->strt.size > MINSTRTABSIZE*2)396 G(L)->strt.size > MINSTRTABSIZE*2)
@@ -397,7 +400,7 @@ static void checkSizes (lua_State *L) { · 3 unmodified lines
397 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;400 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
398 luaZ_resizebuffer(L, &G(L)->buff, newsize);401 luaZ_resizebuffer(L, &G(L)->buff, newsize);
399 }402 }
400 G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */403 G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
401}404}
402 405
403 406
@@ -451,7 +454,8 @@ static void markroot (GCState *st, lua_State *L) { · 47 unmodified lines
451}454}
452 455
453 456
454static void mark (lua_State *L) {457static size_t mark (lua_State *L) {
458 size_t deadmem;
455 GCState st;459 GCState st;
456 GCObject *wkv;460 GCObject *wkv;
457 st.g = G(L);461 st.g = G(L);
@@ -464,7 +468,7 @@ static void mark (lua_State *L) { · 6 unmodified lines
464 wkv = st.wkv; /* keys must be cleared after preserving udata */468 wkv = st.wkv; /* keys must be cleared after preserving udata */
465 st.wkv = NULL;469 st.wkv = NULL;
466 st.wv = NULL;470 st.wv = NULL;
467 luaC_separateudata(L); /* separate userdata to be preserved */471 deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
468 marktmu(&st); /* mark `preserved' userdata */472 marktmu(&st); /* mark `preserved' userdata */
469 propagatemarks(&st); /* remark, to propagate `preserveness' */473 propagatemarks(&st); /* remark, to propagate `preserveness' */
470 cleartablekeys(wkv);474 cleartablekeys(wkv);
@@ -473,13 +477,14 @@ static void mark (lua_State *L) { · 2 unmodified lines
473 cleartablevalues(st.wv);477 cleartablevalues(st.wv);
474 cleartablekeys(st.wkv);478 cleartablekeys(st.wkv);
475 cleartablevalues(st.wkv);479 cleartablevalues(st.wkv);
480 return deadmem;
476}481}
477 482
478 483
479void luaC_collectgarbage (lua_State *L) {484void luaC_collectgarbage (lua_State *L) {
480 mark(L);485 size_t deadmem = mark(L);
481 luaC_sweep(L, 0);486 luaC_sweep(L, 0);
482 checkSizes(L);487 checkSizes(L, deadmem);
483 luaC_callGCTM(L);488 luaC_callGCTM(L);
484}489}
485 490
src/lgc.h+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -15,7 +15,7 @@ · 9 unmodified lines
15 if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }15 if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }
16 16
17 17
18void luaC_separateudata (lua_State *L);18size_t luaC_separateudata (lua_State *L);
19void luaC_callGCTM (lua_State *L);19void luaC_callGCTM (lua_State *L);
20void luaC_sweep (lua_State *L, int all);20void luaC_sweep (lua_State *L, int all);
21void luaC_collectgarbage (lua_State *L);21void luaC_collectgarbage (lua_State *L);
src/lib/lbaselib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -324,7 +324,7 @@ static int luaB_xpcall (lua_State *L) { · 318 unmodified lines
324 324
325 325
326static int luaB_tostring (lua_State *L) {326static int luaB_tostring (lua_State *L) {
327 char buff[64];327 char buff[128];
328 luaL_checkany(L, 1);328 luaL_checkany(L, 1);
329 if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */329 if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
330 return 1; /* use its value */330 return 1; /* use its value */
src/lib/liolib.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard I/O (and system) library3** Standard I/O (and system) library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -158,7 +158,7 @@ static int aux_close (lua_State *L) { · 152 unmodified lines
158 158
159 159
160static int io_close (lua_State *L) {160static 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) {
162 lua_pushstring(L, IO_OUTPUT);162 lua_pushstring(L, IO_OUTPUT);
163 lua_rawget(L, lua_upvalueindex(1));163 lua_rawget(L, lua_upvalueindex(1));
164 }164 }
@@ -175,7 +175,7 @@ static int io_gc (lua_State *L) { · 10 unmodified lines
175 175
176 176
177static int io_tostring (lua_State *L) {177static int io_tostring (lua_State *L) {
178 char buff[32];178 char buff[128];
179 FILE **f = topfile(L, 1);179 FILE **f = topfile(L, 1);
180 if (*f == NULL)180 if (*f == NULL)
181 strcpy(buff, "closed");181 strcpy(buff, "closed");
src/lparser.c+7−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -1141,11 +1141,15 @@ static void ifstat (LexState *ls, int line) { · 1135 unmodified lines
1141 1141
1142static void localfunc (LexState *ls) {1142static void localfunc (LexState *ls) {
1143 expdesc v, b;1143 expdesc v, b;
1144 FuncState *fs = ls->fs;
1144 new_localvar(ls, str_checkname(ls), 0);1145 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);
1146 adjustlocalvars(ls, 1);1148 adjustlocalvars(ls, 1);
1147 body(ls, &b, 0, ls->linenumber);1149 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;
1149}1153}
1150 1154
1151 1155
src/luac/Makefile+1−1
@@ -13,7 +13,7 @@ T= $(BIN)/luac · 12 unmodified lines
13all: $T13all: $T
14 14
15$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a15$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)
17 17
18# print.c needs opcode names from lopcodes.c18# print.c needs opcode names from lopcodes.c
19lopcodes.o: ../lopcodes.c ../lopcodes.h19lopcodes.o: ../lopcodes.c ../lopcodes.h
src/luac/luac.c+3−1
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua compiler (saves bytecodes to files; also list bytecodes)3** Lua compiler (saves bytecodes to files; also list bytecodes)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -182,7 +182,9 @@ int main(int argc, char* argv[]) · 176 unmodified lines
182 FILE* D=fopen(output,"wb");182 FILE* D=fopen(output,"wb");
183 if (D==NULL) cannot(output,"open","out");183 if (D==NULL) cannot(output,"open","out");
184 if (stripping) strip(L,f);184 if (stripping) strip(L,f);
185 lua_lock(L);
185 luaU_dump(L,f,writer,D);186 luaU_dump(L,f,writer,D);
187 lua_unlock(L);
186 if (ferror(D)) cannot(output,"write","out");188 if (ferror(D)) cannot(output,"write","out");
187 fclose(D);189 fclose(D);
188 }190 }
src/lvm.c+4−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua virtual machine3** Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -66,7 +66,7 @@ int luaV_tostring (lua_State *L, StkId obj) { · 60 unmodified lines
66 66
67static void traceexec (lua_State *L) {67static void traceexec (lua_State *L) {
68 lu_byte mask = L->hookmask;68 lu_byte mask = L->hookmask;
69 if (mask > LUA_MASKLINE) { /* instruction-hook set? */69 if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
70 if (L->hookcount == 0) {70 if (L->hookcount == 0) {
71 resethookcount(L);71 resethookcount(L);
72 luaD_callhook(L, LUA_HOOKCOUNT, -1);72 luaD_callhook(L, LUA_HOOKCOUNT, -1);
@@ -399,10 +399,10 @@ StkId luaV_execute (lua_State *L) { · 326 unmodified lines
399 TObject *k;399 TObject *k;
400 const Instruction *pc;400 const Instruction *pc;
401 callentry: /* entry point when calling new functions */401 callentry: /* entry point when calling new functions */
402 L->ci->u.l.pc = &pc;
403 if (L->hookmask & LUA_MASKCALL)402 if (L->hookmask & LUA_MASKCALL)
404 luaD_callhook(L, LUA_HOOKCALL, -1);403 luaD_callhook(L, LUA_HOOKCALL, -1);
405 retentry: /* entry point when returning to old functions */404 retentry: /* entry point when returning to old functions */
405 L->ci->u.l.pc = &pc;
406 lua_assert(L->ci->state == CI_SAVEDPC ||406 lua_assert(L->ci->state == CI_SAVEDPC ||
407 L->ci->state == (CI_SAVEDPC | CI_CALLING));407 L->ci->state == (CI_SAVEDPC | CI_CALLING));
408 L->ci->state = CI_HASFRAME; /* activate frame */408 L->ci->state = CI_HASFRAME; /* activate frame */
@@ -673,9 +673,7 @@ StkId luaV_execute (lua_State *L) { · 264 unmodified lines
673 }673 }
674 else { /* yes: continue its execution */674 else { /* yes: continue its execution */
675 int nresults;675 int nresults;
676 lua_assert(ci->u.l.pc == &pc &&676 lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
677 ttisfunction(ci->base - 1) &&
678 (ci->state & CI_SAVEDPC));
679 lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);677 lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);
680 nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;678 nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;
681 luaD_poscall(L, nresults, ra);679 luaD_poscall(L, nresults, ra);
test/luac.lua+3−3
@@ -1,7 +1,7 @@
1-- bare-bones luac in Lua1-- bare-bones luac in Lua
2-- usage: lua luac.lua file.lua2-- usage: lua luac.lua file.lua
3 3
4assert(arg[1]~=nil,"usage: lua luac.lua file.lua")4assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
5f=assert(io.open("luac.out","w"))5f=assert(io.open("luac.out","wb"))
6f:write(string.dump(loadfile(arg[1])))6f:write(string.dump(assert(loadfile(arg[1]))))
7io.close(f)7io.close(f)