History

Lua 5.2.0-beta-rc2

Lua Team committed 15 years ago

Commit 0f2fa0f1 parent 30837cc24 files · +364 −432Browse files

Unified · Split

24 files
  1. doc/contents.html +5 −3
  2. doc/lua.css +2 −1
  3. doc/manual.html +47 −45
  4. doc/readme.html +4 −3
  5. src/Makefile +25 −23
  6. src/lauxlib.c +6 −7
  7. src/lauxlib.h +4 −1
  8. src/lbaselib.c +15 −6
  9. src/lbitlib.c +2 −2
  10. src/lctype.c +0 −45
  11. src/lctype.h +0 −50
  12. src/ldo.c +23 −4
  13. src/liolib.c +128 −139
  14. src/llex.c +43 −59
  15. src/llex.h +2 −2
  16. src/lobject.c +11 −11
  17. src/loslib.c +2 −2
  18. src/lparser.c +31 −16
  19. src/lparser.h +3 −2
  20. src/lstrlib.c +2 −2
  21. src/ltable.c +2 −2
  22. src/lua.c +2 −2
  23. src/luac.c +3 −3
  24. src/lundump.c +2 −2
doc/contents.html+5−3
@@ -40,7 +40,7 @@ For a complete introduction to Lua programming, see the book · 39 unmodified lines
40<SMALL>40<SMALL>
41Copyright &copy; 2011 Lua.org, PUC-Rio.41Copyright &copy; 2011 Lua.org, PUC-Rio.
42Freely available under the terms of the42Freely available under the terms of the
43<a href="http://www.lua.org/license.html#5">Lua license</a>.43<A HREF="http://www.lua.org/license.html#5">Lua license</A>.
44</SMALL>44</SMALL>
45 45
46<H2><A NAME="contents">Contents</A></H2>46<H2><A NAME="contents">Contents</A></H2>
@@ -146,6 +146,8 @@ Freely available under the terms of the · 99 unmodified lines
146<P>146<P>
147<A HREF="manual.html#pdf-_G">_G</A><BR>147<A HREF="manual.html#pdf-_G">_G</A><BR>
148<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>148<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
149
150<P>
149<A HREF="manual.html#pdf-assert">assert</A><BR>151<A HREF="manual.html#pdf-assert">assert</A><BR>
150<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>152<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
151<A HREF="manual.html#pdf-dofile">dofile</A><BR>153<A HREF="manual.html#pdf-dofile">dofile</A><BR>
@@ -518,9 +520,9 @@ Freely available under the terms of the · 366 unmodified lines
518</TABLE>520</TABLE>
519 521
520<HR>522<HR>
521<SMALL>523<SMALL CLASS="footer">
522Last update:524Last update:
523Mon Jun 13 15:09:33 BRT 2011525Mon Jun 20 08:55:58 BRT 2011
524</SMALL>526</SMALL>
525<!--527<!--
526Last change: revised for Lua 5.2.0 (beta)528Last change: revised for Lua 5.2.0 (beta)
doc/lua.css+2−1
@@ -2,13 +2,14 @@ body { · 1 unmodified line
2 color: #000000 ;2 color: #000000 ;
3 background-color: #FFFFFF ;3 background-color: #FFFFFF ;
4 font-family: sans-serif ;4 font-family: sans-serif ;
5 font-family: Helvetica, Arial, sans-serif ;
5 text-align: justify ;6 text-align: justify ;
6 margin-right: 20px ;7 margin-right: 20px ;
7 margin-left: 20px ;8 margin-left: 20px ;
8}9}
9 10
10h1, h2, h3, h4 {11h1, h2, h3, h4 {
11 font-family: Verdana, sans-serif ;12 font-family: Verdana, Geneva, sans-serif ;
12 font-weight: normal ;13 font-weight: normal ;
13 font-style: italic ;14 font-style: italic ;
14}15}
doc/manual.html+47−45
@@ -38,7 +38,7 @@ Freely available under the terms of the · 37 unmodified lines
38<!-- ====================================================================== -->38<!-- ====================================================================== -->
39<p>39<p>
40 40
41<!-- $Id: manual.of,v 1.77 2011/06/13 16:27:54 roberto Exp $ -->41<!-- $Id: manual.of,v 1.79 2011/06/21 14:35:46 roberto Exp $ -->
42 42
43 43
44 44
@@ -54,7 +54,7 @@ functional programming, and data-driven programming. · 9 unmodified lines
54Lua is intended to be used as a powerful, light-weight54Lua is intended to be used as a powerful, light-weight
55scripting language for any program that needs one.55scripting language for any program that needs one.
56Lua is implemented as a library, written in <em>clean C</em>,56Lua is implemented as a library, written in <em>clean C</em>,
57the common subset of ANSI&nbsp;C and C++.57the common subset of Standard&nbsp;C and C++.
58 58
59 59
60<p>60<p>
@@ -192,8 +192,9 @@ There are several convenient ways to create tables in Lua · 131 unmodified lines
192 192
193 193
194<p>194<p>
195We use the term <em>sequence</em> to denote a table where all195We use the term <em>sequence</em> to denote a table where
196integer keys comprise the set <em>{1..n}</em> for some integer <em>n</em>,196the set of all positive numeric keys is equal to <em>{1..n}</em>
197for some integer <em>n</em>,
197which is called the length of the sequence (see <a href="#3.4.6">&sect;3.4.6</a>).198which is called the length of the sequence (see <a href="#3.4.6">&sect;3.4.6</a>).
198 199
199 200
@@ -234,7 +235,7 @@ of a given value. · 34 unmodified lines
234<h2>2.2 &ndash; <a name="2.2">Environments and the Global Environment</a></h2>235<h2>2.2 &ndash; <a name="2.2">Environments and the Global Environment</a></h2>
235 236
236<p>237<p>
237As discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,238As will be discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
238any reference to a global name <code>var</code> is syntactically translated239any reference to a global name <code>var</code> is syntactically translated
239to <code>_ENV.var</code>.240to <code>_ENV.var</code>.
240Moreover, every chunk is compiled in the scope of an external241Moreover, every chunk is compiled in the scope of an external
@@ -1136,7 +1137,7 @@ The following strings denote other tokens: · 895 unmodified lines
1136<pre>1137<pre>
1137 + - * / % ^ #1138 + - * / % ^ #
1138 == ~= &lt;= &gt;= &lt; &gt; =1139 == ~= &lt;= &gt;= &lt; &gt; =
1139 ( ) { } [ ]1140 ( ) { } [ ] ::
1140 ; : , . .. ...1141 ; : , . .. ...
1141</pre>1142</pre>
1142 1143
@@ -1239,7 +1240,7 @@ Lua also accepts hexadecimal constants, · 96 unmodified lines
1239which start with <code>0x</code> or <code>0X</code>.1240which start with <code>0x</code> or <code>0X</code>.
1240Hexadecimal constants also accept an optional fractional part1241Hexadecimal constants also accept an optional fractional part
1241plus an optional binary exponent,1242plus an optional binary exponent,
1242marked by a letter '<code>e</code>' or '<code>E</code>'.1243marked by a letter '<code>p</code>' or '<code>P</code>'.
1243Examples of valid numerical constants are1244Examples of valid numerical constants are
1244 1245
1245<pre>1246<pre>
@@ -1531,12 +1532,13 @@ labels in Lua are considered statements too: · 285 unmodified lines
1531<pre>1532<pre>
1532 stat ::= <b>goto</b> Name1533 stat ::= <b>goto</b> Name
1533 stat ::= label1534 stat ::= label
1534 label ::= &lsquo;<b>@</b>&rsquo; Name &lsquo;<b>:</b>&rsquo;1535 label ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;
1535</pre>1536</pre>
1536 1537
1537<p>1538<p>
1538A label is visible in the entire block where it is defined1539A label is visible in the entire block where it is defined
1539(including nested blocks, but not nested functions).1540(including nested blocks, but not nested functions).
1541A function cannot have more than one label with a given name.
1540A goto may jump to any visible label as long as it does not1542A goto may jump to any visible label as long as it does not
1541enter into the scope of a local variable.1543enter into the scope of a local variable.
1542 1544
@@ -1995,10 +1997,17 @@ character is one byte). · 452 unmodified lines
1995 1997
1996 1998
1997<p>1999<p>
1998The length of a table <code>t</code> is only defined if the2000A program can modify the behavior of the length operator for
2001any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">&sect;2.4</a>).
2002
2003
2004<p>
2005Unless a <code>__len</code> metamethod is given,
2006the length of a table <code>t</code> is only defined if the
1999table is a <em>sequence</em>,2007table is a <em>sequence</em>,
2000that is,2008that is,
2001all its numeric keys comprise the set <em>{1..n}</em> for some integer <em>n</em>.2009the set of its positive numeric keys is equal to <em>{1..n}</em>
2010for some integer <em>n</em>.
2002In that case, <em>n</em> is its length.2011In that case, <em>n</em> is its length.
2003Note that a table like2012Note that a table like
2004 2013
@@ -2008,16 +2017,11 @@ Note that a table like · 3 unmodified lines
2008is not a sequence, because it has the key <code>4</code>2017is not a sequence, because it has the key <code>4</code>
2009but does not have the key <code>3</code>.2018but does not have the key <code>3</code>.
2010(So, there is no <em>n</em> such that the set <em>{1..n}</em> is equal2019(So, there is no <em>n</em> such that the set <em>{1..n}</em> is equal
2011to the set of numeric keys of that table.)2020to the set of positive numeric keys of that table.)
2012Note, however, that non-numeric keys do not interfere2021Note, however, that non-numeric keys do not interfere
2013with whether a table is a sequence.2022with whether a table is a sequence.
2014 2023
2015 2024
2016<p>
2017A program can modify the behavior of the length operator for
2018any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">&sect;2.4</a>).
2019
2020
2021 2025
2022 2026
2023 2027
@@ -2824,11 +2828,11 @@ It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newst · 800 unmodified lines
2824 return realloc(ptr, nsize);2828 return realloc(ptr, nsize);
2825 }2829 }
2826</pre><p>2830</pre><p>
2827Note that ANSI&nbsp;C ensures2831Note that Standard&nbsp;C ensures
2828that <code>free(NULL)</code> has no effect and that2832that <code>free(NULL)</code> has no effect and that
2829<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.2833<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
2830This code assumes that <code>realloc</code> does not fail when shrinking a block.2834This code assumes that <code>realloc</code> does not fail when shrinking a block.
2831ANSI&nbsp;C does not ensure this behavior,2835Standard&nbsp;C does not ensure this behavior,
2832but it seems a safe assumption.2836but it seems a safe assumption.
2833 2837
2834 2838
@@ -2864,11 +2868,6 @@ The value of <code>op</code> must be one of the following constants: · 29 unmodified lines
2864 2868
2865</ul>2869</ul>
2866 2870
2867<p>
2868When the operation is <code>LUA_OPUNM</code>,
2869the caller must push a <b>nil</b> value for the second operand.
2870
2871
2872 2871
2873 2872
2874 2873
@@ -5907,7 +5906,7 @@ as <code>return luaL_error(<em>args</em>)</code>. · 3032 unmodified lines
5907 5906
5908 5907
5909<hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p>5908<hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p>
5910<span class="apii">[-0, +(1/3), <em>m</em>]</span>5909<span class="apii">[-0, +3, <em>m</em>]</span>
5911<pre>int luaL_execresult (lua_State *L, int stat);</pre>5910<pre>int luaL_execresult (lua_State *L, int stat);</pre>
5912 5911
5913<p>5912<p>
@@ -6097,7 +6096,7 @@ It is implemented as the following macro: · 183 unmodified lines
6097 6096
6098<hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>6097<hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>
6099<span class="apii">[-0, +1, <em>m</em>]</span>6098<span class="apii">[-0, +1, <em>m</em>]</span>
6100<pre>int luaL_newlibtable (lua_State *L, const luaL_Reg *l);</pre>6099<pre>int luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre>
6101 6100
6102<p>6101<p>
6103Creates a new table with a size optimized6102Creates a new table with a size optimized
@@ -7471,7 +7470,7 @@ including if necessary a path and an extension. · 1367 unmodified lines
7471 7470
7472 7471
7473<p>7472<p>
7474This function is not supported by ANSI&nbsp;C.7473This function is not supported by Standard&nbsp;C.
7475As such, it is only available on some platforms7474As such, it is only available on some platforms
7476(Windows, Linux, Mac OS X, Solaris, BSD,7475(Windows, Linux, Mac OS X, Solaris, BSD,
7477plus other Unix systems that support the <code>dlfcn</code> standard).7476plus other Unix systems that support the <code>dlfcn</code> standard).
@@ -8098,15 +8097,13 @@ It provides all its functions inside the table <a name="pdf-table"><code>table</ · 620 unmodified lines
8098 8097
8099 8098
8100<p>8099<p>
8101Currently, all functions in the table library assume that the table8100Currently, all functions in the table library,
8102represents a list.
8103In particular, they all ignore non-numeric keys
8104in tables given as arguments.
8105All functions in the table library,
8106except <a href="#pdf-table.pack"><code>table.pack</code></a>,8101except <a href="#pdf-table.pack"><code>table.pack</code></a>,
8107may apply the length operator on the list.8102work on lists.
8108In that case, the list must be a proper sequence8103A list here means a proper sequence
8109or have a <code>__len</code> metamethod (see <a href="#3.4.6">&sect;3.4.6</a>).8104or a table with a <code>__len</code> metamethod (see <a href="#3.4.6">&sect;3.4.6</a>).
8105In particular, all functions ignore non-numeric keys
8106in lists given as arguments.
8110 8107
8111 8108
8112<p>8109<p>
@@ -8135,7 +8132,8 @@ If <code>i</code> is greater than <code>j</code>, returns the empty string. · 22 unmodified lines
8135 8132
8136<p>8133<p>
8137Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,8134Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,
8138shifting up other elements to open space, if necessary.8135shifting up the elements
8136<code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
8139The default value for <code>pos</code> is <code>#list+1</code>,8137The default value for <code>pos</code> is <code>#list+1</code>,
8140so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end8138so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
8141of list <code>t</code>.8139of list <code>t</code>.
@@ -8162,7 +8160,9 @@ if any parameter is <b>nil</b>. · 20 unmodified lines
8162 8160
8163<p>8161<p>
8164Removes from <code>list</code> the element at position <code>pos</code>,8162Removes from <code>list</code> the element at position <code>pos</code>,
8165shifting down other elements to close the space, if necessary.8163shifting down the elements
8164<code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>
8165and erasing element <code>list[#list]</code>.
8166Returns the value of the removed element.8166Returns the value of the removed element.
8167The default value for <code>pos</code> is <code>#list</code>,8167The default value for <code>pos</code> is <code>#list</code>,
8168so that a call <code>table.remove(t)</code> removes the last element8168so that a call <code>table.remove(t)</code> removes the last element
@@ -8177,12 +8177,12 @@ of list <code>t</code>. · 8 unmodified lines
8177 8177
8178<p>8178<p>
8179Sorts list elements in a given order, <em>in-place</em>,8179Sorts list elements in a given order, <em>in-place</em>,
8180from <code>table[1]</code> to <code>table[#list]</code>.8180from <code>list[1]</code> to <code>list[#list]</code>.
8181If <code>comp</code> is given,8181If <code>comp</code> is given,
8182then it must be a function that receives two list elements8182then it must be a function that receives two list elements
8183and returns true when the first element must come8183and returns true when the first element must come
8184before the second in the final order8184before the second in the final order
8185(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).8185(so that <code>not comp(list[i+1],list[i])</code> will be true after the sort).
8186If <code>comp</code> is not given,8186If <code>comp</code> is not given,
8187then the standard Lua operator <code>&lt;</code> is used instead.8187then the standard Lua operator <code>&lt;</code> is used instead.
8188 8188
@@ -8459,7 +8459,7 @@ Returns the angle <code>x</code> (given in degrees) in radians. · 270 unmodified lines
8459 8459
8460<p>8460<p>
8461This function is an interface to the simple8461This function is an interface to the simple
8462pseudo-random generator function <code>rand</code> provided by ANSI&nbsp;C.8462pseudo-random generator function <code>rand</code> provided by Standard&nbsp;C.
8463(No guarantees can be given for its statistical properties.)8463(No guarantees can be given for its statistical properties.)
8464 8464
8465 8465
@@ -9242,9 +9242,11 @@ this value is exactly <code>t2</code><em>-</em><code>t1</code>. · 776 unmodified lines
9242<p>9242<p>
9243This function is equivalent to the C&nbsp;function <code>system</code>.9243This function is equivalent to the C&nbsp;function <code>system</code>.
9244It passes <code>command</code> to be executed by an operating system shell.9244It passes <code>command</code> to be executed by an operating system shell.
9245It returns <b>true</b>9245Its first result is <b>true</b>
9246if the command terminated successfully.9246if the command terminated successfully,
9247Otherwise, it returns <b>nil</b> plus a string and a number,9247or <b>nil</b> otherwise.
9248After this first result
9249the function returns a string and a number,
9248as follows:9250as follows:
9249 9251
9250<ul>9252<ul>
@@ -10139,7 +10141,7 @@ Here is the complete syntax of Lua in extended BNF. · 888 unmodified lines
10139 10141
10140 retstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]10142 retstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
10141 10143
10142 label ::= &lsquo;<b>@</b>&rsquo; Name &lsquo;<b>:</b>&rsquo;10144 label ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;
10143 10145
10144 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]10146 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]
10145 10147
@@ -10191,9 +10193,9 @@ Here is the complete syntax of Lua in extended BNF. · 45 unmodified lines
10191 10193
10192 10194
10193<HR>10195<HR>
10194<SMALL>10196<SMALL CLASS="footer">
10195Last update:10197Last update:
10196Mon Jun 13 14:56:14 BRT 201110198Tue Jun 21 19:09:27 BRT 2011
10197</SMALL>10199</SMALL>
10198<!--10200<!--
10199Last change: revised for Lua 5.2.0 (beta)10201Last change: revised for Lua 5.2.0 (beta)
doc/readme.html+4−3
@@ -335,7 +335,7 @@ Here are the other changes introduced in Lua 5.2: · 334 unmodified lines
335<LI> new <CODE>lua_copy</CODE>335<LI> new <CODE>lua_copy</CODE>
336<LI> new <CODE>lua_absindex</CODE>336<LI> new <CODE>lua_absindex</CODE>
337<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>337<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
338<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API338<LI> <CODE>nparams</CODE> and <CODE>isvararg</CODE> available in debug API
339<LI> new <CODE>lua_Unsigned</CODE>339<LI> new <CODE>lua_Unsigned</CODE>
340</UL>340</UL>
341 341
@@ -350,6 +350,7 @@ Here are the other changes introduced in Lua 5.2: · 8 unmodified lines
350<LI> new hash for floats350<LI> new hash for floats
351<LI> handling of non-string error messages in the standalone interpreter351<LI> handling of non-string error messages in the standalone interpreter
352<LI> generational mode for garbage collection (experimental)352<LI> generational mode for garbage collection (experimental)
353<LI> NaN trick (experimental)
353</UL>354</UL>
354 355
355<H2><A NAME="license">License</A></H2>356<H2><A NAME="license">License</A></H2>
@@ -396,9 +397,9 @@ THE SOFTWARE. · 40 unmodified lines
396</BLOCKQUOTE>397</BLOCKQUOTE>
397 398
398<HR>399<HR>
399<SMALL>400<SMALL CLASS="footer">
400Last update:401Last update:
401Mon Jun 13 15:07:49 BRT 2011402Thu Jun 16 08:21:17 BRT 2011
402</SMALL>403</SMALL>
403<!--404<!--
404Last change: revised for Lua 5.2.0 (beta)405Last change: revised for Lua 5.2.0 (beta)
src/Makefile+25−23
@@ -7,13 +7,18 @@ · 6 unmodified lines
7PLAT= none7PLAT= none
8 8
9CC= gcc9CC= gcc
10CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(MYCFLAGS)10CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS)
11LIBS= -lm $(MYLIBS)11LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
12LIBS= -lm $(SYSLIBS) $(MYLIBS)
12 13
13AR= ar rcu14AR= ar rcu
14RANLIB= ranlib15RANLIB= ranlib
15RM= rm -f16RM= rm -f
16 17
18SYSCFLAGS=
19SYSLDFLAGS=
20SYSLIBS=
21
17MYCFLAGS=22MYCFLAGS=
18MYLDFLAGS=23MYLDFLAGS=
19MYLIBS=24MYLIBS=
@@ -23,7 +28,7 @@ MYLIBS= · 3 unmodified lines
23PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris28PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
24 29
25LUA_A= liblua.a30LUA_A= liblua.a
26CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \31CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
27 lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \32 lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
28 ltm.o lundump.o lvm.o lzio.o33 ltm.o lundump.o lvm.o lzio.o
29LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \34LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
@@ -53,10 +58,10 @@ $(LUA_A): $(CORE_O) $(LIB_O) · 23 unmodified lines
53 $(RANLIB) $@58 $(RANLIB) $@
54 59
55$(LUA_T): $(LUA_O) $(LUA_A)60$(LUA_T): $(LUA_O) $(LUA_A)
56 $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)61 $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
57 62
58$(LUAC_T): $(LUAC_O) $(LUA_A)63$(LUAC_T): $(LUAC_O) $(LUA_A)
59 $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)64 $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
60 65
61clean:66clean:
62 $(RM) $(ALL_T) $(ALL_O)67 $(RM) $(ALL_T) $(ALL_O)
@@ -68,12 +73,11 @@ echo: · 5 unmodified lines
68 @echo "PLAT= $(PLAT)"73 @echo "PLAT= $(PLAT)"
69 @echo "CC= $(CC)"74 @echo "CC= $(CC)"
70 @echo "CFLAGS= $(CFLAGS)"75 @echo "CFLAGS= $(CFLAGS)"
76 @echo "LDFLAGS= $(SYSLDFLAGS)"
77 @echo "LIBS= $(LIBS)"
71 @echo "AR= $(AR)"78 @echo "AR= $(AR)"
72 @echo "RANLIB= $(RANLIB)"79 @echo "RANLIB= $(RANLIB)"
73 @echo "RM= $(RM)"80 @echo "RM= $(RM)"
74 @echo "MYCFLAGS= $(MYCFLAGS)"
75 @echo "MYLDFLAGS= $(MYLDFLAGS)"
76 @echo "MYLIBS= $(MYLIBS)"
77 81
78# Convenience targets for popular platforms82# Convenience targets for popular platforms
79ALL= all83ALL= all
@@ -83,35 +87,35 @@ none: · 3 unmodified lines
83 @echo " $(PLATS)"87 @echo " $(PLATS)"
84 88
85aix:89aix:
86 $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"90 $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"
87 91
88ansi:92ansi:
89 $(MAKE) $(ALL) MYCFLAGS="-DLUA_ANSI"93 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI"
90 94
91bsd:95bsd:
92 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"96 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E"
93 97
94freebsd:98freebsd:
95 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"99 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline"
96 100
97generic: $(ALL)101generic: $(ALL)
98 102
99linux:103linux:
100 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline"104 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lncurses"
101 105
102macosx:106macosx:
103 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline"107 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline"
104 108
105mingw:109mingw:
106 $(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \110 $(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \
107 "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \111 "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
108 "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe112 "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
109 113
110posix:114posix:
111 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX"115 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
112 116
113solaris:117solaris:
114 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"118 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl"
115 119
116# list targets that do not create files (but not all makes understand .PHONY)120# list targets that do not create files (but not all makes understand .PHONY)
117.PHONY: all $(PLATS) default o a clean depend echo none121.PHONY: all $(PLATS) default o a clean depend echo none
@@ -128,7 +132,6 @@ lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ · 10 unmodified lines
128 lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \132 lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
129 lstring.h ltable.h lvm.h133 lstring.h ltable.h lvm.h
130lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h134lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h
131lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h
132ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h135ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
133ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \136ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
134 ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \137 ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \
@@ -144,14 +147,14 @@ lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ · 9 unmodified lines
144 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h147 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
145linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h148linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
146liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h149liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
147llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \150llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
148 lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h151 lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
149lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h152lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
150lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \153lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
151 ltm.h lzio.h lmem.h ldo.h lgc.h154 ltm.h lzio.h lmem.h ldo.h lgc.h
152loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h155loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
153lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \156lobject.o: lobject.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
154 lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h157 llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
155lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h158lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
156loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h159loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
157lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \160lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
@@ -178,4 +181,3 @@ lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ · 20 unmodified lines
178lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \181lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
179 lzio.h182 lzio.h
180 183
181# (end of Makefile)
src/lauxlib.c+6−7
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lauxlib.c,v 1.232 2011/05/03 16:01:57 roberto Exp $2** $Id: lauxlib.c,v 1.233 2011/06/16 14:11:04 roberto Exp $
3** Auxiliary functions for building Lua libraries3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -251,13 +251,12 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) { · 245 unmodified lines
251 else {251 else {
252 inspectstat(stat, what); /* interpret result */252 inspectstat(stat, what); /* interpret result */
253 if (*what == 'e' && stat == 0) /* successful termination? */253 if (*what == 'e' && stat == 0) /* successful termination? */
254 return luaL_fileresult(L, 1, NULL);254 lua_pushboolean(L, 1);
255 else { /* return nil,what,code */255 else
256 lua_pushnil(L);256 lua_pushnil(L);
257 lua_pushstring(L, what);257 lua_pushstring(L, what);
258 lua_pushinteger(L, stat);258 lua_pushinteger(L, stat);
259 return 3;259 return 3; /* return true/nil,what,code */
260 }
261 }260 }
262}261}
263 262
src/lauxlib.h+4−1
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lauxlib.h,v 1.116 2011/04/08 19:17:36 roberto Exp $2** $Id: lauxlib.h,v 1.117 2011/06/16 14:10:12 roberto Exp $
3** Auxiliary functions for building Lua libraries3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -164,6 +164,7 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); · 158 unmodified lines
164 164
165 165
166/* compatibility with old module system */166/* compatibility with old module system */
167#if defined(LUA_COMPAT_MODULE)
167 168
168LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,169LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
169 int sizehint);170 int sizehint);
@@ -172,6 +173,8 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, · 2 unmodified lines
172 173
173#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))174#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
174 175
176#endif
177
175 178
176#endif179#endif
177 180
src/lbaselib.c+15−6
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lbaselib.c,v 1.261 2011/05/26 16:09:40 roberto Exp $2** $Id: lbaselib.c,v 1.262 2011/06/16 14:12:24 roberto Exp $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -268,6 +268,13 @@ static int luaB_loadfile (lua_State *L) { · 262 unmodified lines
268** =======================================================268** =======================================================
269*/269*/
270 270
271
272typedef struct {
273char c;
274 const char *mode;
275} loaddata;
276
277
271/*278/*
272** check whether a chunk (prefix in 's') satisfies given 'mode'279** check whether a chunk (prefix in 's') satisfies given 'mode'
273** ('t' for text, 'b' for binary). Returns error message (also280** ('t' for text, 'b' for binary). Returns error message (also
@@ -298,7 +305,7 @@ static const char *checkrights (lua_State *L, const char *mode, const char *s) { · 24 unmodified lines
298*/305*/
299static const char *generic_reader (lua_State *L, void *ud, size_t *size) {306static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
300 const char *s;307 const char *s;
301 const char **mode = (const char **)ud;308 loaddata *ld = (loaddata *)ud;
302 luaL_checkstack(L, 2, "too many nested functions");309 luaL_checkstack(L, 2, "too many nested functions");
303 lua_pushvalue(L, 1); /* get function */310 lua_pushvalue(L, 1); /* get function */
304 lua_call(L, 0, 1); /* call it */311 lua_call(L, 0, 1); /* call it */
@@ -307,9 +314,9 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { · 2 unmodified lines
307 return NULL;314 return NULL;
308 }315 }
309 else if ((s = lua_tostring(L, -1)) != NULL) {316 else if ((s = lua_tostring(L, -1)) != NULL) {
310 if (*mode != NULL) { /* first time? */317 if (ld->mode != NULL) { /* first time? */
311 s = checkrights(L, *mode, s); /* check mode */318 s = checkrights(L, ld->mode, s); /* check mode */
312 *mode = NULL; /* to avoid further checks */319 ld->mode = NULL; /* to avoid further checks */
313 if (s) luaL_error(L, s);320 if (s) luaL_error(L, s);
314 }321 }
315 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */322 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
@@ -335,9 +342,11 @@ static int luaB_load (lua_State *L) { · 19 unmodified lines
335 }342 }
336 else { /* loading from a reader function */343 else { /* loading from a reader function */
337 const char *chunkname = luaL_optstring(L, 2, "=(load)");344 const char *chunkname = luaL_optstring(L, 2, "=(load)");
345 loaddata ld;
346 ld.mode = mode;
338 luaL_checktype(L, 1, LUA_TFUNCTION);347 luaL_checktype(L, 1, LUA_TFUNCTION);
339 lua_settop(L, RESERVEDSLOT); /* create reserved slot */348 lua_settop(L, RESERVEDSLOT); /* create reserved slot */
340 status = lua_load(L, generic_reader, &mode, chunkname);349 status = lua_load(L, generic_reader, &ld, chunkname);
341 }350 }
342 if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */351 if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */
343 lua_pushvalue(L, 4); /* environment for loaded function */352 lua_pushvalue(L, 4); /* environment for loaded function */
src/lbitlib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lbitlib.c,v 1.15 2010/12/17 13:26:38 roberto Exp $2** $Id: lbitlib.c,v 1.16 2011/06/20 16:35:23 roberto Exp $
3** Standard library for bitwise operations3** Standard library for bitwise operations
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -152,7 +152,7 @@ static int b_rrot (lua_State *L) { · 146 unmodified lines
152static int fieldargs (lua_State *L, int farg, int *width) {152static int fieldargs (lua_State *L, int farg, int *width) {
153 int f = luaL_checkint(L, farg);153 int f = luaL_checkint(L, farg);
154 int w = luaL_optint(L, farg + 1, 1);154 int w = luaL_optint(L, farg + 1, 1);
155 luaL_argcheck(L, 0 <= f, farg, "field cannot be netative");155 luaL_argcheck(L, 0 <= f, farg, "field cannot be negative");
156 luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");156 luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");
157 if (f + w > LUA_NBITS)157 if (f + w > LUA_NBITS)
158 luaL_error(L, "trying to access non-existent bits");158 luaL_error(L, "trying to access non-existent bits");
src/lctype.c+0−45
@@ -1,45 +0,0 @@
1/*
2** $Id: lctype.c,v 1.8 2009/11/19 19:06:52 roberto Exp $
3** 'ctype' functions for Lua
4** See Copyright Notice in lua.h
5*/
6
7#include <limits.h>
8
9#include "lctype.h"
10
11LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
12 0x00, /* EOZ */
13 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
15 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
16 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
17 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
18 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
19 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
20 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
21 0x04, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x25,
22 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25,
23 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25,
24 0x25, 0x25, 0x25, 0x04, 0x04, 0x04, 0x04, 0x05,
25 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05,
26 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
27 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
28 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45};
src/lctype.h+0−50
@@ -1,50 +0,0 @@
1/*
2** $Id: lctype.h,v 1.8 2009/11/19 19:06:52 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
11#include <limits.h>
12
13#include "lua.h"
14
15#include "llimits.h"
16
17
18#define ALPHABIT 0
19#define DIGITBIT 1
20#define PRINTBIT 2
21#define SPACEBIT 3
22#define XDIGITBIT 4
23#define UPPERBIT 5
24
25
26#define MASK(B) (1 << (B))
27
28
29/*
30** add 1 to char to allow index -1 (EOZ)
31*/
32#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
33
34/*
35** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
36*/
37#define lislalpha(c) testprop(c, MASK(ALPHABIT))
38#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
39#define lisupper(c) testprop(c, MASK(UPPERBIT))
40#define lisdigit(c) testprop(c, MASK(DIGITBIT))
41#define lisspace(c) testprop(c, MASK(SPACEBIT))
42#define lisprint(c) testprop(c, MASK(PRINTBIT))
43#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
44
45
46/* one more entry for 0 and one more for -1 (EOZ) */
47LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
48
49#endif
50
src/ldo.c+23−4
@@ -1,10 +1,11 @@
1/*1/*
2** $Id: ldo.c,v 2.95 2011/06/02 19:31:40 roberto Exp $2** $Id: ldo.c,v 2.97 2011/06/20 16:36:03 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*/
6 6
7 7
8#include <locale.h>
8#include <setjmp.h>9#include <setjmp.h>
9#include <stdlib.h>10#include <stdlib.h>
10#include <string.h>11#include <string.h>
@@ -612,8 +613,22 @@ struct SParser { /* data to `f_parser' */ · 601 unmodified lines
612 Mbuffer buff; /* dynamic structure used by the scanner */613 Mbuffer buff; /* dynamic structure used by the scanner */
613 Dyndata dyd; /* dynamic structures used by the parser */614 Dyndata dyd; /* dynamic structures used by the parser */
614 const char *name;615 const char *name;
616 TString *savedlocale;
615};617};
616 618
619
620/*
621** save current locale and set locale to "C" for calling the parser
622*/
623static Proto *callparser (lua_State *L, struct SParser *p, int c) {
624 const char *oldloc = setlocale(LC_ALL, NULL); /* get current locale */
625 p->savedlocale = luaS_new(L, oldloc); /* make a copy */
626 setsvalue2s(L, L->top - 1, p->savedlocale); /* anchor it */
627 (void)setlocale(LC_ALL, "C"); /* standard locale for parsing Lua files */
628 return luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
629}
630
631
617static void f_parser (lua_State *L, void *ud) {632static void f_parser (lua_State *L, void *ud) {
618 int i;633 int i;
619 Proto *tf;634 Proto *tf;
@@ -621,8 +636,7 @@ static void f_parser (lua_State *L, void *ud) { · 1 unmodified line
621 struct SParser *p = cast(struct SParser *, ud);636 struct SParser *p = cast(struct SParser *, ud);
622 int c = zgetc(p->z); /* read first character */637 int c = zgetc(p->z); /* read first character */
623 tf = (c == LUA_SIGNATURE[0])638 tf = (c == LUA_SIGNATURE[0])
624 ? luaU_undump(L, p->z, &p->buff, p->name)639 ? luaU_undump(L, p->z, &p->buff, p->name) : callparser(L, p, c);
625 : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
626 setptvalue2s(L, L->top, tf);640 setptvalue2s(L, L->top, tf);
627 incr_top(L);641 incr_top(L);
628 cl = luaF_newLclosure(L, tf);642 cl = luaF_newLclosure(L, tf);
@@ -635,8 +649,9 @@ static void f_parser (lua_State *L, void *ud) { · 6 unmodified lines
635int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {649int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {
636 struct SParser p;650 struct SParser p;
637 int status;651 int status;
652 setnilvalue(L->top++); /* reserve space for anchoring locale */
638 L->nny++; /* cannot yield during parsing */653 L->nny++; /* cannot yield during parsing */
639 p.z = z; p.name = name;654 p.z = z; p.name = name; p.savedlocale = NULL;
640 p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;655 p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;
641 p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;656 p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
642 p.dyd.label.arr = NULL; p.dyd.label.size = 0;657 p.dyd.label.arr = NULL; p.dyd.label.size = 0;
@@ -647,6 +662,10 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { · 4 unmodified lines
647 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);662 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);
648 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);663 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);
649 L->nny--;664 L->nny--;
665 if (p.savedlocale) /* locale was changed? */
666 (void)setlocale(LC_ALL, getstr(p.savedlocale)); /* restore old locale */
667 setobjs2s(L, L->top - 2, L->top - 1); /* remove reserved space */
668 --L->top;
650 return status;669 return status;
651}670}
652 671
src/liolib.c+128−139
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: liolib.c,v 2.99 2011/03/03 16:34:46 roberto Exp $2** $Id: liolib.c,v 2.100 2011/06/21 13:43:48 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*/
@@ -19,8 +19,6 @@ · 13 unmodified lines
19#include "lualib.h"19#include "lualib.h"
20 20
21 21
22#define MAX_SIZE_T (~(size_t)0)
23
24 22
25/*23/*
26** lua_popen spawns a new process connected to the current one through24** lua_popen spawns a new process connected to the current one through
@@ -51,11 +49,15 @@ · 24 unmodified lines
51#endif /* } */49#endif /* } */
52 50
53 51
54#define IO_INPUT 152#define IO_PREFIX "lua_io_"
55#define IO_OUTPUT 253#define IO_INPUT (IO_PREFIX "input")
54#define IO_OUTPUT (IO_PREFIX "output")
56 55
57 56
58static const char *const fnames[] = {"input", "output"};57typedef struct LStream {
58 FILE *f; /* stream */
59 lua_CFunction closef; /* to close stream (NULL for closed streams) */
60} LStream;
59 61
60 62
61static void fileerror (lua_State *L, int arg, const char *filename) {63static void fileerror (lua_State *L, int arg, const char *filename) {
@@ -64,16 +66,18 @@ static void fileerror (lua_State *L, int arg, const char *filename) { · 2 unmodified lines
64}66}
65 67
66 68
67#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))69#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
70
71#define isclosed(p) ((p)->closef == NULL)
68 72
69 73
70static int io_type (lua_State *L) {74static int io_type (lua_State *L) {
71 void *ud;75 LStream *p;
72 luaL_checkany(L, 1);76 luaL_checkany(L, 1);
73 ud = luaL_testudata(L, 1, LUA_FILEHANDLE);77 p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
74 if (ud == NULL)78 if (p == NULL)
75 lua_pushnil(L); /* not a file */79 lua_pushnil(L); /* not a file */
76 else if (*((FILE **)ud) == NULL)80 else if (isclosed(p))
77 lua_pushliteral(L, "closed file");81 lua_pushliteral(L, "closed file");
78 else82 else
79 lua_pushliteral(L, "file");83 lua_pushliteral(L, "file");
@@ -81,11 +85,22 @@ static int io_type (lua_State *L) { · 1 unmodified line
81}85}
82 86
83 87
88static int f_tostring (lua_State *L) {
89 LStream *p = tolstream(L);
90 if (isclosed(p))
91 lua_pushliteral(L, "file (closed)");
92 else
93 lua_pushfstring(L, "file (%p)", p->f);
94 return 1;
95}
96
97
84static FILE *tofile (lua_State *L) {98static FILE *tofile (lua_State *L) {
85 FILE **f = tofilep(L);99 LStream *p = tolstream(L);
86 if (*f == NULL)100 if (isclosed(p))
87 luaL_error(L, "attempt to use a closed file");101 luaL_error(L, "attempt to use a closed file");
88 return *f;102 lua_assert(p->f);
103 return p->f;
89}104}
90 105
91 106
@@ -94,40 +109,35 @@ static FILE *tofile (lua_State *L) { · 2 unmodified lines
94** before opening the actual file; so, if there is a memory error, the109** before opening the actual file; so, if there is a memory error, the
95** file is not left opened.110** file is not left opened.
96*/111*/
97static FILE **newprefile (lua_State *L) {112static LStream *newprefile (lua_State *L) {
98 FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));113 LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
99 *pf = NULL; /* file handle is currently `closed' */114 p->closef = NULL; /* mark file handle as 'closed' */
100 luaL_setmetatable(L, LUA_FILEHANDLE);115 luaL_setmetatable(L, LUA_FILEHANDLE);
101 return pf;116 return p;
102}117}
103 118
104 119
105static FILE **newfile (lua_State *L) {120static int aux_close (lua_State *L) {
106 FILE **pf = newprefile(L);121 LStream *p = tolstream(L);
107 lua_pushvalue(L, lua_upvalueindex(1)); /* set upvalue... */122 lua_CFunction cf = p->closef;
108 lua_setuservalue(L, -2); /* ... as environment for new file */123 p->closef = NULL; /* mark stream as closed */
109 return pf;124 return (*cf)(L); /* close it */
110}125}
111 126
112 127
113/*128static int io_close (lua_State *L) {
114** function to (not) close the standard files stdin, stdout, and stderr129 if (lua_isnone(L, 1)) /* no argument? */
115*/130 lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
116static int io_noclose (lua_State *L) {131 tofile(L); /* make sure argument is an open stream */
117 lua_pushnil(L);132 return aux_close(L);
118 lua_pushliteral(L, "cannot close standard file");
119 return 2;
120}133}
121 134
122 135
123/*136static int f_gc (lua_State *L) {
124** function to close 'popen' files137 LStream *p = tolstream(L);
125*/138 if (!isclosed(p) && p->f != NULL)
126static int io_pclose (lua_State *L) {139 aux_close(L); /* ignore closed and incompletely open files */
127 FILE **p = tofilep(L);140 return 0;
128 int stat = lua_pclose(L, *p);
129 *p = NULL; /* mark stream as closed (for GC) */
130 return luaL_execresult(L, stat);
131}141}
132 142
133 143
@@ -135,111 +145,90 @@ static int io_pclose (lua_State *L) { · 1 unmodified line
135** function to close regular files145** function to close regular files
136*/146*/
137static int io_fclose (lua_State *L) {147static int io_fclose (lua_State *L) {
138 FILE **p = tofilep(L);148 LStream *p = tolstream(L);
139 int ok = (fclose(*p) == 0);149 int res = fclose(p->f);
140 *p = NULL; /* mark stream as closed (for GC) */150 return luaL_fileresult(L, (res == 0), NULL);
141 return luaL_fileresult(L, ok, NULL);
142}151}
143 152
144 153
145static int aux_close (lua_State *L) {154static LStream *newfile (lua_State *L) {
146 lua_getuservalue(L, 1);155 LStream *p = newprefile(L);
147 lua_getfield(L, -1, "__close");156 p->f = NULL;
148 return (lua_tocfunction(L, -1))(L);157 p->closef = &io_fclose;
149}158 return p;
150
151
152static int io_close (lua_State *L) {
153 if (lua_isnone(L, 1))
154 lua_rawgeti(L, lua_upvalueindex(1), IO_OUTPUT);
155 tofile(L); /* make sure argument is a file */
156 return aux_close(L);
157}
158
159
160static int io_gc (lua_State *L) {
161 FILE *f = *tofilep(L);
162 if (f != NULL) /* ignore closed files */
163 aux_close(L);
164 return 0;
165}
166
167
168static int io_tostring (lua_State *L) {
169 FILE *f = *tofilep(L);
170 if (f == NULL)
171 lua_pushliteral(L, "file (closed)");
172 else
173 lua_pushfstring(L, "file (%p)", f);
174 return 1;
175}159}
176 160
177 161
178static int io_open (lua_State *L) {162static int io_open (lua_State *L) {
179 const char *filename = luaL_checkstring(L, 1);163 const char *filename = luaL_checkstring(L, 1);
180 const char *mode = luaL_optstring(L, 2, "r");164 const char *mode = luaL_optstring(L, 2, "r");
181 FILE **pf;165 LStream *p = newfile(L);
182 int i = 0;166 int i = 0;
183 /* check whether 'mode' matches '[rwa]%+?b?' */167 /* check whether 'mode' matches '[rwa]%+?b?' */
184 if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&168 if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
185 (mode[i] != '+' || ++i) && /* skip if char is '+' */169 (mode[i] != '+' || ++i) && /* skip if char is '+' */
186 (mode[i] != 'b' || ++i) && /* skip if char is 'b' */170 (mode[i] != 'b' || ++i) && /* skip if char is 'b' */
187 (mode[i] == '\0')))171 (mode[i] == '\0')))
188 luaL_error(L, "invalid mode " LUA_QL("%s")172 return luaL_error(L, "invalid mode " LUA_QL("%s")
189 " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);173 " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
190 pf = newfile(L);174 p->f = fopen(filename, mode);
191 *pf = fopen(filename, mode);175 return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
192 return (*pf == NULL) ? luaL_fileresult(L, 0, filename) : 1;
193}176}
194 177
195 178
196/*179/*
197** this function has a separated environment, which defines the180** function to close 'popen' files
198** correct __close for 'popen' files
199*/181*/
182static int io_pclose (lua_State *L) {
183 LStream *p = tolstream(L);
184 return luaL_execresult(L, lua_pclose(L, p->f));
185}
186
187
200static int io_popen (lua_State *L) {188static int io_popen (lua_State *L) {
201 const char *filename = luaL_checkstring(L, 1);189 const char *filename = luaL_checkstring(L, 1);
202 const char *mode = luaL_optstring(L, 2, "r");190 const char *mode = luaL_optstring(L, 2, "r");
203 FILE **pf = newfile(L);191 LStream *p = newprefile(L);
204 *pf = lua_popen(L, filename, mode);192 p->f = lua_popen(L, filename, mode);
205 return (*pf == NULL) ? luaL_fileresult(L, 0, filename) : 1;193 p->closef = &io_pclose;
194 return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
206}195}
207 196
208 197
209static int io_tmpfile (lua_State *L) {198static int io_tmpfile (lua_State *L) {
210 FILE **pf = newfile(L);199 LStream *p = newfile(L);
211 *pf = tmpfile();200 p->f = tmpfile();
212 return (*pf == NULL) ? luaL_fileresult(L, 0, NULL) : 1;201 return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
213}202}
214 203
215 204
216static FILE *getiofile (lua_State *L, int findex) {205static FILE *getiofile (lua_State *L, const char *findex) {
217 FILE *f;206 LStream *p;
218 lua_rawgeti(L, lua_upvalueindex(1), findex);207 lua_getfield(L, LUA_REGISTRYINDEX, findex);
219 f = *(FILE **)lua_touserdata(L, -1);208 p = (LStream *)lua_touserdata(L, -1);
220 if (f == NULL)209 if (isclosed(p))
221 luaL_error(L, "standard %s file is closed", fnames[findex - 1]);210 luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
222 return f;211 return p->f;
223}212}
224 213
225 214
226static int g_iofile (lua_State *L, int f, const char *mode) {215static int g_iofile (lua_State *L, const char *f, const char *mode) {
227 if (!lua_isnoneornil(L, 1)) {216 if (!lua_isnoneornil(L, 1)) {
228 const char *filename = lua_tostring(L, 1);217 const char *filename = lua_tostring(L, 1);
229 if (filename) {218 if (filename) {
230 FILE **pf = newfile(L);219 LStream *p = newfile(L);
231 *pf = fopen(filename, mode);220 p->f = fopen(filename, mode);
232 if (*pf == NULL)221 if (p->f == NULL)
233 fileerror(L, 1, filename);222 fileerror(L, 1, filename);
234 }223 }
235 else {224 else {
236 tofile(L); /* check that it's a valid file handle */225 tofile(L); /* check that it's a valid file handle */
237 lua_pushvalue(L, 1);226 lua_pushvalue(L, 1);
238 }227 }
239 lua_rawseti(L, lua_upvalueindex(1), f);228 lua_setfield(L, LUA_REGISTRYINDEX, f);
240 }229 }
241 /* return current value */230 /* return current value */
242 lua_rawgeti(L, lua_upvalueindex(1), f);231 lua_getfield(L, LUA_REGISTRYINDEX, f);
243 return 1;232 return 1;
244}233}
245 234
@@ -281,16 +270,16 @@ static int io_lines (lua_State *L) { · 35 unmodified lines
281 int toclose;270 int toclose;
282 if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */271 if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
283 if (lua_isnil(L, 1)) { /* no file name? */272 if (lua_isnil(L, 1)) { /* no file name? */
284 lua_rawgeti(L, lua_upvalueindex(1), IO_INPUT); /* get default input */273 lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
285 lua_replace(L, 1); /* put it at index 1 */274 lua_replace(L, 1); /* put it at index 1 */
286 tofile(L); /* check that it's a valid file handle */275 tofile(L); /* check that it's a valid file handle */
287 toclose = 0; /* do not close it after iteration */276 toclose = 0; /* do not close it after iteration */
288 }277 }
289 else { /* open a new file */278 else { /* open a new file */
290 const char *filename = luaL_checkstring(L, 1);279 const char *filename = luaL_checkstring(L, 1);
291 FILE **pf = newfile(L);280 LStream *p = newfile(L);
292 *pf = fopen(filename, "r");281 p->f = fopen(filename, "r");
293 if (*pf == NULL)282 if (p->f == NULL)
294 fileerror(L, 1, filename);283 fileerror(L, 1, filename);
295 lua_replace(L, 1); /* put file at index 1 */284 lua_replace(L, 1); /* put file at index 1 */
296 toclose = 1; /* close it after iteration */285 toclose = 1; /* close it after iteration */
@@ -350,6 +339,8 @@ static int read_line (lua_State *L, FILE *f, int chop) { · 53 unmodified lines
350}339}
351 340
352 341
342#define MAX_SIZE_T (~(size_t)0)
343
353static void read_all (lua_State *L, FILE *f) {344static void read_all (lua_State *L, FILE *f) {
354 size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */345 size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
355 luaL_Buffer b;346 luaL_Buffer b;
@@ -440,15 +431,15 @@ static int f_read (lua_State *L) { · 84 unmodified lines
440 431
441 432
442static int io_readline (lua_State *L) {433static int io_readline (lua_State *L) {
443 FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));434 LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
444 int i;435 int i;
445 int n = (int)lua_tointeger(L, lua_upvalueindex(2));436 int n = (int)lua_tointeger(L, lua_upvalueindex(2));
446 if (f == NULL) /* file is already closed? */437 if (isclosed(p)) /* file is already closed? */
447 luaL_error(L, "file is already closed");438 return luaL_error(L, "file is already closed");
448 lua_settop(L , 1);439 lua_settop(L , 1);
449 for (i = 1; i <= n; i++) /* push arguments to 'g_read' */440 for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
450 lua_pushvalue(L, lua_upvalueindex(3 + i));441 lua_pushvalue(L, lua_upvalueindex(3 + i));
451 n = g_read(L, f, 2); /* 'n' is number of results */442 n = g_read(L, p->f, 2); /* 'n' is number of results */
452 lua_assert(n > 0); /* should return at least a nil */443 lua_assert(n > 0); /* should return at least a nil */
453 if (!lua_isnil(L, -n)) /* read at least one value? */444 if (!lua_isnil(L, -n)) /* read at least one value? */
454 return n; /* return them */445 return n; /* return them */
@@ -494,7 +485,7 @@ static int io_write (lua_State *L) { · 39 unmodified lines
494 485
495 486
496static int f_write (lua_State *L) {487static int f_write (lua_State *L) {
497 FILE * f = tofile(L);488 FILE *f = tofile(L);
498 lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */489 lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
499 return g_write(L, f, 2);490 return g_write(L, f, 2);
500}491}
@@ -538,6 +529,9 @@ static int f_flush (lua_State *L) { · 37 unmodified lines
538}529}
539 530
540 531
532/*
533** functions for 'io' library
534*/
541static const luaL_Reg iolib[] = {535static const luaL_Reg iolib[] = {
542 {"close", io_close},536 {"close", io_close},
543 {"flush", io_flush},537 {"flush", io_flush},
@@ -554,6 +548,9 @@ static const luaL_Reg iolib[] = { · 10 unmodified lines
554};548};
555 549
556 550
551/*
552** methods for file handles
553*/
557static const luaL_Reg flib[] = {554static const luaL_Reg flib[] = {
558 {"close", io_close},555 {"close", io_close},
559 {"flush", f_flush},556 {"flush", f_flush},
@@ -562,8 +559,8 @@ static const luaL_Reg flib[] = { · 2 unmodified lines
562 {"seek", f_seek},559 {"seek", f_seek},
563 {"setvbuf", f_setvbuf},560 {"setvbuf", f_setvbuf},
564 {"write", f_write},561 {"write", f_write},
565 {"__gc", io_gc},562 {"__gc", f_gc},
566 {"__tostring", io_tostring},563 {"__tostring", f_tostring},
567 {NULL, NULL}564 {NULL, NULL}
568};565};
569 566
@@ -577,46 +574,38 @@ static void createmeta (lua_State *L) { · 7 unmodified lines
577}574}
578 575
579 576
580static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {577/*
581 *newprefile(L) = f;578** function to (not) close the standard files stdin, stdout, and stderr
582 if (k > 0) {579*/
583 lua_pushvalue(L, -1); /* copy new file */580static int io_noclose (lua_State *L) {
584 lua_rawseti(L, 1, k); /* add it to common upvalue */581 LStream *p = tolstream(L);
585 }582 p->closef = &io_noclose; /* keep file opened */
586 lua_pushvalue(L, 3); /* get environment for default files */583 lua_pushnil(L);
587 lua_setuservalue(L, -2); /* set it as environment for file */584 lua_pushliteral(L, "cannot close standard file");
588 lua_setfield(L, 2, fname); /* add file to module */585 return 2;
589}586}
590 587
591 588
592/*589static void createstdfile (lua_State *L, FILE *f, const char *k,
593** pushes a new table with {__close = cls}590 const char *fname) {
594*/591 LStream *p = newprefile(L);
595static void newenv (lua_State *L, lua_CFunction cls) {592 p->f = f;
596 lua_createtable(L, 0, 1);593 p->closef = &io_noclose;
597 lua_pushcfunction(L, cls);594 if (k != NULL) {
598 lua_setfield(L, -2, "__close");595 lua_pushvalue(L, -1);
596 lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
597 }
598 lua_setfield(L, -2, fname); /* add file to module */
599}599}
600 600
601 601
602LUAMOD_API int luaopen_io (lua_State *L) {602LUAMOD_API int luaopen_io (lua_State *L) {
603 lua_settop(L, 0);603 luaL_newlib(L, iolib); /* new module */
604 createmeta(L);604 createmeta(L);
605 /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
606 newenv(L, io_fclose); /* upvalue for all io functions at index 1 */
607 luaL_newlibtable(L, iolib); /* new module at index 2 */
608 lua_pushvalue(L, 1); /* copy of env to be consumed by 'setfuncs' */
609 luaL_setfuncs(L, iolib, 1);
610 /* create (and set) default files */605 /* create (and set) default files */
611 newenv(L, io_noclose); /* environment for default files at index 3 */
612 createstdfile(L, stdin, IO_INPUT, "stdin");606 createstdfile(L, stdin, IO_INPUT, "stdin");
613 createstdfile(L, stdout, IO_OUTPUT, "stdout");607 createstdfile(L, stdout, IO_OUTPUT, "stdout");
614 createstdfile(L, stderr, 0, "stderr");608 createstdfile(L, stderr, NULL, "stderr");
615 lua_pop(L, 1); /* pop environment for default files */
616 lua_getfield(L, 2, "popen");
617 newenv(L, io_pclose); /* create environment for 'popen' streams */
618 lua_setupvalue(L, -2, 1); /* set it as upvalue for 'popen' */
619 lua_pop(L, 1); /* pop 'popen' */
620 return 1;609 return 1;
621}610}
622 611
src/llex.c+43−59
@@ -1,11 +1,11 @@
1/*1/*
2** $Id: llex.c,v 2.47 2011/05/03 15:51:16 roberto Exp $2** $Id: llex.c,v 2.50 2011/06/20 16:52:48 roberto Exp $
3** Lexical Analyzer3** Lexical Analyzer
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
7 7
8#include <locale.h>8#include <ctype.h>
9#include <string.h>9#include <string.h>
10 10
11#define llex_c11#define llex_c
@@ -13,7 +13,6 @@ · 1 unmodified line
13 13
14#include "lua.h"14#include "lua.h"
15 15
16#include "lctype.h"
17#include "ldo.h"16#include "ldo.h"
18#include "llex.h"17#include "llex.h"
19#include "lobject.h"18#include "lobject.h"
@@ -38,7 +37,7 @@ static const char *const luaX_tokens [] = { · 18 unmodified lines
38 "end", "false", "for", "function", "goto", "if",37 "end", "false", "for", "function", "goto", "if",
39 "in", "local", "nil", "not", "or", "repeat",38 "in", "local", "nil", "not", "or", "repeat",
40 "return", "then", "true", "until", "while",39 "return", "then", "true", "until", "while",
41 "..", "...", "==", ">=", "<=", "~=", "<eof>",40 "..", "...", "==", ">=", "<=", "~=", "::", "<eof>",
42 "<number>", "<name>", "<string>"41 "<number>", "<name>", "<string>"
43};42};
44 43
@@ -75,7 +74,7 @@ void luaX_init (lua_State *L) { · 30 unmodified lines
75const char *luaX_token2str (LexState *ls, int token) {74const char *luaX_token2str (LexState *ls, int token) {
76 if (token < FIRST_RESERVED) {75 if (token < FIRST_RESERVED) {
77 lua_assert(token == cast(unsigned char, token));76 lua_assert(token == cast(unsigned char, token));
78 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :77 return (isprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
79 luaO_pushfstring(ls->L, "char(%d)", token);78 luaO_pushfstring(ls->L, "char(%d)", token);
80 }79 }
81 else {80 else {
@@ -185,52 +184,24 @@ static int check_next (LexState *ls, const char *set) { · 103 unmodified lines
185}184}
186 185
187 186
188/*
189** change all characters 'from' in buffer to 'to'
190*/
191static 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
203 187
204#define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)188#define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
205 189
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*/
210static 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
221 190
222/* LUA_NUMBER */191/* LUA_NUMBER */
223static void read_numeral (LexState *ls, SemInfo *seminfo) {192static void read_numeral (LexState *ls, SemInfo *seminfo) {
224 lua_assert(lisdigit(ls->current));193 lua_assert(isdigit(ls->current));
225 do {194 do {
226 save_and_next(ls);195 save_and_next(ls);
227 if (check_next(ls, "EePp")) /* exponent part? */196 if (check_next(ls, "EePp")) /* exponent part? */
228 check_next(ls, "+-"); /* optional exponent sign */197 check_next(ls, "+-"); /* optional exponent sign */
229 } while (lislalnum(ls->current) || ls->current == '.');198 } while (isalnum(ls->current) || ls->current == '.');
230 save(ls, '\0');199 save(ls, '\0');
231 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */200 if (!luaO_str2d(luaZ_buffer(ls->buff),
232 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */201 luaZ_bufflen(ls->buff) - 1,
233 trydecpoint(ls, seminfo); /* try to update decimal point separator */202 &seminfo->r)) /* format error? */
203 lexerror(ls, "malformed number", TK_NUMBER);
204
234}205}
235 206
236 207
@@ -287,25 +258,32 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { · 50 unmodified lines
287 258
288 259
289static int readhexaesc (LexState *ls) {260static int readhexaesc (LexState *ls) {
290 int c1, c2 = EOZ;261 int c1 = next(ls);
291 if (!lisxdigit(c1 = next(ls)) || !lisxdigit(c2 = next(ls))) {262 int c2 = EOZ;
292 luaZ_resetbuffer(ls->buff); /* prepare error message */263 if (isxdigit(c1)) {
293 save(ls, '\\'); save(ls, 'x');264 c2 = next(ls);
294 if (c1 != EOZ) save(ls, c1);265 if (isxdigit(c2))
295 if (c2 != EOZ) save(ls, c2);266 return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2);
296 lexerror(ls, "hexadecimal digit expected", TK_STRING);267 /* else go through to error */
297 }268 }
298 return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2);269 luaZ_resetbuffer(ls->buff); /* prepare error message */
270 save(ls, '\\'); save(ls, 'x');
271 if (c1 != EOZ) save(ls, c1);
272 if (c2 != EOZ) save(ls, c2);
273 lexerror(ls, "hexadecimal digit expected", TK_STRING);
274 return 0; /* to avoid warnings */
299}275}
300 276
301 277
302static int readdecesc (LexState *ls) {278static int readdecesc (LexState *ls) {
303 int c1 = ls->current, c2, c3;279 int c1 = ls->current; /* first char must be a digit */
304 int c = c1 - '0';280 int c2 = next(ls); /* read second char */
305 if (lisdigit(c2 = next(ls))) {281 int c = c1 - '0'; /* partial result */
306 c = 10*c + c2 - '0';282 if (isdigit(c2)) {
307 if (lisdigit(c3 = next(ls))) {283 int c3 = next(ls); /* read third char */
308 c = 10*c + c3 - '0';284 c = 10*c + c2 - '0'; /* update result */
285 if (isdigit(c3)) {
286 c = 10*c + c3 - '0'; /* update result */
309 if (c > UCHAR_MAX) {287 if (c > UCHAR_MAX) {
310 luaZ_resetbuffer(ls->buff); /* prepare error message */288 luaZ_resetbuffer(ls->buff); /* prepare error message */
311 save(ls, '\\');289 save(ls, '\\');
@@ -349,14 +327,14 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 37 unmodified lines
349 case EOZ: continue; /* will raise an error next loop */327 case EOZ: continue; /* will raise an error next loop */
350 case '*': { /* skip following span of spaces */328 case '*': { /* skip following span of spaces */
351 next(ls); /* skip the '*' */329 next(ls); /* skip the '*' */
352 while (lisspace(ls->current)) {330 while (isspace(ls->current)) {
353 if (currIsNewline(ls)) inclinenumber(ls);331 if (currIsNewline(ls)) inclinenumber(ls);
354 else next(ls);332 else next(ls);
355 }333 }
356 continue; /* do not save 'c' */334 continue; /* do not save 'c' */
357 }335 }
358 default: {336 default: {
359 if (!lisdigit(ls->current))337 if (!isdigit(ls->current))
360 c = ls->current; /* handles \\, \", \', and \? */338 c = ls->current; /* handles \\, \", \', and \? */
361 else /* digital escape \ddd */339 else /* digital escape \ddd */
362 c = readdecesc(ls);340 c = readdecesc(ls);
@@ -437,6 +415,11 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 74 unmodified lines
437 if (ls->current != '=') return '~';415 if (ls->current != '=') return '~';
438 else { next(ls); return TK_NE; }416 else { next(ls); return TK_NE; }
439 }417 }
418 case ':': {
419 next(ls);
420 if (ls->current != ':') return ':';
421 else { next(ls); return TK_DBCOLON; }
422 }
440 case '"': case '\'': { /* short literal strings */423 case '"': case '\'': { /* short literal strings */
441 read_string(ls, ls->current, seminfo);424 read_string(ls, ls->current, seminfo);
442 return TK_STRING;425 return TK_STRING;
@@ -448,7 +431,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 5 unmodified lines
448 return TK_DOTS; /* '...' */431 return TK_DOTS; /* '...' */
449 else return TK_CONCAT; /* '..' */432 else return TK_CONCAT; /* '..' */
450 }433 }
451 else if (!lisdigit(ls->current)) return '.';434 else if (!isdigit(ls->current)) return '.';
452 /* else go through */435 /* else go through */
453 }436 }
454 case '0': case '1': case '2': case '3': case '4':437 case '0': case '1': case '2': case '3': case '4':
@@ -460,11 +443,12 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 5 unmodified lines
460 return TK_EOS;443 return TK_EOS;
461 }444 }
462 default: {445 default: {
463 if (lislalpha(ls->current)) { /* identifier or reserved word? */446 if (isalpha(ls->current) || ls->current == '_') {
447 /* identifier or reserved word */
464 TString *ts;448 TString *ts;
465 do {449 do {
466 save_and_next(ls);450 save_and_next(ls);
467 } while (lislalnum(ls->current));451 } while (isalnum(ls->current) || ls->current == '_');
468 ts = luaX_newstring(ls, luaZ_buffer(ls->buff),452 ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
469 luaZ_bufflen(ls->buff));453 luaZ_bufflen(ls->buff));
470 seminfo->ts = ts;454 seminfo->ts = ts;
src/llex.h+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: llex.h,v 1.70 2011/05/03 15:51:16 roberto Exp $2** $Id: llex.h,v 1.71 2011/06/20 16:52:48 roberto Exp $
3** Lexical Analyzer3** Lexical Analyzer
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -26,7 +26,7 @@ enum RESERVED { · 20 unmodified lines
26 TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,26 TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
27 TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,27 TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
28 /* other terminal symbols */28 /* other terminal symbols */
29 TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_EOS,29 TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS,
30 TK_NUMBER, TK_NAME, TK_STRING30 TK_NUMBER, TK_NAME, TK_STRING
31};31};
32 32
src/lobject.c+11−11
@@ -1,9 +1,10 @@
1/*1/*
2** $Id: lobject.c,v 2.49 2011/05/31 18:24:36 roberto Exp $2** $Id: lobject.c,v 2.51 2011/06/18 17:25:15 roberto Exp $
3** Some generic functions over Lua objects3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
7#include <ctype.h>
7#include <stdarg.h>8#include <stdarg.h>
8#include <stdio.h>9#include <stdio.h>
9#include <stdlib.h>10#include <stdlib.h>
@@ -14,7 +15,6 @@ · 4 unmodified lines
14 15
15#include "lua.h"16#include "lua.h"
16 17
17#include "lctype.h"
18#include "ldebug.h"18#include "ldebug.h"
19#include "ldo.h"19#include "ldo.h"
20#include "lmem.h"20#include "lmem.h"
@@ -85,9 +85,9 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { · 64 unmodified lines
85 85
86 86
87int luaO_hexavalue (int c) {87int luaO_hexavalue (int c) {
88 if (lisdigit(c)) return c - '0';88 lua_assert(isxdigit(c));
89 else if (lisupper(c)) return c - 'A' + 10;89 if (isdigit(c)) return c - '0';
90 else return c - 'a' + 10;90 else return toupper(c) - 'A' + 10;
91}91}
92 92
93 93
@@ -104,8 +104,8 @@ static int isneg (const char **s) { · 10 unmodified lines
104 104
105 105
106static lua_Number readhexa (const char **s, lua_Number r, int *count) {106static lua_Number readhexa (const char **s, lua_Number r, int *count) {
107 while (lisxdigit(cast_uchar(**s))) { /* read integer part */107 while (isxdigit(cast_uchar(**s))) { /* read integer part */
108 r = (r * 16.0) + (double)luaO_hexavalue(*(*s)++);108 r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++)));
109 (*count)++;109 (*count)++;
110 }110 }
111 return r;111 return r;
@@ -121,7 +121,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 9 unmodified lines
121 int e = 0, i = 0;121 int e = 0, i = 0;
122 int neg = 0; /* 1 if number is negative */122 int neg = 0; /* 1 if number is negative */
123 *endptr = cast(char *, s); /* nothing is valid yet */123 *endptr = cast(char *, s); /* nothing is valid yet */
124 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */124 while (isspace(cast_uchar(*s))) s++; /* skip initial spaces */
125 neg = isneg(&s); /* check signal */125 neg = isneg(&s); /* check signal */
126 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */126 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
127 return 0.0; /* invalid format (no '0x') */127 return 0.0; /* invalid format (no '0x') */
@@ -140,9 +140,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 12 unmodified lines
140 int neg1;140 int neg1;
141 s++; /* skip 'p' */141 s++; /* skip 'p' */
142 neg1 = isneg(&s); /* signal */142 neg1 = isneg(&s); /* signal */
143 if (!lisdigit(cast_uchar(*s)))143 if (!isdigit(cast_uchar(*s)))
144 goto ret; /* must have at least one digit */144 goto ret; /* must have at least one digit */
145 while (lisdigit(cast_uchar(*s))) /* read exponent */145 while (isdigit(cast_uchar(*s))) /* read exponent */
146 exp1 = exp1 * 10 + *(s++) - '0';146 exp1 = exp1 * 10 + *(s++) - '0';
147 if (neg1) exp1 = -exp1;147 if (neg1) exp1 = -exp1;
148 e += exp1;148 e += exp1;
@@ -163,7 +163,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { · 14 unmodified lines
163 else163 else
164 *result = lua_str2number(s, &endptr);164 *result = lua_str2number(s, &endptr);
165 if (endptr == s) return 0; /* nothing recognized */165 if (endptr == s) return 0; /* nothing recognized */
166 while (lisspace(cast_uchar(*endptr))) endptr++;166 while (isspace(cast_uchar(*endptr))) endptr++;
167 return (endptr == s + len); /* OK if no trailing characters */167 return (endptr == s + len); /* OK if no trailing characters */
168}168}
169 169
src/loslib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: loslib.c,v 1.34 2011/03/03 16:34:46 roberto Exp $2** $Id: loslib.c,v 1.35 2011/06/20 16:50:59 roberto Exp $
3** Standard Operating System library3** Standard Operating System library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -21,7 +21,7 @@ · 15 unmodified lines
21 21
22 22
23/*23/*
24** list of valid conversion specifiers @* for the 'strftime' function24** list of valid conversion specifiers for the 'strftime' function
25*/25*/
26#if !defined(LUA_STRFTIMEOPTIONS)26#if !defined(LUA_STRFTIMEOPTIONS)
27 27
src/lparser.c+31−16
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lparser.c,v 2.109 2011/05/02 17:33:01 roberto Exp $2** $Id: lparser.c,v 2.111 2011/06/20 16:52:48 roberto Exp $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -367,7 +367,7 @@ static int findlabel (LexState *ls, int g) { · 361 unmodified lines
367 /* check labels in current block for a match */367 /* check labels in current block for a match */
368 for (i = bl->firstlabel; i < dyd->label.n; i++) {368 for (i = bl->firstlabel; i < dyd->label.n; i++) {
369 Labeldesc *lb = &dyd->label.arr[i];369 Labeldesc *lb = &dyd->label.arr[i];
370 if (eqstr(lb->name, gt->name)) { /* correct label? */370 if (eqstr(lb->name, gt->name) && lb->pc != -1) { /* correct label? */
371 if (gt->nactvar > lb->nactvar &&371 if (gt->nactvar > lb->nactvar &&
372 (bl->upval || dyd->label.n > bl->firstlabel))372 (bl->upval || dyd->label.n > bl->firstlabel))
373 luaK_patchclose(ls->fs, gt->pc, lb->nactvar);373 luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
@@ -411,7 +411,7 @@ static void findgotos (LexState *ls, Labeldesc *lb) { · 37 unmodified lines
411/*411/*
412** "export" pending gotos to outer level, to check them against412** "export" pending gotos to outer level, to check them against
413** outer labels; if the block being exited has upvalues, and413** outer labels; if the block being exited has upvalues, and
414** the goto exists the scope of any variable (which can be the414** the goto exits the scope of any variable (which can be the
415** upvalue), close those variables being exited.415** upvalue), close those variables being exited.
416*/416*/
417static void movegotosout (FuncState *fs, BlockCnt *bl) {417static void movegotosout (FuncState *fs, BlockCnt *bl) {
@@ -460,12 +460,18 @@ static void breaklabel (LexState *ls) { · 42 unmodified lines
460static void undefgoto (LexState *ls, Labeldesc *gt) {460static void undefgoto (LexState *ls, Labeldesc *gt) {
461 const char *msg = (gt->name->tsv.reserved > 0)461 const char *msg = (gt->name->tsv.reserved > 0)
462 ? "<%s> at line %d not inside a loop"462 ? "<%s> at line %d not inside a loop"
463 : "label " LUA_QS " (<goto> at line %d) undefined";463 : "no visible label " LUA_QS " for <goto> at line %d";
464 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);464 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
465 semerror(ls, msg);465 semerror(ls, msg);
466}466}
467 467
468 468
469static 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
469static void leaveblock (FuncState *fs) {475static void leaveblock (FuncState *fs) {
470 BlockCnt *bl = fs->bl;476 BlockCnt *bl = fs->bl;
471 LexState *ls = fs->ls;477 LexState *ls = fs->ls;
@@ -481,7 +487,7 @@ static void leaveblock (FuncState *fs) { · 9 unmodified lines
481 removevars(fs, bl->nactvar);487 removevars(fs, bl->nactvar);
482 lua_assert(bl->nactvar == fs->nactvar);488 lua_assert(bl->nactvar == fs->nactvar);
483 fs->freereg = fs->nactvar; /* free registers */489 fs->freereg = fs->nactvar; /* free registers */
484 ls->dyd->label.n = bl->firstlabel; /* remove local labels */490 invalidatelabels(&ls->dyd->label, bl->firstlabel); /* remove local labels */
485 if (bl->previous) /* inner block? */491 if (bl->previous) /* inner block? */
486 movegotosout(fs, bl); /* update pending gotos to outer block */492 movegotosout(fs, bl); /* update pending gotos to outer block */
487 else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */493 else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
@@ -526,6 +532,7 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { · 38 unmodified lines
526 fs->nlocvars = 0;532 fs->nlocvars = 0;
527 fs->nactvar = 0;533 fs->nactvar = 0;
528 fs->firstlocal = ls->dyd->actvar.n;534 fs->firstlocal = ls->dyd->actvar.n;
535 fs->firstlabel = ls->dyd->label.n;
529 fs->bl = NULL;536 fs->bl = NULL;
530 f = luaF_newproto(L);537 f = luaF_newproto(L);
531 fs->f = f;538 fs->f = f;
@@ -548,6 +555,7 @@ static void close_func (LexState *ls) { · 16 unmodified lines
548 Proto *f = fs->f;555 Proto *f = fs->f;
549 luaK_ret(fs, 0, 0); /* final return */556 luaK_ret(fs, 0, 0); /* final return */
550 leaveblock(fs);557 leaveblock(fs);
558 ls->dyd->label.n = fs->firstlabel; /* remove labels */
551 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);559 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
552 f->sizecode = fs->pc;560 f->sizecode = fs->pc;
553 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);561 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
@@ -1185,13 +1193,11 @@ static void gotostat (LexState *ls, TString *label, int line) { · 631 unmodified lines
1185}1193}
1186 1194
1187 1195
1188static void labelstat (LexState *ls, TString *label, int line) {1196/* check for repeated labels on the same function */
1189 /* label -> '@' NAME ':' */1197static void checkrepeated (LexState *ls, FuncState *fs, Labellist *ll,
1190 FuncState *fs = ls->fs;1198 TString *label) {
1191 Labellist *ll = &ls->dyd->label;1199 int i;
1192 int l, i; /* index of new label being created */1200 for (i = fs->firstlabel; i < ll->n; i++) {
1193 /* check for repeated labels on the same block */
1194 for (i = ls->fs->bl->firstlabel; i < ll->n; i++) {
1195 if (eqstr(label, ll->arr[i].name)) {1201 if (eqstr(label, ll->arr[i].name)) {
1196 const char *msg = luaO_pushfstring(ls->L, 1202 const char *msg = luaO_pushfstring(ls->L,
1197 "label " LUA_QS " already defined on line %d",1203 "label " LUA_QS " already defined on line %d",
@@ -1199,11 +1205,20 @@ static void labelstat (LexState *ls, TString *label, int line) { · 1 unmodified line
1199 semerror(ls, msg);1205 semerror(ls, msg);
1200 }1206 }
1201 }1207 }
1202 checknext(ls, ':'); /* skip colon */1208}
1209
1210
1211static void labelstat (LexState *ls, TString *label, int line) {
1212 /* label -> '::' NAME '::' */
1213 FuncState *fs = ls->fs;
1214 Labellist *ll = &ls->dyd->label;
1215 int l; /* index of new label being created */
1216 checkrepeated(ls, fs, ll, label); /* check for repeated labels */
1217 checknext(ls, TK_DBCOLON); /* skip double colon */
1203 /* create new entry for this label */1218 /* create new entry for this label */
1204 l = newlabelentry(ls, ll, label, line, fs->pc);1219 l = newlabelentry(ls, ll, label, line, fs->pc);
1205 /* skip other no-op statements */1220 /* skip other no-op statements */
1206 while (ls->t.token == ';' || ls->t.token == '@')1221 while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
1207 statement(ls);1222 statement(ls);
1208 if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */1223 if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
1209 /* assume that locals are already out of scope */1224 /* assume that locals are already out of scope */
@@ -1537,8 +1552,8 @@ static void statement (LexState *ls) { · 327 unmodified lines
1537 localstat(ls);1552 localstat(ls);
1538 break;1553 break;
1539 }1554 }
1540 case '@': { /* stat -> label */1555 case TK_DBCOLON: { /* stat -> label */
1541 luaX_next(ls); /* skip '@' */1556 luaX_next(ls); /* skip double colon */
1542 labelstat(ls, str_checkname(ls), line);1557 labelstat(ls, str_checkname(ls), line);
1543 break;1558 break;
1544 }1559 }
src/lparser.h+3−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp $2** $Id: lparser.h,v 1.69 2011/06/16 16:36:39 roberto Exp $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -62,7 +62,7 @@ typedef struct Vardesc { · 56 unmodified lines
62/* description of pending goto statements and label statements */62/* description of pending goto statements and label statements */
63typedef struct Labeldesc {63typedef struct Labeldesc {
64 TString *name; /* label identifier */64 TString *name; /* label identifier */
65 int pc; /* position in code */65 int pc; /* position in code (for labels, -1 means out of scope) */
66 int line; /* line where it appeared */66 int line; /* line where it appeared */
67 lu_byte nactvar; /* local level where it appears in current block */67 lu_byte nactvar; /* local level where it appears in current block */
68} Labeldesc;68} Labeldesc;
@@ -107,6 +107,7 @@ typedef struct FuncState { · 38 unmodified lines
107 int nk; /* number of elements in `k' */107 int nk; /* number of elements in `k' */
108 int np; /* number of elements in `p' */108 int np; /* number of elements in `p' */
109 int firstlocal; /* index of first local var of this function */109 int firstlocal; /* index of first local var of this function */
110 int firstlabel; /* index of first label of this function */
110 short nlocvars; /* number of elements in `locvars' */111 short nlocvars; /* number of elements in `locvars' */
111 lu_byte nactvar; /* number of active local variables */112 lu_byte nactvar; /* number of active local variables */
112 lu_byte nups; /* number of upvalues */113 lu_byte nups; /* number of upvalues */
src/lstrlib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lstrlib.c,v 1.168 2011/06/09 18:22:47 roberto Exp $2** $Id: lstrlib.c,v 1.169 2011/06/16 14:14:05 roberto Exp $
3** Standard library for string operations and pattern-matching3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -45,7 +45,7 @@ static int str_len (lua_State *L) { · 39 unmodified lines
45/* translate a relative string position: negative means back from end */45/* translate a relative string position: negative means back from end */
46static size_t posrelat (ptrdiff_t pos, size_t len) {46static size_t posrelat (ptrdiff_t pos, size_t len) {
47 if (pos >= 0) return (size_t)pos;47 if (pos >= 0) return (size_t)pos;
48 else if (-(size_t)pos > len) return 0;48 else if (0u - (size_t)pos > len) return 0;
49 else return len - ((size_t)-pos) + 1;49 else return len - ((size_t)-pos) + 1;
50}50}
51 51
src/ltable.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ltable.c,v 2.59 2011/06/09 18:23:27 roberto Exp $2** $Id: ltable.c,v 2.60 2011/06/16 14:14:31 roberto Exp $
3** Lua tables (hash)3** Lua tables (hash)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -88,7 +88,7 @@ static Node *hashnum (const Table *t, lua_Number n) { · 82 unmodified lines
88 int i;88 int i;
89 luai_hashnum(i, n);89 luai_hashnum(i, n);
90 if (i < 0) {90 if (i < 0) {
91 if ((unsigned int)i == -(unsigned int)i)91 if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
92 i = 0; /* handle INT_MIN */92 i = 0; /* handle INT_MIN */
93 i = -i; /* must be a positive value */93 i = -i; /* must be a positive value */
94 }94 }
src/lua.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lua.c,v 1.199 2011/05/26 16:09:40 roberto Exp $2** $Id: lua.c,v 1.200 2011/06/16 14:30:58 roberto Exp $
3** Lua stand-alone interpreter3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -183,7 +183,7 @@ static int docall (lua_State *L, int narg, int nres) { · 177 unmodified lines
183 183
184 184
185static void print_version (void) {185static void print_version (void) {
186 luai_writestring(LUA_COPYRIGHT, sizeof(LUA_COPYRIGHT));186 luai_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
187 luai_writeline();187 luai_writeline();
188}188}
189 189
src/luac.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: luac.c,v 1.66 2011/05/10 01:08:57 lhf Exp $2** $Id: luac.c,v 1.67 2011/06/21 12:29:00 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*/
@@ -162,7 +162,7 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 156 unmodified lines
162static int pmain(lua_State* L)162static int pmain(lua_State* L)
163{163{
164 int argc=(int)lua_tointeger(L,1);164 int argc=(int)lua_tointeger(L,1);
165 char** argv=lua_touserdata(L,2);165 char** argv=(char**)lua_touserdata(L,2);
166 const Proto* f;166 const Proto* f;
167 int i;167 int i;
168 if (!lua_checkstack(L,argc)) fatal("too many input files");168 if (!lua_checkstack(L,argc)) fatal("too many input files");
@@ -193,7 +193,7 @@ int main(int argc, char* argv[]) · 24 unmodified lines
193 argc-=i; argv+=i;193 argc-=i; argv+=i;
194 if (argc<=0) usage("no input files given");194 if (argc<=0) usage("no input files given");
195 L=luaL_newstate();195 L=luaL_newstate();
196 if (L==NULL) fatal("not enough memory for state");196 if (L==NULL) fatal("cannot create state: not enough memory");
197 lua_pushcfunction(L,&pmain);197 lua_pushcfunction(L,&pmain);
198 lua_pushinteger(L,argc);198 lua_pushinteger(L,argc);
199 lua_pushlightuserdata(L,argv);199 lua_pushlightuserdata(L,argv);
src/lundump.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lundump.c,v 1.69 2011/05/06 13:35:17 lhf Exp $2** $Id: lundump.c,v 1.70 2011/06/21 12:29:00 lhf Exp $
3** load precompiled Lua chunks3** load precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -44,7 +44,7 @@ static void error(LoadState* S, const char* why) · 38 unmodified lines
44 44
45static void LoadBlock(LoadState* S, void* b, size_t size)45static void LoadBlock(LoadState* S, void* b, size_t size)
46{46{
47 if (luaZ_read(S->Z,b,size)!=0) error(S,"corrupted");47 if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
48}48}
49 49
50static int LoadChar(LoadState* S)50static int LoadChar(LoadState* S)

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