History

Lua 5.2.0-beta-rc3

Lua Team committed 15 years ago

Commit deeb5211 parent 0f2fa0f10 files · +436 −266Browse files

Unified · Split

10 files
  1. README +1 −1
  2. doc/manual.html +210 −202
  3. doc/readme.html +3 −5
  4. src/Makefile +6 −5
  5. src/lctype.c +49 −0
  6. src/lctype.h +95 −0
  7. src/llex.c +48 −20
  8. src/lobject.c +9 −10
  9. src/lparser.c +13 −20
  10. src/lparser.h +2 −3
README+1−1
@@ -1,5 +1,5 @@
11
2−This is Lua 5.2 (beta), released on 13 Jun 2011.
2+This is Lua 5.2 (beta), released on 27 Jun 2011.
33
44 For installation instructions, license details, and
55 further information about Lua, see doc/readme.html.
doc/manual.html+210−202
@@ -38,7 +38,7 @@ Freely available under the terms of the · 37 unmodified lines
3838 <!-- ====================================================================== -->
3939 <p>
4040
41−<!-- $Id: manual.of,v 1.79 2011/06/21 14:35:46 roberto Exp $ -->
41+<!-- $Id: manual.of,v 1.80 2011/06/27 18:26:28 roberto Exp $ -->
4242
4343
4444
@@ -209,10 +209,11 @@ Thus tables can also carry <em>methods</em> (see <a href="#3.4.10">&sect;3.4.10< · 164 unmodified lines
209209
210210 <p>
211211 The indexing of tables follows
212−the definition of equality in the language.
212+the definition of raw equality in the language.
213213 The expressions <code>a[i]</code> and <code>a[j]</code>
214214 denote the same table element
215−if and only if <code>i == j</code>.
215+if and only if <code>i</code> and <code>j</code> are raw equal
216+(that is, equal without metamethods).
216217
217218
218219 <p>
@@ -328,7 +329,7 @@ you may give an <em>message handler</em> · 109 unmodified lines
328329 to be called in case of errors.
329330 This function is called with the original error message
330331 and returns a new error message.
331−It is called before the error unwonds the stack,
332+It is called before the error unwinds the stack,
332333 so that it can gather more information about the error,
333334 for instance by inspecting the stack and creating a stack traceback.
334335 This message handler is still protected by the protected call;
@@ -443,7 +444,7 @@ in the following code. · 108 unmodified lines
443444
444445 <ul>
445446
446−<li><b>"add":</b>
447+<li><b>"add": </b>
447448 the <code>+</code> operation.
448449
449450
@@ -481,25 +482,25 @@ the behavior of the <code>op1 + op2</code> is · 31 unmodified lines
481482 </pre><p>
482483 </li>
483484
484−<li><b>"sub":</b>
485+<li><b>"sub": </b>
485486 the <code>-</code> operation.
486487
487488 Behavior similar to the "add" operation.
488489 </li>
489490
490−<li><b>"mul":</b>
491+<li><b>"mul": </b>
491492 the <code>*</code> operation.
492493
493494 Behavior similar to the "add" operation.
494495 </li>
495496
496−<li><b>"div":</b>
497+<li><b>"div": </b>
497498 the <code>/</code> operation.
498499
499500 Behavior similar to the "add" operation.
500501 </li>
501502
502−<li><b>"mod":</b>
503+<li><b>"mod": </b>
503504 the <code>%</code> operation.
504505
505506 Behavior similar to the "add" operation,
@@ -507,7 +508,7 @@ with the operation · 1 unmodified line
507508 <code>o1 - floor(o1/o2)*o2</code> as the primitive operation.
508509 </li>
509510
510−<li><b>"pow":</b>
511+<li><b>"pow": </b>
511512 the <code>^</code> (exponentiation) operation.
512513
513514 Behavior similar to the "add" operation,
@@ -515,7 +516,7 @@ with the function <code>pow</code> (from the C&nbsp;math library) · 1 unmodified line
515516 as the primitive operation.
516517 </li>
517518
518−<li><b>"unm":</b>
519+<li><b>"unm": </b>
519520 the unary <code>-</code> operation.
520521
521522
@@ -538,7 +539,7 @@ the unary <code>-</code> operation. · 16 unmodified lines
538539 </pre><p>
539540 </li>
540541
541−<li><b>"concat":</b>
542+<li><b>"concat": </b>
542543 the <code>..</code> (concatenation) operation.
543544
544545
@@ -559,7 +560,7 @@ the <code>..</code> (concatenation) operation. · 14 unmodified lines
559560 </pre><p>
560561 </li>
561562
562−<li><b>"len":</b>
563+<li><b>"len": </b>
563564 the <code>#</code> operation.
564565
565566
@@ -582,7 +583,7 @@ the <code>#</code> operation. · 16 unmodified lines
582583 See <a href="#3.4.6">&sect;3.4.6</a> for a description of the length of a table.
583584 </li>
584585
585−<li><b>"eq":</b>
586+<li><b>"eq": </b>
586587 the <code>==</code> operation.
587588
588589 The function <code>getequalhandler</code> defines how Lua chooses a metamethod
@@ -620,7 +621,7 @@ The "eq" event is defined as follows: · 31 unmodified lines
620621 </pre><p>
621622 </li>
622623
623−<li><b>"lt":</b>
624+<li><b>"lt": </b>
624625 the <code>&lt;</code> operation.
625626
626627
@@ -642,7 +643,7 @@ the <code>&lt;</code> operation. · 15 unmodified lines
642643 </pre><p>
643644 </li>
644645
645−<li><b>"le":</b>
646+<li><b>"le": </b>
646647 the <code>&lt;=</code> operation.
647648
648649
@@ -672,7 +673,7 @@ Lua tries the "lt", assuming that <code>a &lt;= b</code> is · 23 unmodified lines
672673 equivalent to <code>not (b &lt; a)</code>.
673674 </li>
674675
675−<li><b>"index":</b>
676+<li><b>"index": </b>
676677 The indexing access <code>table[key]</code>.
677678 Note that the metamethod is tried only
678679 when <code>key</code> is not present in <code>table</code>.
@@ -704,7 +705,7 @@ so the metamethod is always tried.) · 25 unmodified lines
704705 </pre><p>
705706 </li>
706707
707−<li><b>"newindex":</b>
708+<li><b>"newindex": </b>
708709 The indexing assignment <code>table[key] = value</code>.
709710 Note that the metamethod is tried only
710711 when <code>key</code> is not present in <code>table</code>.
@@ -733,7 +734,7 @@ when <code>key</code> is not present in <code>table</code>. · 22 unmodified lines
733734 </pre><p>
734735 </li>
735736
736−<li><b>"call":</b>
737+<li><b>"call": </b>
737738 called when Lua calls a value.
738739
739740
@@ -845,7 +846,7 @@ and the metatable has a field indexed by the string "<code>__gc</code>". · 105 unmodified lines
845846 Note that if you set a metatable without a <code>__gc</code> field
846847 and later create that field in the metatable,
847848 the object will not be marked for finalization.
848−However, after a userdata is marked,
849+However, after an object is marked,
849850 you can freely change the <code>__gc</code> field of its metatable.
850851
851852
@@ -873,7 +874,16 @@ the reverse order that they were marked for collection, · 21 unmodified lines
873874 among those collected in that cycle;
874875 that is, the first finalizer to be called is the one associated
875876 with the object marked last in the program.
876−The object memory is freed only in the next garbage-collection cycle.
877+The execution of each finalizer may occur at any point during
878+the execution of the regular code.
879+
880+
881+<p>
882+Because the object being collected must still be used by the finalizer
883+and even <em>resurrected</em>resurrection
884+(e.g., stored by the finalizer in a global variable),
885+the object memory is freed only when it becomes completely inaccessible
886+(that is, in the next garbage-collection cycle unless it was resurrected).
877887
878888
879889
@@ -1536,9 +1546,10 @@ labels in Lua are considered statements too: · 656 unmodified lines
15361546 </pre>
15371547
15381548 <p>
1539−A label is visible in the entire block where it is defined
1540−(including nested blocks, but not nested functions).
1541−A function cannot have more than one label with a given name.
1549+A label is visible in the entire block where it is defined,
1550+except
1551+inside nested blocks where a label with the same name is defined and
1552+inside nested functions.
15421553 A goto may jump to any visible label as long as it does not
15431554 enter into the scope of a local variable.
15441555
@@ -2592,12 +2603,12 @@ defined as constants in <code>lua.h</code>. · 1047 unmodified lines
25922603 The following constants are defined:
25932604
25942605 <ul>
2595−<li><b>LUA_RIDX_MAINTHREAD:</b> At this index the registry has
2606+<li><b>LUA_RIDX_MAINTHREAD: </b> At this index the registry has
25962607 the main thread of the state.
25972608 (The main thread is the one created together with the state.)
25982609 </li>
25992610
2600−<li><b>LUA_RIDX_GLOBALS:</b> At this index the registry has
2611+<li><b>LUA_RIDX_GLOBALS: </b> At this index the registry has
26012612 the global environment.
26022613 This is the C&nbsp;equivalent to the <a href="#pdf-_G"><code>_G</code></a> global variable.
26032614 </li>
@@ -2840,7 +2851,7 @@ but it seems a safe assumption. · 236 unmodified lines
28402851
28412852
28422853 <hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p>
2843−<span class="apii">[-(2/1), +1, <em>e</em>]</span>
2854+<span class="apii">[-(2|1), +1, <em>e</em>]</span>
28442855 <pre>int lua_arith (lua_State *L, int op);</pre>
28452856
28462857 <p>
@@ -2858,13 +2869,13 @@ The value of <code>op</code> must be one of the following constants: · 11 unmodified lines
28582869
28592870 <ul>
28602871
2861−<li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>:</b>performs addition (<code>+</code>)</li>
2862−<li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>:</b>performs subtraction (<code>-</code>)</li>
2863−<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>:</b>performs multiplication (<code>*</code>)</li>
2864−<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>:</b>performs division (<code>/</code>)</li>
2865−<li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>:</b>performs modulo (<code>%</code>)</li>
2866−<li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>:</b>performs exponentiation (<code>^</code>)</li>
2867−<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>:</b>performs mathematical negation (unary <code>-</code>)</li>
2872+<li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li>
2873+<li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li>
2874+<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li>
2875+<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>: </b> performs division (<code>/</code>)</li>
2876+<li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li>
2877+<li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li>
2878+<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li>
28682879
28692880 </ul>
28702881
@@ -3068,9 +3079,9 @@ The value of <code>op</code> must be one of the following constants: · 197 unmodified lines
30683079
30693080 <ul>
30703081
3071−<li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>:</b>compares for equality (<code>==</code>)</li>
3072−<li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>:</b>compares for less than (<code>&lt;</code>)</li>
3073−<li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>:</b>compares for less or equal (<code>&lt;=</code>)</li>
3082+<li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li>
3083+<li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</code>)</li>
3084+<li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt;=</code>)</li>
30743085
30753086 </ul>
30763087
@@ -3186,28 +3197,28 @@ according to the value of the parameter <code>what</code>: · 109 unmodified lines
31863197
31873198 <ul>
31883199
3189−<li><b><code>LUA_GCSTOP</code>:</b>
3200+<li><b><code>LUA_GCSTOP</code>: </b>
31903201 stops the garbage collector.
31913202 </li>
31923203
3193−<li><b><code>LUA_GCRESTART</code>:</b>
3204+<li><b><code>LUA_GCRESTART</code>: </b>
31943205 restarts the garbage collector.
31953206 </li>
31963207
3197−<li><b><code>LUA_GCCOLLECT</code>:</b>
3208+<li><b><code>LUA_GCCOLLECT</code>: </b>
31983209 performs a full garbage-collection cycle.
31993210 </li>
32003211
3201−<li><b><code>LUA_GCCOUNT</code>:</b>
3212+<li><b><code>LUA_GCCOUNT</code>: </b>
32023213 returns the current amount of memory (in Kbytes) in use by Lua.
32033214 </li>
32043215
3205−<li><b><code>LUA_GCCOUNTB</code>:</b>
3216+<li><b><code>LUA_GCCOUNTB</code>: </b>
32063217 returns the remainder of dividing the current amount of bytes of
32073218 memory in use by Lua by 1024.
32083219 </li>
32093220
3210−<li><b><code>LUA_GCSTEP</code>:</b>
3221+<li><b><code>LUA_GCSTEP</code>: </b>
32113222 performs an incremental step of garbage collection.
32123223 The step "size" is controlled by <code>data</code>
32133224 (larger values mean more steps) in a non-specified way.
@@ -3217,19 +3228,19 @@ The function returns 1 if the step finished a · 3 unmodified lines
32173228 garbage-collection cycle.
32183229 </li>
32193230
3220−<li><b><code>LUA_GCSETPAUSE</code>:</b>
3231+<li><b><code>LUA_GCSETPAUSE</code>: </b>
32213232 sets <code>data</code> as the new value
32223233 for the <em>pause</em> of the collector (see <a href="#2.5">&sect;2.5</a>).
32233234 The function returns the previous value of the pause.
32243235 </li>
32253236
3226−<li><b><code>LUA_GCSETSTEPMUL</code>:</b>
3237+<li><b><code>LUA_GCSETSTEPMUL</code>: </b>
32273238 sets <code>data</code> as the new value for the <em>step multiplier</em> of
32283239 the collector (see <a href="#2.5">&sect;2.5</a>).
32293240 The function returns the previous value of the step multiplier.
32303241 </li>
32313242
3232−<li><b><code>LUA_GCISRUNNING</code>:</b>
3243+<li><b><code>LUA_GCISRUNNING</code>: </b>
32333244 returns a boolean that tells whether the collector is running
32343245 (i.e., not stopped).
32353246 </li>
@@ -3293,19 +3304,6 @@ as in the case of an yield. · 57 unmodified lines
32933304
32943305
32953306
3296−<hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p>
3297−<span class="apii">[-0, +1, <em>-</em>]</span>
3298−<pre>void lua_getuservalue (lua_State *L, int index);</pre>
3299−
3300−<p>
3301−Pushes onto the stack the Lua value associated with the userdata
3302−at the given index.
3303−This Lua value must be a table or <b>nil</b>.
3304−
3305−
3306−
3307−
3308−
33093307 <hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p>
33103308 <span class="apii">[-0, +1, <em>e</em>]</span>
33113309 <pre>void lua_getfield (lua_State *L, int index, const char *k);</pre>
@@ -3381,6 +3379,19 @@ this result is equal to the number of elements in the stack · 69 unmodified lines
33813379
33823380
33833381
3382+<hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p>
3383+<span class="apii">[-0, +1, <em>-</em>]</span>
3384+<pre>void lua_getuservalue (lua_State *L, int index);</pre>
3385+
3386+<p>
3387+Pushes onto the stack the Lua value associated with the userdata
3388+at the given index.
3389+This Lua value must be a table or <b>nil</b>.
3390+
3391+
3392+
3393+
3394+
33843395 <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p>
33853396 <span class="apii">[-1, +1, <em>-</em>]</span>
33863397 <pre>void lua_insert (lua_State *L, int index);</pre>
@@ -3590,15 +3601,15 @@ The return values of <a href="#lua_load"><code>lua_load</code></a> are: · 203 unmodified lines
35903601
35913602 <ul>
35923603
3593−<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a> (0):</b> no errors;</li>
3604+<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> no errors;</li>
35943605
3595−<li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>:</b>
3606+<li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b>
35963607 syntax error during pre-compilation;</li>
35973608
3598−<li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>:</b>
3609+<li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
35993610 memory allocation error.</li>
36003611
3601−<li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>:</b>
3612+<li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
36023613 error while running a <code>__gc</code> metamethod.
36033614 (This error has no relation with the chunk being loaded.
36043615 It is generated by the garbage collector.)
@@ -3707,13 +3718,6 @@ and you can detect when it is being collected. · 102 unmodified lines
37073718 A full userdata is only equal to itself (under raw equality).
37083719
37093720
3710−<p>
3711−When Lua collects a full userdata with a <code>gc</code> metamethod,
3712−Lua calls the metamethod and marks the userdata as finalized.
3713−When this userdata is collected again then
3714−Lua frees its corresponding memory.
3715−
3716−
37173721
37183722
37193723
@@ -3823,23 +3827,23 @@ The <a href="#lua_pcall"><code>lua_pcall</code></a> function returns one of the · 103 unmodified lines
38233827
38243828 <ul>
38253829
3826−<li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0):</b>
3830+<li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b>
38273831 success.</li>
38283832
3829−<li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>:</b>
3833+<li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>: </b>
38303834 a runtime error.
38313835 </li>
38323836
3833−<li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>:</b>
3837+<li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
38343838 memory allocation error.
38353839 For such errors, Lua does not call the message handler.
38363840 </li>
38373841
3838−<li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>:</b>
3842+<li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>: </b>
38393843 error while running the message handler.
38403844 </li>
38413845
3842−<li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>:</b>
3846+<li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
38433847 error while running a <code>__gc</code> metamethod.
38443848 (This error typically has no relation with the function being called.
38453849 It is generated by the garbage collector.)
@@ -4018,7 +4022,7 @@ light userdata with the same C&nbsp;address. · 172 unmodified lines
40184022
40194023 <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p>
40204024 <span class="apii">[-0, +1, <em>m</em>]</span>
4021−<pre>void lua_pushliteral (lua_State *L, const char *s);</pre>
4025+<pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre>
40224026
40234027 <p>
40244028 This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>,
@@ -4341,18 +4345,6 @@ with user data <code>ud</code>. · 316 unmodified lines
43414345
43424346
43434347
4344−<hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p>
4345−<span class="apii">[-1, +0, <em>-</em>]</span>
4346−<pre>void lua_setuservalue (lua_State *L, int index);</pre>
4347−
4348−<p>
4349−Pops a table or <b>nil</b> from the stack and sets it as
4350−the new value associated to the userdata at the given index.
4351−
4352−
4353−
4354−
4355−
43564348 <hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p>
43574349 <span class="apii">[-1, +0, <em>e</em>]</span>
43584350 <pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>
@@ -4433,6 +4425,18 @@ If <code>index</code> is&nbsp;0, then all stack elements are removed. · 74 unmodified lines
44334425
44344426
44354427
4428+<hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p>
4429+<span class="apii">[-1, +0, <em>-</em>]</span>
4430+<pre>void lua_setuservalue (lua_State *L, int index);</pre>
4431+
4432+<p>
4433+Pops a table or <b>nil</b> from the stack and sets it as
4434+the new value associated to the userdata at the given index.
4435+
4436+
4437+
4438+
4439+
44364440 <hr><h3><a name="lua_State"><code>lua_State</code></a></h3>
44374441 <pre>typedef struct lua_State lua_State;</pre>
44384442
@@ -4919,7 +4923,7 @@ The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following · 480 unmodified lines
49194923
49204924 <ul>
49214925
4922−<li><b><code>source</code>:</b>
4926+<li><b><code>source</code>: </b>
49234927 the source of the chunk that created the function.
49244928 If <code>source</code> starts with a '<code>@</code>',
49254929 it means that the function was defined in a file where
@@ -4931,31 +4935,31 @@ the function was defined in a string where · 5 unmodified lines
49314935 <code>source</code> is that string.
49324936 </li>
49334937
4934−<li><b><code>short_src</code>:</b>
4938+<li><b><code>short_src</code>: </b>
49354939 a "printable" version of <code>source</code>, to be used in error messages.
49364940 </li>
49374941
4938−<li><b><code>linedefined</code>:</b>
4942+<li><b><code>linedefined</code>: </b>
49394943 the line number where the definition of the function starts.
49404944 </li>
49414945
4942−<li><b><code>lastlinedefined</code>:</b>
4946+<li><b><code>lastlinedefined</code>: </b>
49434947 the line number where the definition of the function ends.
49444948 </li>
49454949
4946−<li><b><code>what</code>:</b>
4950+<li><b><code>what</code>: </b>
49474951 the string <code>"Lua"</code> if the function is a Lua function,
49484952 <code>"C"</code> if it is a C&nbsp;function,
49494953 <code>"main"</code> if it is the main part of a chunk.
49504954 </li>
49514955
4952−<li><b><code>currentline</code>:</b>
4956+<li><b><code>currentline</code>: </b>
49534957 the current line where the given function is executing.
49544958 When no line information is available,
49554959 <code>currentline</code> is set to -1.
49564960 </li>
49574961
4958−<li><b><code>name</code>:</b>
4962+<li><b><code>name</code>: </b>
49594963 a reasonable name for the given function.
49604964 Because functions in Lua are first-class values,
49614965 they do not have a fixed name:
@@ -4967,7 +4971,7 @@ If it cannot find a name, · 5 unmodified lines
49674971 then <code>name</code> is set to <code>NULL</code>.
49684972 </li>
49694973
4970−<li><b><code>namewhat</code>:</b>
4974+<li><b><code>namewhat</code>: </b>
49714975 explains the <code>name</code> field.
49724976 The value of <code>namewhat</code> can be
49734977 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
@@ -4976,21 +4980,21 @@ according to how the function was called. · 2 unmodified lines
49764980 (Lua uses the empty string when no other option seems to apply.)
49774981 </li>
49784982
4979−<li><b><code>istailcall</code>:</b>
4983+<li><b><code>istailcall</code>: </b>
49804984 true if this function invocation was called by a tail call.
49814985 In this case, the caller of this level is not in the stack.
49824986 </li>
49834987
4984−<li><b><code>nups</code>:</b>
4988+<li><b><code>nups</code>: </b>
49854989 the number of upvalues of the function.
49864990 </li>
49874991
4988−<li><b><code>nparams</code>:</b>
4992+<li><b><code>nparams</code>: </b>
49894993 the number of fixed parameters of the function
49904994 (always 0&nbsp;for C&nbsp;functions).
49914995 </li>
49924996
4993−<li><b><code>isvararg</code>:</b>
4997+<li><b><code>isvararg</code>: </b>
49944998 whether the function is a vararg function
49954999 (always true for C&nbsp;functions).
49965000 </li>
@@ -5070,29 +5074,30 @@ a value to be pushed on the stack: · 73 unmodified lines
50705074
50715075 <ul>
50725076
5073−<li><b>'<code>n</code>':</b> fills in the field <code>name</code> and <code>namewhat</code>;
5077+<li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;
50745078 </li>
50755079
5076−<li><b>'<code>S</code>':</b>
5080+<li><b>'<code>S</code>': </b>
50775081 fills in the fields <code>source</code>, <code>short_src</code>,
50785082 <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
50795083 </li>
50805084
5081−<li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>;
5085+<li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;
50825086 </li>
50835087
5084−<li><b>'<code>t</code>':</b> fills in the field <code>istailcall</code>;
5088+<li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;
50855089 </li>
50865090
5087−<li><b>'<code>u</code>':</b> fills in the field <code>nups</code>;
5091+<li><b>'<code>u</code>': </b> fills in the fields
5092+<code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;
50885093 </li>
50895094
5090−<li><b>'<code>f</code>':</b>
5095+<li><b>'<code>f</code>': </b>
50915096 pushes onto the stack the function that is
50925097 running at the given level;
50935098 </li>
50945099
5095−<li><b>'<code>L</code>':</b>
5100+<li><b>'<code>L</code>': </b>
50965101 pushes onto the stack a table whose indices are the
50975102 numbers of the lines that are valid on the function.
50985103 (A <em>valid line</em> is a line with some associated code,
@@ -5164,7 +5169,8 @@ This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> s · 65 unmodified lines
51645169 an identification of the <em>activation record</em>
51655170 of the function executing at a given level.
51665171 Level&nbsp;0 is the current running function,
5167−whereas level <em>n+1</em> is the function that has called level <em>n</em>.
5172+whereas level <em>n+1</em> is the function that has called level <em>n</em>
5173+(except for tail calls, which do not count on the stack).
51685174 When there are no errors, <a href="#lua_getstack"><code>lua_getstack</code></a> returns 1;
51695175 when called with a level greater than the stack depth,
51705176 it returns 0.
@@ -5257,24 +5263,24 @@ For each event, the hook is called as explained below: · 86 unmodified lines
52575263
52585264 <ul>
52595265
5260−<li><b>The call hook:</b> is called when the interpreter calls a function.
5266+<li><b>The call hook: </b> is called when the interpreter calls a function.
52615267 The hook is called just after Lua enters the new function,
52625268 before the function gets its arguments.
52635269 </li>
52645270
5265−<li><b>The return hook:</b> is called when the interpreter returns from a function.
5271+<li><b>The return hook: </b> is called when the interpreter returns from a function.
52665272 The hook is called just before Lua leaves the function.
52675273 There is no standard way to access the values
52685274 to be returned by the function.
52695275 </li>
52705276
5271−<li><b>The line hook:</b> is called when the interpreter is about to
5277+<li><b>The line hook: </b> is called when the interpreter is about to
52725278 start the execution of a new line of code,
52735279 or when it jumps back in the code (even to the same line).
52745280 (This event only happens while Lua is executing a Lua function.)
52755281 </li>
52765282
5277−<li><b>The count hook:</b> is called after the interpreter executes every
5283+<li><b>The count hook: </b> is called after the interpreter executes every
52785284 <code>count</code> instructions.
52795285 (This event only happens while Lua is executing a Lua function.)
52805286 </li>
@@ -5333,7 +5339,7 @@ when the index is greater than the number of upvalues. · 52 unmodified lines
53335339
53345340 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p>
53355341 <span class="apii">[-0, +0, <em>-</em>]</span>
5336−<pre>void *(lua_upvalueid) (lua_State *L, int funcindex, int n);</pre>
5342+<pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>
53375343
53385344 <p>
53395345 Returns an unique identifier for the upvalue numbered <code>n</code>
@@ -5832,7 +5838,7 @@ and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</co · 492 unmodified lines
58325838
58335839 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
58345840 <span class="apii">[-0, +0, <em>-</em>]</span>
5835−<pre>void *luaL_checkversion (lua_State *L);</pre>
5841+<pre>void luaL_checkversion (lua_State *L);</pre>
58365842
58375843 <p>
58385844 Checks whether the core running the call,
@@ -5919,9 +5925,9 @@ process-related functions in the standard library · 80 unmodified lines
59195925
59205926
59215927 <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p>
5922−<span class="apii">[-0, +(1/3), <em>m</em>]</span>
5928+<span class="apii">[-0, +(1|3), <em>m</em>]</span>
59235929 <pre>int luaL_fileresult (lua_State *L, int stat,
5924− const char *fname)</pre>
5930+ const char *fname);</pre>
59255931
59265932 <p>
59275933 This function produces the return values for
@@ -6650,22 +6656,22 @@ It performs different functions according to its first argument, <code>opt</code · 722 unmodified lines
66506656
66516657 <ul>
66526658
6653−<li><b>"collect":</b>
6659+<li><b>"collect": </b>
66546660 performs a full garbage-collection cycle.
66556661 This is the default option.
66566662 </li>
66576663
6658−<li><b>"stop":</b>
6664+<li><b>"stop": </b>
66596665 stops automatic invocation of the garbage collector.
66606666 The collector will run only when explcitly invoked,
66616667 until a call to restart it.
66626668 </li>
66636669
6664−<li><b>"restart":</b>
6670+<li><b>"restart": </b>
66656671 restarts automatic invocation the garbage collector.
66666672 </li>
66676673
6668−<li><b>"count":</b>
6674+<li><b>"count": </b>
66696675 returns the total memory in use by Lua (in Kbytes) and
66706676 a second value with the total memory in bytes modulo 1024.
66716677 The first value has a fractional part,
@@ -6679,7 +6685,7 @@ so the following equality is always true: · 7 unmodified lines
66796685 with a non floating-point type for numbers.)
66806686 </li>
66816687
6682−<li><b>"step":</b>
6688+<li><b>"step": </b>
66836689 performs a garbage-collection step.
66846690 The step "size" is controlled by <code>arg</code>
66856691 (larger values mean more steps) in a non-specified way.
@@ -6688,19 +6694,19 @@ you must experimentally tune the value of <code>arg</code>. · 2 unmodified lines
66886694 Returns <b>true</b> if the step finished a collection cycle.
66896695 </li>
66906696
6691−<li><b>"setpause":</b>
6697+<li><b>"setpause": </b>
66926698 sets <code>arg</code> as the new value for the <em>pause</em> of
66936699 the collector (see <a href="#2.5">&sect;2.5</a>).
66946700 Returns the previous value for <em>pause</em>.
66956701 </li>
66966702
6697−<li><b>"setstepmul":</b>
6703+<li><b>"setstepmul": </b>
66986704 sets <code>arg</code> as the new value for the <em>step multiplier</em> of
66996705 the collector (see <a href="#2.5">&sect;2.5</a>).
67006706 Returns the previous value for <em>step</em>.
67016707 </li>
67026708
6703−<li><b>"isrunning":</b>
6709+<li><b>"isrunning": </b>
67046710 returns a boolean that tells whether the collector is running
67056711 (i.e., not stopped).
67066712 </li>
@@ -7757,9 +7763,9 @@ The name <code>gsub</code> comes from <em>Global SUBstitution</em>. · 1050 unmodified lines
77577763 <p>
77587764 If <code>repl</code> is a string, then its value is used for replacement.
77597765 The character&nbsp;<code>%</code> works as an escape character:
7760−any sequence in <code>repl</code> of the form <code>%<em>n</em></code>,
7761−with <em>n</em> between 1 and 9,
7762−stands for the value of the <em>n</em>-th captured substring (see below).
7766+any sequence in <code>repl</code> of the form <code>%<em>d</em></code>,
7767+with <em>d</em> between 1 and 9,
7768+stands for the value of the <em>d</em>-th captured substring (see below).
77637769 The sequence <code>%0</code> stands for the whole match.
77647770 The sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.
77657771
@@ -7903,35 +7909,35 @@ The following combinations are allowed in describing a character class: · 137 unmodified lines
79037909
79047910 <ul>
79057911
7906−<li><b><em>x</em>:</b>
7912+<li><b><em>x</em>: </b>
79077913 (where <em>x</em> is not one of the <em>magic characters</em>
79087914 <code>^$()%.[]*+-?</code>)
79097915 represents the character <em>x</em> itself.
79107916 </li>
79117917
7912−<li><b><code>.</code>:</b> (a dot) represents all characters.</li>
7918+<li><b><code>.</code>: </b> (a dot) represents all characters.</li>
79137919
7914−<li><b><code>%a</code>:</b> represents all letters.</li>
7920+<li><b><code>%a</code>: </b> represents all letters.</li>
79157921
7916−<li><b><code>%c</code>:</b> represents all control characters.</li>
7922+<li><b><code>%c</code>: </b> represents all control characters.</li>
79177923
7918−<li><b><code>%d</code>:</b> represents all digits.</li>
7924+<li><b><code>%d</code>: </b> represents all digits.</li>
79197925
7920−<li><b><code>%g</code>:</b> represents all printable characters except space.</li>
7926+<li><b><code>%g</code>: </b> represents all printable characters except space.</li>
79217927
7922−<li><b><code>%l</code>:</b> represents all lowercase letters.</li>
7928+<li><b><code>%l</code>: </b> represents all lowercase letters.</li>
79237929
7924−<li><b><code>%p</code>:</b> represents all punctuation characters.</li>
7930+<li><b><code>%p</code>: </b> represents all punctuation characters.</li>
79257931
7926−<li><b><code>%s</code>:</b> represents all space characters.</li>
7932+<li><b><code>%s</code>: </b> represents all space characters.</li>
79277933
7928−<li><b><code>%u</code>:</b> represents all uppercase letters.</li>
7934+<li><b><code>%u</code>: </b> represents all uppercase letters.</li>
79297935
7930−<li><b><code>%w</code>:</b> represents all alphanumeric characters.</li>
7936+<li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>
79317937
7932−<li><b><code>%x</code>:</b> represents all hexadecimal digits.</li>
7938+<li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>
79337939
7934−<li><b><code>%<em>x</em></code>:</b> (where <em>x</em> is any non-alphanumeric character)
7940+<li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)
79357941 represents the character <em>x</em>.
79367942 This is the standard way to escape the magic characters.
79377943 Any punctuation character (even the non magic)
@@ -7939,7 +7945,7 @@ can be preceded by a '<code>%</code>' · 1 unmodified line
79397945 when used to represent itself in a pattern.
79407946 </li>
79417947
7942−<li><b><code>[<em>set</em>]</code>:</b>
7948+<li><b><code>[<em>set</em>]</code>: </b>
79437949 represents the class which is the union of all
79447950 characters in <em>set</em>.
79457951 A range of characters can be specified by
@@ -7961,7 +7967,7 @@ Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> · 15 unmodified lines
79617967 have no meaning.
79627968 </li>
79637969
7964−<li><b><code>[^<em>set</em>]</code>:</b>
7970+<li><b><code>[^<em>set</em>]</code>: </b>
79657971 represents the complement of <em>set</em>,
79667972 where <em>set</em> is interpreted as above.
79677973 </li>
@@ -8097,13 +8103,11 @@ It provides all its functions inside the table <a name="pdf-table"><code>table</ · 129 unmodified lines
80978103
80988104
80998105 <p>
8100−Currently, all functions in the table library,
8101−except <a href="#pdf-table.pack"><code>table.pack</code></a>,
8102−work on lists.
8103−A list here means a proper sequence
8104−or a table with a <code>__len</code> metamethod (see <a href="#3.4.6">&sect;3.4.6</a>).
8105−In particular, all functions ignore non-numeric keys
8106−in lists given as arguments.
8106+Remember that, whenever an operation needs the length of a table,
8107+the table should be a proper sequence
8108+or have a <code>__len</code> metamethod (see <a href="#3.4.6">&sect;3.4.6</a>).
8109+All functions ignore non-numeric keys
8110+in tables given as arguments.
81078111
81088112
81098113 <p>
@@ -8642,7 +8646,7 @@ Returns the bitwise exclusive or of its operands. · 532 unmodified lines
86428646
86438647
86448648 <p>
8645−<hr><h3><a name="pdf-bit32.extract"><code>bit32.extract (n, field, width)</code></a></h3>
8649+<hr><h3><a name="pdf-bit32.extract"><code>bit32.extract (n, field [, width])</code></a></h3>
86468650
86478651
86488652 <p>
@@ -8652,10 +8656,14 @@ Bits are numbered from 0 (least significant) to 31 (most significant). · 3 unmodified lines
86528656 All accessed bits must be in the range <em>[0, 31]</em>.
86538657
86548658
8659+<p>
8660+The default for <code>width</code> is 1.
8661+
8662+
86558663
86568664
86578665 <p>
8658−<hr><h3><a name="pdf-bit32.replace"><code>bit32.replace (n, v, field, width)</code></a></h3>
8666+<hr><h3><a name="pdf-bit32.replace"><code>bit32.replace (n, v, field [, width])</code></a></h3>
86598667
86608668
86618669 <p>
@@ -8848,7 +8856,7 @@ instead of returning an error code. · 186 unmodified lines
88488856 <p>
88498857 Opens the given file name in read mode
88508858 and returns an iterator function that
8851−works like <code>file:lines(&middot;&middot;&middot;)</code> over the oppened file.
8859+works like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.
88528860 When the iterator function detects the end of file,
88538861 it returns <b>nil</b> (to finish the loop) and automatically closes the file.
88548862
@@ -8877,12 +8885,12 @@ or, in case of errors, <b>nil</b> plus an error message. · 22 unmodified lines
88778885 The <code>mode</code> string can be any of the following:
88788886
88798887 <ul>
8880−<li><b>"r":</b> read mode (the default);</li>
8881−<li><b>"w":</b> write mode;</li>
8882−<li><b>"a":</b> append mode;</li>
8883−<li><b>"r+":</b> update mode, all previous data is preserved;</li>
8884−<li><b>"w+":</b> update mode, all previous data is erased;</li>
8885−<li><b>"a+":</b> append update mode, previous data is preserved,
8888+<li><b>"r": </b> read mode (the default);</li>
8889+<li><b>"w": </b> write mode;</li>
8890+<li><b>"a": </b> append mode;</li>
8891+<li><b>"r+": </b> update mode, all previous data is preserved;</li>
8892+<li><b>"w+": </b> update mode, all previous data is erased;</li>
8893+<li><b>"a+": </b> append update mode, previous data is preserved,
88868894 writing is only allowed at the end of file.</li>
88878895 </ul><p>
88888896 The <code>mode</code> string can also have a '<code>b</code>' at the end,
@@ -9037,28 +9045,28 @@ The available formats are · 148 unmodified lines
90379045
90389046 <ul>
90399047
9040−<li><b>"*n":</b>
9048+<li><b>"*n": </b>
90419049 reads a number;
90429050 this is the only format that returns a number instead of a string.
90439051 </li>
90449052
9045−<li><b>"*a":</b>
9053+<li><b>"*a": </b>
90469054 reads the whole file, starting at the current position.
90479055 On end of file, it returns the empty string.
90489056 </li>
90499057
9050−<li><b>"*l":</b>
9058+<li><b>"*l": </b>
90519059 reads the next line skipping the end of line,
90529060 returning <b>nil</b> on end of file.
90539061 This is the default format.
90549062 </li>
90559063
9056−<li><b>"*L":</b>
9064+<li><b>"*L": </b>
90579065 reads the next line keeping the end of line (if present),
90589066 returning <b>nil</b> on end of file.
90599067 </li>
90609068
9061−<li><b><em>number</em>:</b>
9069+<li><b><em>number</em>: </b>
90629070 reads a string with up to this number of characters,
90639071 returning <b>nil</b> on end of file.
90649072 If number is zero,
@@ -9081,9 +9089,9 @@ to the position given by <code>offset</code> plus a base · 16 unmodified lines
90819089 specified by the string <code>whence</code>, as follows:
90829090
90839091 <ul>
9084−<li><b>"set":</b> base is position 0 (beginning of the file);</li>
9085−<li><b>"cur":</b> base is current position;</li>
9086−<li><b>"end":</b> base is end of file;</li>
9092+<li><b>"set": </b> base is position 0 (beginning of the file);</li>
9093+<li><b>"cur": </b> base is current position;</li>
9094+<li><b>"end": </b> base is end of file;</li>
90879095 </ul><p>
90889096 In case of success, function <code>seek</code> returns the final file position,
90899097 measured in bytes from the beginning of the file.
@@ -9114,17 +9122,17 @@ There are three available modes: · 24 unmodified lines
91149122
91159123 <ul>
91169124
9117−<li><b>"no":</b>
9125+<li><b>"no": </b>
91189126 no buffering; the result of any output operation appears immediately.
91199127 </li>
91209128
9121−<li><b>"full":</b>
9129+<li><b>"full": </b>
91229130 full buffering; output operation is performed only
91239131 when the buffer is full (or when you explicitly <code>flush</code> the file
91249132 (see <a href="#pdf-io.flush"><code>io.flush</code></a>)).
91259133 </li>
91269134
9127−<li><b>"line":</b>
9135+<li><b>"line": </b>
91289136 line buffering; output is buffered until a newline is output
91299137 or there is any input from some special files
91309138 (such as a terminal device).
@@ -9251,12 +9259,12 @@ as follows: · 120 unmodified lines
92519259
92529260 <ul>
92539261
9254−<li><b>"<code>exit</code>":</b>
9262+<li><b>"<code>exit</code>": </b>
92559263 the command terminated normally;
92569264 the following number is the exit status of the command.
92579265 </li>
92589266
9259−<li><b>"<code>signal</code>":</b>
9267+<li><b>"<code>signal</code>": </b>
92609268 the command was terminated by a signal;
92619269 the following number is the signal that terminated the command.
92629270 </li>
@@ -9460,18 +9468,6 @@ within any function, and so have no direct access to local variables. · 197 unmodified lines
94609468
94619469
94629470
9463−<p>
9464−<hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3>
9465−
9466−
9467−<p>
9468−Returns the Lua value associated to <code>u</code>.
9469−If <code>u</code> is not a userdata,
9470−returns <b>nil</b>.
9471−
9472−
9473−
9474−
94759471 <p>
94769472 <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3>
94779473
@@ -9596,18 +9592,13 @@ The function returns <b>nil</b> if there is no upvalue with the given index. · 118 unmodified lines
95969592
95979593
95989594 <p>
9599−<hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3>
9600−
9601−
9602−<p>
9603−Sets the given <code>value</code> as
9604−the Lua value associated to the given <code>udata</code>.
9605−<code>value</code> must be a table or <b>nil</b>;
9606−<code>udata</code> must be a full userdata.
9595+<hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3>
96079596
96089597
96099598 <p>
9610−Returns <code>udata</code>.
9599+Returns the Lua value associated to <code>u</code>.
9600+If <code>u</code> is not a userdata,
9601+returns <b>nil</b>.
96119602
96129603
96139604
@@ -9624,9 +9615,9 @@ The string mask may have the following characters, · 10 unmodified lines
96249615 with the given meaning:
96259616
96269617 <ul>
9627−<li><b><code>"c"</code>:</b> the hook is called every time Lua calls a function;</li>
9628−<li><b><code>"r"</code>:</b> the hook is called every time Lua returns from a function;</li>
9629−<li><b><code>"l"</code>:</b> the hook is called every time Lua enters a new line of code.</li>
9618+<li><b><code>"c"</code>: </b> the hook is called every time Lua calls a function;</li>
9619+<li><b><code>"r"</code>: </b> the hook is called every time Lua returns from a function;</li>
9620+<li><b><code>"l"</code>: </b> the hook is called every time Lua enters a new line of code.</li>
96309621 </ul><p>
96319622 With a <code>count</code> different from zero,
96329623 the hook is called after every <code>count</code> instructions.
@@ -9701,6 +9692,23 @@ Otherwise, it returns the name of the upvalue. · 68 unmodified lines
97019692
97029693
97039694
9695+<p>
9696+<hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3>
9697+
9698+
9699+<p>
9700+Sets the given <code>value</code> as
9701+the Lua value associated to the given <code>udata</code>.
9702+<code>value</code> must be a table or <b>nil</b>;
9703+<code>udata</code> must be a full userdata.
9704+
9705+
9706+<p>
9707+Returns <code>udata</code>.
9708+
9709+
9710+
9711+
97049712 <p>
97059713 <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3>
97069714
@@ -9772,12 +9780,12 @@ Its usage is: · 65 unmodified lines
97729780 The options are:
97739781
97749782 <ul>
9775−<li><b><code>-e <em>stat</em></code>:</b> executes string <em>stat</em>;</li>
9776−<li><b><code>-l <em>mod</em></code>:</b> "requires" <em>mod</em>;</li>
9777−<li><b><code>-i</code>:</b> enters interactive mode after running <em>script</em>;</li>
9778−<li><b><code>-v</code>:</b> prints version information;</li>
9779−<li><b><code>--</code>:</b> stops handling options;</li>
9780−<li><b><code>-</code>:</b> executes <code>stdin</code> as a file and stops handling options.</li>
9783+<li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li>
9784+<li><b><code>-l <em>mod</em></code>: </b> "requires" <em>mod</em>;</li>
9785+<li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li>
9786+<li><b><code>-v</code>: </b> prints version information;</li>
9787+<li><b><code>--</code>: </b> stops handling options;</li>
9788+<li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li>
97819789 </ul><p>
97829790 After handling its options, <code>lua</code> runs the given <em>script</em>,
97839791 passing to it the given <em>args</em> as string arguments.
@@ -10195,7 +10203,7 @@ Here is the complete syntax of Lua in extended BNF. · 411 unmodified lines
1019510203 <HR>
1019610204 <SMALL CLASS="footer">
1019710205 Last update:
10198−Tue Jun 21 19:09:27 BRT 2011
10206+Mon Jun 27 15:48:15 BRT 2011
1019910207 </SMALL>
1020010208 <!--
1020110209 Last change: revised for Lua 5.2.0 (beta)
doc/readme.html+3−5
@@ -145,9 +145,7 @@ and liblua.a (the library). · 144 unmodified lines
145145 <P>
146146 <LI>
147147 To check that Lua has been built correctly, do "<KBD>make test</KBD>"
148− after building Lua. This will run the interpreter on a simple "Hello world"
149− Lua program from the test directory.
150− You may want to try other example programs in that directory.
148+ after building Lua. This will run the interpreter and print its version string.
151149 </OL>
152150
153151 <H3>Installing Lua</H3>
@@ -162,7 +160,7 @@ and liblua.a (the library). · 8 unmodified lines
162160 where xxx is your platform name.
163161
164162 <P>
165− To install Lua locally, then do "<KBD>make local</KBD>".
163+ To install Lua locally, do "<KBD>make local</KBD>".
166164 This will create a directory <TT>install</TT> with subdirectories
167165 <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>,
168166 and install Lua as listed below.
@@ -399,7 +397,7 @@ THE SOFTWARE. · 230 unmodified lines
399397 <HR>
400398 <SMALL CLASS="footer">
401399 Last update:
402−Thu Jun 16 08:21:17 BRT 2011
400+Fri Jun 24 11:30:57 BRT 2011
403401 </SMALL>
404402 <!--
405403 Last change: revised for Lua 5.2.0 (beta)
src/Makefile+6−5
@@ -28,7 +28,7 @@ MYLIBS= · 27 unmodified lines
2828 PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
2929
3030 LUA_A= liblua.a
31−CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
31+CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
3232 lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
3333 ltm.o lundump.o lvm.o lzio.o
3434 LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
@@ -132,6 +132,7 @@ lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ · 97 unmodified lines
132132 lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
133133 lstring.h ltable.h lvm.h
134134 lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h
135+lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h
135136 ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
136137 ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
137138 ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \
@@ -147,14 +148,14 @@ lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ · 9 unmodified lines
147148 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
148149 linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
149150 liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
150−llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
151− lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
151+llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \
152+ lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
152153 lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
153154 lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
154155 ltm.h lzio.h lmem.h ldo.h lgc.h
155156 loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
156−lobject.o: lobject.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
157− llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
157+lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \
158+ lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
158159 lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
159160 loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
160161 lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
src/lctype.c+49−0
@@ -0,0 +1,49 @@
1+/*
2+** $Id: lctype.c,v 1.10 2011/06/24 12:25:33 roberto Exp $
3+** 'ctype' functions for Lua
4+** See Copyright Notice in lua.h
5+*/
6+
7+#include "lctype.h"
8+
9+#if !LUA_USE_CTYPE /* { */
10+
11+#include <limits.h>
12+
13+LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
14+ 0x00, /* EOZ */
15+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
16+ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
17+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
18+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
19+ 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
20+ 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
21+ 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
22+ 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
23+ 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
24+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
25+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
26+ 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
27+ 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
28+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
29+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
30+ 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
31+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */
32+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */
34+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */
36+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */
38+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */
40+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */
42+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */
44+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */
46+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47+};
48+
49+#endif /* } */
src/lctype.h+95−0
@@ -0,0 +1,95 @@
1+/*
2+** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp $
3+** 'ctype' functions for Lua
4+** See Copyright Notice in lua.h
5+*/
6+
7+#ifndef lctype_h
8+#define lctype_h
9+
10+#include "lua.h"
11+
12+
13+/*
14+** WARNING: the functions defined here do not necessarily correspond
15+** to the similar functions in the standard C ctype.h. They are
16+** optimized for the specific needs of Lua
17+*/
18+
19+#if !defined(LUA_USE_CTYPE)
20+
21+#if 'A' == 65 && '0' == 48
22+/* ASCII case: can use its own tables; faster and fixed */
23+#define LUA_USE_CTYPE 0
24+#else
25+/* must use standard C ctype */
26+#define LUA_USE_CTYPE 1
27+#endif
28+
29+#endif
30+
31+
32+#if !LUA_USE_CTYPE /* { */
33+
34+#include <limits.h>
35+
36+#include "llimits.h"
37+
38+
39+#define ALPHABIT 0
40+#define DIGITBIT 1
41+#define PRINTBIT 2
42+#define SPACEBIT 3
43+#define XDIGITBIT 4
44+
45+
46+#define MASK(B) (1 << (B))
47+
48+
49+/*
50+** add 1 to char to allow index -1 (EOZ)
51+*/
52+#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
53+
54+/*
55+** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
56+*/
57+#define lislalpha(c) testprop(c, MASK(ALPHABIT))
58+#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
59+#define lisdigit(c) testprop(c, MASK(DIGITBIT))
60+#define lisspace(c) testprop(c, MASK(SPACEBIT))
61+#define lisprint(c) testprop(c, MASK(PRINTBIT))
62+#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
63+
64+/*
65+** this 'ltolower' only works for alphabetic characters
66+*/
67+#define ltolower(c) ((c) | ('A' ^ 'a'))
68+
69+
70+/* two more entries for 0 and -1 (EOZ) */
71+LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
72+
73+
74+#else /* }{ */
75+
76+/*
77+** use standard C ctypes
78+*/
79+
80+#include <ctype.h>
81+
82+
83+#define lislalpha(c) (isalpha(c) || (c) == '_')
84+#define lislalnum(c) (isalnum(c) || (c) == '_')
85+#define lisdigit(c) (isdigit(c))
86+#define lisspace(c) (isspace(c))
87+#define lisprint(c) (isprint(c))
88+#define lisxdigit(c) (isxdigit(c))
89+
90+#define ltolower(c) (tolower(c))
91+
92+#endif /* } */
93+
94+#endif
95+
src/llex.c+48−20
@@ -1,11 +1,11 @@
11 /*
2−** $Id: llex.c,v 2.50 2011/06/20 16:52:48 roberto Exp $
2+** $Id: llex.c,v 2.49 2011/06/23 14:54:48 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
66
77
8−#include <ctype.h>
8+#include <locale.h>
99 #include <string.h>
1010
1111 #define llex_c
@@ -13,6 +13,7 @@ · 1 unmodified line
1313
1414 #include "lua.h"
1515
16+#include "lctype.h"
1617 #include "ldo.h"
1718 #include "llex.h"
1819 #include "lobject.h"
@@ -74,7 +75,7 @@ void luaX_init (lua_State *L) { · 55 unmodified lines
7475 const char *luaX_token2str (LexState *ls, int token) {
7576 if (token < FIRST_RESERVED) {
7677 lua_assert(token == cast(unsigned char, token));
77− return (isprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
78+ return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
7879 luaO_pushfstring(ls->L, "char(%d)", token);
7980 }
8081 else {
@@ -184,24 +185,52 @@ static int check_next (LexState *ls, const char *set) { · 103 unmodified lines
184185 }
185186
186187
188+/*
189+** change all characters 'from' in buffer to 'to'
190+*/
191+static void buffreplace (LexState *ls, char from, char to) {
192+ size_t n = luaZ_bufflen(ls->buff);
193+ char *p = luaZ_buffer(ls->buff);
194+ while (n--)
195+ if (p[n] == from) p[n] = to;
196+}
197+
198+
199+#if !defined(getlocaledecpoint)
200+#define getlocaledecpoint() (localeconv()->decimal_point[0])
201+#endif
202+
187203
188204 #define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
189205
206+/*
207+** in case of format error, try to change decimal point separator to
208+** the one defined in the current locale and check again
209+*/
210+static void trydecpoint (LexState *ls, SemInfo *seminfo) {
211+ char old = ls->decpoint;
212+ ls->decpoint = getlocaledecpoint();
213+ buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
214+ if (!buff2d(ls->buff, &seminfo->r)) {
215+ /* format error with correct decimal point: no more options */
216+ buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
217+ lexerror(ls, "malformed number", TK_NUMBER);
218+ }
219+}
220+
190221
191222 /* LUA_NUMBER */
192223 static void read_numeral (LexState *ls, SemInfo *seminfo) {
193− lua_assert(isdigit(ls->current));
224+ lua_assert(lisdigit(ls->current));
194225 do {
195226 save_and_next(ls);
196227 if (check_next(ls, "EePp")) /* exponent part? */
197228 check_next(ls, "+-"); /* optional exponent sign */
198− } while (isalnum(ls->current) || ls->current == '.');
229+ } while (lislalnum(ls->current) || ls->current == '.');
199230 save(ls, '\0');
200− if (!luaO_str2d(luaZ_buffer(ls->buff),
201− luaZ_bufflen(ls->buff) - 1,
202− &seminfo->r)) /* format error? */
203− lexerror(ls, "malformed number", TK_NUMBER);
204−
231+ buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
232+ if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
233+ trydecpoint(ls, seminfo); /* try to update decimal point separator */
205234 }
206235
207236
@@ -260,9 +289,9 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { · 52 unmodified lines
260289 static int readhexaesc (LexState *ls) {
261290 int c1 = next(ls);
262291 int c2 = EOZ;
263− if (isxdigit(c1)) {
292+ if (lisxdigit(c1)) {
264293 c2 = next(ls);
265− if (isxdigit(c2))
294+ if (lisxdigit(c2))
266295 return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2);
267296 /* else go through to error */
268297 }
@@ -279,10 +308,10 @@ static int readdecesc (LexState *ls) { · 10 unmodified lines
279308 int c1 = ls->current; /* first char must be a digit */
280309 int c2 = next(ls); /* read second char */
281310 int c = c1 - '0'; /* partial result */
282− if (isdigit(c2)) {
311+ if (lisdigit(c2)) {
283312 int c3 = next(ls); /* read third char */
284313 c = 10*c + c2 - '0'; /* update result */
285− if (isdigit(c3)) {
314+ if (lisdigit(c3)) {
286315 c = 10*c + c3 - '0'; /* update result */
287316 if (c > UCHAR_MAX) {
288317 luaZ_resetbuffer(ls->buff); /* prepare error message */
@@ -327,14 +356,14 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 38 unmodified lines
327356 case EOZ: continue; /* will raise an error next loop */
328357 case '*': { /* skip following span of spaces */
329358 next(ls); /* skip the '*' */
330− while (isspace(ls->current)) {
359+ while (lisspace(ls->current)) {
331360 if (currIsNewline(ls)) inclinenumber(ls);
332361 else next(ls);
333362 }
334363 continue; /* do not save 'c' */
335364 }
336365 default: {
337− if (!isdigit(ls->current))
366+ if (!lisdigit(ls->current))
338367 c = ls->current; /* handles \\, \", \', and \? */
339368 else /* digital escape \ddd */
340369 c = readdecesc(ls);
@@ -431,7 +460,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 90 unmodified lines
431460 return TK_DOTS; /* '...' */
432461 else return TK_CONCAT; /* '..' */
433462 }
434− else if (!isdigit(ls->current)) return '.';
463+ else if (!lisdigit(ls->current)) return '.';
435464 /* else go through */
436465 }
437466 case '0': case '1': case '2': case '3': case '4':
@@ -443,12 +472,11 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 5 unmodified lines
443472 return TK_EOS;
444473 }
445474 default: {
446− if (isalpha(ls->current) || ls->current == '_') {
447− /* identifier or reserved word */
475+ if (lislalpha(ls->current)) { /* identifier or reserved word? */
448476 TString *ts;
449477 do {
450478 save_and_next(ls);
451− } while (isalnum(ls->current) || ls->current == '_');
479+ } while (lislalnum(ls->current));
452480 ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
453481 luaZ_bufflen(ls->buff));
454482 seminfo->ts = ts;
src/lobject.c+9−10
@@ -1,10 +1,9 @@
11 /*
2−** $Id: lobject.c,v 2.51 2011/06/18 17:25:15 roberto Exp $
2+** $Id: lobject.c,v 2.52 2011/06/24 12:25:02 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
66
7−#include <ctype.h>
87 #include <stdarg.h>
98 #include <stdio.h>
109 #include <stdlib.h>
@@ -15,6 +14,7 @@ · 4 unmodified lines
1514
1615 #include "lua.h"
1716
17+#include "lctype.h"
1818 #include "ldebug.h"
1919 #include "ldo.h"
2020 #include "lmem.h"
@@ -85,9 +85,8 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { · 64 unmodified lines
8585
8686
8787 int luaO_hexavalue (int c) {
88− lua_assert(isxdigit(c));
89− if (isdigit(c)) return c - '0';
90− else return toupper(c) - 'A' + 10;
88+ if (lisdigit(c)) return c - '0';
89+ else return ltolower(c) - 'a' + 10;
9190 }
9291
9392
@@ -104,7 +103,7 @@ static int isneg (const char **s) { · 10 unmodified lines
104103
105104
106105 static lua_Number readhexa (const char **s, lua_Number r, int *count) {
107− while (isxdigit(cast_uchar(**s))) { /* read integer part */
106+ while (lisxdigit(cast_uchar(**s))) { /* read integer part */
108107 r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++)));
109108 (*count)++;
110109 }
@@ -121,7 +120,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 10 unmodified lines
121120 int e = 0, i = 0;
122121 int neg = 0; /* 1 if number is negative */
123122 *endptr = cast(char *, s); /* nothing is valid yet */
124− while (isspace(cast_uchar(*s))) s++; /* skip initial spaces */
123+ while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
125124 neg = isneg(&s); /* check signal */
126125 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
127126 return 0.0; /* invalid format (no '0x') */
@@ -140,9 +139,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 12 unmodified lines
140139 int neg1;
141140 s++; /* skip 'p' */
142141 neg1 = isneg(&s); /* signal */
143− if (!isdigit(cast_uchar(*s)))
142+ if (!lisdigit(cast_uchar(*s)))
144143 goto ret; /* must have at least one digit */
145− while (isdigit(cast_uchar(*s))) /* read exponent */
144+ while (lisdigit(cast_uchar(*s))) /* read exponent */
146145 exp1 = exp1 * 10 + *(s++) - '0';
147146 if (neg1) exp1 = -exp1;
148147 e += exp1;
@@ -163,7 +162,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { · 14 unmodified lines
163162 else
164163 *result = lua_str2number(s, &endptr);
165164 if (endptr == s) return 0; /* nothing recognized */
166− while (isspace(cast_uchar(*endptr))) endptr++;
165+ while (lisspace(cast_uchar(*endptr))) endptr++;
167166 return (endptr == s + len); /* OK if no trailing characters */
168167 }
169168
src/lparser.c+13−20
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.111 2011/06/20 16:52:48 roberto Exp $
2+** $Id: lparser.c,v 2.112 2011/06/27 18:18:59 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -367,7 +367,7 @@ static int findlabel (LexState *ls, int g) { · 361 unmodified lines
367367 /* check labels in current block for a match */
368368 for (i = bl->firstlabel; i < dyd->label.n; i++) {
369369 Labeldesc *lb = &dyd->label.arr[i];
370− if (eqstr(lb->name, gt->name) && lb->pc != -1) { /* correct label? */
370+ if (eqstr(lb->name, gt->name)) { /* correct label? */
371371 if (gt->nactvar > lb->nactvar &&
372372 (bl->upval || dyd->label.n > bl->firstlabel))
373373 luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
@@ -466,12 +466,6 @@ static void undefgoto (LexState *ls, Labeldesc *gt) { · 92 unmodified lines
466466 }
467467
468468
469−static void invalidatelabels (Labellist *ll, int level) {
470− for (; level < ll->n; level++)
471− ll->arr[level].pc = -1; /* mark label as out of scope */
472−}
473−
474−
475469 static void leaveblock (FuncState *fs) {
476470 BlockCnt *bl = fs->bl;
477471 LexState *ls = fs->ls;
@@ -487,7 +481,7 @@ static void leaveblock (FuncState *fs) { · 9 unmodified lines
487481 removevars(fs, bl->nactvar);
488482 lua_assert(bl->nactvar == fs->nactvar);
489483 fs->freereg = fs->nactvar; /* free registers */
490− invalidatelabels(&ls->dyd->label, bl->firstlabel); /* remove local labels */
484+ ls->dyd->label.n = bl->firstlabel; /* remove local labels */
491485 if (bl->previous) /* inner block? */
492486 movegotosout(fs, bl); /* update pending gotos to outer block */
493487 else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
@@ -532,7 +526,6 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { · 38 unmodified lines
532526 fs->nlocvars = 0;
533527 fs->nactvar = 0;
534528 fs->firstlocal = ls->dyd->actvar.n;
535− fs->firstlabel = ls->dyd->label.n;
536529 fs->bl = NULL;
537530 f = luaF_newproto(L);
538531 fs->f = f;
@@ -555,7 +548,6 @@ static void close_func (LexState *ls) { · 16 unmodified lines
555548 Proto *f = fs->f;
556549 luaK_ret(fs, 0, 0); /* final return */
557550 leaveblock(fs);
558− ls->dyd->label.n = fs->firstlabel; /* remove labels */
559551 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
560552 f->sizecode = fs->pc;
561553 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
@@ -1193,16 +1185,15 @@ static void gotostat (LexState *ls, TString *label, int line) { · 631 unmodified lines
11931185 }
11941186
11951187
1196−/* check for repeated labels on the same function */
1197−static void checkrepeated (LexState *ls, FuncState *fs, Labellist *ll,
1198− TString *label) {
1188+/* check for repeated labels on the same block */
1189+static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {
11991190 int i;
1200− for (i = fs->firstlabel; i < ll->n; i++) {
1191+ for (i = fs->bl->firstlabel; i < ll->n; i++) {
12011192 if (eqstr(label, ll->arr[i].name)) {
1202− const char *msg = luaO_pushfstring(ls->L,
1203− "label " LUA_QS " already defined on line %d",
1204− getstr(label), ll->arr[i].line);
1205− semerror(ls, msg);
1193+ const char *msg = luaO_pushfstring(fs->ls->L,
1194+ "label " LUA_QS " already defined on line %d",
1195+ getstr(label), ll->arr[i].line);
1196+ semerror(fs->ls, msg);
12061197 }
12071198 }
12081199 }
@@ -1213,7 +1204,7 @@ static void labelstat (LexState *ls, TString *label, int line) { · 4 unmodified lines
12131204 FuncState *fs = ls->fs;
12141205 Labellist *ll = &ls->dyd->label;
12151206 int l; /* index of new label being created */
1216− checkrepeated(ls, fs, ll, label); /* check for repeated labels */
1207+ checkrepeated(fs, ll, label); /* check for repeated labels */
12171208 checknext(ls, TK_DBCOLON); /* skip double colon */
12181209 /* create new entry for this label */
12191210 l = newlabelentry(ls, ll, label, line, fs->pc);
@@ -1607,5 +1598,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, · 387 unmodified lines
16071598 L->top--; /* pop name */
16081599 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
16091600 return funcstate.f;
1601+ /* all scopes should be correctly finished */
1602+ lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
16101603 }
16111604
src/lparser.h+2−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.h,v 1.69 2011/06/16 16:36:39 roberto Exp $
2+** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -62,7 +62,7 @@ typedef struct Vardesc { · 56 unmodified lines
6262 /* description of pending goto statements and label statements */
6363 typedef struct Labeldesc {
6464 TString *name; /* label identifier */
65− int pc; /* position in code (for labels, -1 means out of scope) */
65+ int pc; /* position in code */
6666 int line; /* line where it appeared */
6767 lu_byte nactvar; /* local level where it appears in current block */
6868 } Labeldesc;
@@ -107,7 +107,6 @@ typedef struct FuncState { · 38 unmodified lines
107107 int nk; /* number of elements in `k' */
108108 int np; /* number of elements in `p' */
109109 int firstlocal; /* index of first local var of this function */
110− int firstlabel; /* index of first label of this function */
111110 short nlocvars; /* number of elements in `locvars' */
112111 lu_byte nactvar; /* number of active local variables */
113112 lu_byte nups; /* number of upvalues */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t