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