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
4040 <SMALL>
4141 Copyright &copy; 2011 Lua.org, PUC-Rio.
4242 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>.
4444 </SMALL>
4545
4646 <H2><A NAME="contents">Contents</A></H2>
@@ -146,6 +146,8 @@ Freely available under the terms of the · 99 unmodified lines
146146 <P>
147147 <A HREF="manual.html#pdf-_G">_G</A><BR>
148148 <A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
149+
150+<P>
149151 <A HREF="manual.html#pdf-assert">assert</A><BR>
150152 <A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
151153 <A HREF="manual.html#pdf-dofile">dofile</A><BR>
@@ -518,9 +520,9 @@ Freely available under the terms of the · 366 unmodified lines
518520 </TABLE>
519521
520522 <HR>
521−<SMALL>
523+<SMALL CLASS="footer">
522524 Last update:
523−Mon Jun 13 15:09:33 BRT 2011
525+Mon Jun 20 08:55:58 BRT 2011
524526 </SMALL>
525527 <!--
526528 Last change: revised for Lua 5.2.0 (beta)
doc/lua.css+2−1
@@ -2,13 +2,14 @@ body { · 1 unmodified line
22 color: #000000 ;
33 background-color: #FFFFFF ;
44 font-family: sans-serif ;
5+ font-family: Helvetica, Arial, sans-serif ;
56 text-align: justify ;
67 margin-right: 20px ;
78 margin-left: 20px ;
89 }
910
1011 h1, h2, h3, h4 {
11− font-family: Verdana, sans-serif ;
12+ font-family: Verdana, Geneva, sans-serif ;
1213 font-weight: normal ;
1314 font-style: italic ;
1415 }
doc/manual.html+47−45
@@ -38,7 +38,7 @@ Freely available under the terms of the · 37 unmodified lines
3838 <!-- ====================================================================== -->
3939 <p>
4040
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 $ -->
4242
4343
4444
@@ -54,7 +54,7 @@ functional programming, and data-driven programming. · 9 unmodified lines
5454 Lua is intended to be used as a powerful, light-weight
5555 scripting language for any program that needs one.
5656 Lua is implemented as a library, written in <em>clean C</em>,
57−the common subset of ANSI&nbsp;C and C++.
57+the common subset of Standard&nbsp;C and C++.
5858
5959
6060 <p>
@@ -192,8 +192,9 @@ There are several convenient ways to create tables in Lua · 131 unmodified lines
192192
193193
194194 <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>,
197198 which is called the length of the sequence (see <a href="#3.4.6">&sect;3.4.6</a>).
198199
199200
@@ -234,7 +235,7 @@ of a given value. · 34 unmodified lines
234235 <h2>2.2 &ndash; <a name="2.2">Environments and the Global Environment</a></h2>
235236
236237 <p>
237−As discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
238+As will be discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
238239 any reference to a global name <code>var</code> is syntactically translated
239240 to <code>_ENV.var</code>.
240241 Moreover, every chunk is compiled in the scope of an external
@@ -1136,7 +1137,7 @@ The following strings denote other tokens: · 895 unmodified lines
11361137 <pre>
11371138 + - * / % ^ #
11381139 == ~= &lt;= &gt;= &lt; &gt; =
1139− ( ) { } [ ]
1140+ ( ) { } [ ] ::
11401141 ; : , . .. ...
11411142 </pre>
11421143
@@ -1239,7 +1240,7 @@ Lua also accepts hexadecimal constants, · 96 unmodified lines
12391240 which start with <code>0x</code> or <code>0X</code>.
12401241 Hexadecimal constants also accept an optional fractional part
12411242 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>'.
12431244 Examples of valid numerical constants are
12441245
12451246 <pre>
@@ -1531,12 +1532,13 @@ labels in Lua are considered statements too: · 285 unmodified lines
15311532 <pre>
15321533 stat ::= <b>goto</b> Name
15331534 stat ::= label
1534− label ::= &lsquo;<b>@</b>&rsquo; Name &lsquo;<b>:</b>&rsquo;
1535+ label ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;
15351536 </pre>
15361537
15371538 <p>
15381539 A label is visible in the entire block where it is defined
15391540 (including nested blocks, but not nested functions).
1541+A function cannot have more than one label with a given name.
15401542 A goto may jump to any visible label as long as it does not
15411543 enter into the scope of a local variable.
15421544
@@ -1995,10 +1997,17 @@ character is one byte). · 452 unmodified lines
19951997
19961998
19971999 <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">&sect;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
19992007 table is a <em>sequence</em>,
20002008 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>.
20022011 In that case, <em>n</em> is its length.
20032012 Note that a table like
20042013
@@ -2008,16 +2017,11 @@ Note that a table like · 3 unmodified lines
20082017 is not a sequence, because it has the key <code>4</code>
20092018 but does not have the key <code>3</code>.
20102019 (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.)
20122021 Note, however, that non-numeric keys do not interfere
20132022 with whether a table is a sequence.
20142023
20152024
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">&sect;2.4</a>).
2019−
2020−
20212025
20222026
20232027
@@ -2824,11 +2828,11 @@ It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newst · 800 unmodified lines
28242828 return realloc(ptr, nsize);
28252829 }
28262830 </pre><p>
2827−Note that ANSI&nbsp;C ensures
2831+Note that Standard&nbsp;C ensures
28282832 that <code>free(NULL)</code> has no effect and that
28292833 <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
28302834 This code assumes that <code>realloc</code> does not fail when shrinking a block.
2831−ANSI&nbsp;C does not ensure this behavior,
2835+Standard&nbsp;C does not ensure this behavior,
28322836 but it seems a safe assumption.
28332837
28342838
@@ -2864,11 +2868,6 @@ The value of <code>op</code> must be one of the following constants: · 29 unmodified lines
28642868
28652869 </ul>
28662870
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−
28722871
28732872
28742873
@@ -5907,7 +5906,7 @@ as <code>return luaL_error(<em>args</em>)</code>. · 3032 unmodified lines
59075906
59085907
59095908 <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>
59115910 <pre>int luaL_execresult (lua_State *L, int stat);</pre>
59125911
59135912 <p>
@@ -6097,7 +6096,7 @@ It is implemented as the following macro: · 183 unmodified lines
60976096
60986097 <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>
60996098 <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>
61016100
61026101 <p>
61036102 Creates a new table with a size optimized
@@ -7471,7 +7470,7 @@ including if necessary a path and an extension. · 1367 unmodified lines
74717470
74727471
74737472 <p>
7474−This function is not supported by ANSI&nbsp;C.
7473+This function is not supported by Standard&nbsp;C.
74757474 As such, it is only available on some platforms
74767475 (Windows, Linux, Mac OS X, Solaris, BSD,
74777476 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
80988097
80998098
81008099 <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,
81068101 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">&sect;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">&sect;3.4.6</a>).
8105+In particular, all functions ignore non-numeric keys
8106+in lists given as arguments.
81108107
81118108
81128109 <p>
@@ -8135,7 +8132,8 @@ If <code>i</code> is greater than <code>j</code>, returns the empty string. · 22 unmodified lines
81358132
81368133 <p>
81378134 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], &middot;&middot;&middot;, list[#list]</code>.
81398137 The default value for <code>pos</code> is <code>#list+1</code>,
81408138 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
81418139 of list <code>t</code>.
@@ -8162,7 +8160,9 @@ if any parameter is <b>nil</b>. · 20 unmodified lines
81628160
81638161 <p>
81648162 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], &middot;&middot;&middot;, list[#list]</code>
8165+and erasing element <code>list[#list]</code>.
81668166 Returns the value of the removed element.
81678167 The default value for <code>pos</code> is <code>#list</code>,
81688168 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
81778177
81788178 <p>
81798179 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>.
81818181 If <code>comp</code> is given,
81828182 then it must be a function that receives two list elements
81838183 and returns true when the first element must come
81848184 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).
81868186 If <code>comp</code> is not given,
81878187 then the standard Lua operator <code>&lt;</code> is used instead.
81888188
@@ -8459,7 +8459,7 @@ Returns the angle <code>x</code> (given in degrees) in radians. · 270 unmodified lines
84598459
84608460 <p>
84618461 This function is an interface to the simple
8462−pseudo-random generator function <code>rand</code> provided by ANSI&nbsp;C.
8462+pseudo-random generator function <code>rand</code> provided by Standard&nbsp;C.
84638463 (No guarantees can be given for its statistical properties.)
84648464
84658465
@@ -9242,9 +9242,11 @@ this value is exactly <code>t2</code><em>-</em><code>t1</code>. · 776 unmodified lines
92429242 <p>
92439243 This function is equivalent to the C&nbsp;function <code>system</code>.
92449244 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,
92489250 as follows:
92499251
92509252 <ul>
@@ -10139,7 +10141,7 @@ Here is the complete syntax of Lua in extended BNF. · 888 unmodified lines
1013910141
1014010142 retstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
1014110143
10142− label ::= &lsquo;<b>@</b>&rsquo; Name &lsquo;<b>:</b>&rsquo;
10144+ label ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;
1014310145
1014410146 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]
1014510147
@@ -10191,9 +10193,9 @@ Here is the complete syntax of Lua in extended BNF. · 45 unmodified lines
1019110193
1019210194
1019310195 <HR>
10194−<SMALL>
10196+<SMALL CLASS="footer">
1019510197 Last update:
10196−Mon Jun 13 14:56:14 BRT 2011
10198+Tue Jun 21 19:09:27 BRT 2011
1019710199 </SMALL>
1019810200 <!--
1019910201 Last 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
335335 <LI> new <CODE>lua_copy</CODE>
336336 <LI> new <CODE>lua_absindex</CODE>
337337 <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
339339 <LI> new <CODE>lua_Unsigned</CODE>
340340 </UL>
341341
@@ -350,6 +350,7 @@ Here are the other changes introduced in Lua 5.2: · 8 unmodified lines
350350 <LI> new hash for floats
351351 <LI> handling of non-string error messages in the standalone interpreter
352352 <LI> generational mode for garbage collection (experimental)
353+<LI> NaN trick (experimental)
353354 </UL>
354355
355356 <H2><A NAME="license">License</A></H2>
@@ -396,9 +397,9 @@ THE SOFTWARE. · 40 unmodified lines
396397 </BLOCKQUOTE>
397398
398399 <HR>
399−<SMALL>
400+<SMALL CLASS="footer">
400401 Last update:
401−Mon Jun 13 15:07:49 BRT 2011
402+Thu Jun 16 08:21:17 BRT 2011
402403 </SMALL>
403404 <!--
404405 Last change: revised for Lua 5.2.0 (beta)
src/Makefile+25−23
@@ -7,13 +7,18 @@ · 6 unmodified lines
77 PLAT= none
88
99 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)
1213
1314 AR= ar rcu
1415 RANLIB= ranlib
1516 RM= rm -f
1617
18+SYSCFLAGS=
19+SYSLDFLAGS=
20+SYSLIBS=
21+
1722 MYCFLAGS=
1823 MYLDFLAGS=
1924 MYLIBS=
@@ -23,7 +28,7 @@ MYLIBS= · 3 unmodified lines
2328 PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
2429
2530 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 \
2732 lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
2833 ltm.o lundump.o lvm.o lzio.o
2934 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
5358 $(RANLIB) $@
5459
5560 $(LUA_T): $(LUA_O) $(LUA_A)
56− $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
61+ $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
5762
5863 $(LUAC_T): $(LUAC_O) $(LUA_A)
59− $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
64+ $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
6065
6166 clean:
6267 $(RM) $(ALL_T) $(ALL_O)
@@ -68,12 +73,11 @@ echo: · 5 unmodified lines
6873 @echo "PLAT= $(PLAT)"
6974 @echo "CC= $(CC)"
7075 @echo "CFLAGS= $(CFLAGS)"
76+ @echo "LDFLAGS= $(SYSLDFLAGS)"
77+ @echo "LIBS= $(LIBS)"
7178 @echo "AR= $(AR)"
7279 @echo "RANLIB= $(RANLIB)"
7380 @echo "RM= $(RM)"
74− @echo "MYCFLAGS= $(MYCFLAGS)"
75− @echo "MYLDFLAGS= $(MYLDFLAGS)"
76− @echo "MYLIBS= $(MYLIBS)"
7781
7882 # Convenience targets for popular platforms
7983 ALL= all
@@ -83,35 +87,35 @@ none: · 3 unmodified lines
8387 @echo " $(PLATS)"
8488
8589 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"
8791
8892 ansi:
89− $(MAKE) $(ALL) MYCFLAGS="-DLUA_ANSI"
93+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI"
9094
9195 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"
9397
9498 freebsd:
95− $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
99+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline"
96100
97101 generic: $(ALL)
98102
99103 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"
101105
102106 macosx:
103− $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline"
107+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline"
104108
105109 mingw:
106110 $(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \
107111 "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
109113
110114 posix:
111− $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX"
115+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
112116
113117 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"
115119
116120 # list targets that do not create files (but not all makes understand .PHONY)
117121 .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
128132 lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
129133 lstring.h ltable.h lvm.h
130134 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
132135 ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
133136 ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
134137 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
144147 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
145148 linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
146149 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
149152 lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
150153 lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
151154 ltm.h lzio.h lmem.h ldo.h lgc.h
152155 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
155158 lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
156159 loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
157160 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
178181 lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
179182 lzio.h
180183
181−# (end of Makefile)
src/lauxlib.c+6−7
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -251,13 +251,12 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) { · 245 unmodified lines
251251 else {
252252 inspectstat(stat, what); /* interpret result */
253253 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
256256 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 */
261260 }
262261 }
263262
src/lauxlib.h+4−1
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -164,6 +164,7 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); · 158 unmodified lines
164164
165165
166166 /* compatibility with old module system */
167+#if defined(LUA_COMPAT_MODULE)
167168
168169 LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
169170 int sizehint);
@@ -172,6 +173,8 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, · 2 unmodified lines
172173
173174 #define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
174175
176+#endif
177+
175178
176179 #endif
177180
src/lbaselib.c+15−6
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -268,6 +268,13 @@ static int luaB_loadfile (lua_State *L) { · 262 unmodified lines
268268 ** =======================================================
269269 */
270270
271+
272+typedef struct {
273+char c;
274+ const char *mode;
275+} loaddata;
276+
277+
271278 /*
272279 ** check whether a chunk (prefix in 's') satisfies given 'mode'
273280 ** ('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
298305 */
299306 static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
300307 const char *s;
301− const char **mode = (const char **)ud;
308+ loaddata *ld = (loaddata *)ud;
302309 luaL_checkstack(L, 2, "too many nested functions");
303310 lua_pushvalue(L, 1); /* get function */
304311 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
307314 return NULL;
308315 }
309316 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 */
313320 if (s) luaL_error(L, s);
314321 }
315322 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
@@ -335,9 +342,11 @@ static int luaB_load (lua_State *L) { · 19 unmodified lines
335342 }
336343 else { /* loading from a reader function */
337344 const char *chunkname = luaL_optstring(L, 2, "=(load)");
345+ loaddata ld;
346+ ld.mode = mode;
338347 luaL_checktype(L, 1, LUA_TFUNCTION);
339348 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);
341350 }
342351 if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */
343352 lua_pushvalue(L, 4); /* environment for loaded function */
src/lbitlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Standard library for bitwise operations
44 ** See Copyright Notice in lua.h
55 */
@@ -152,7 +152,7 @@ static int b_rrot (lua_State *L) { · 146 unmodified lines
152152 static int fieldargs (lua_State *L, int farg, int *width) {
153153 int f = luaL_checkint(L, farg);
154154 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");
156156 luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");
157157 if (f + w > LUA_NBITS)
158158 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−
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−};
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) */
47−LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
48−
49−#endif
50−
src/ldo.c+23−4
@@ -1,10 +1,11 @@
11 /*
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 $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
66
77
8+#include <locale.h>
89 #include <setjmp.h>
910 #include <stdlib.h>
1011 #include <string.h>
@@ -612,8 +613,22 @@ struct SParser { /* data to `f_parser' */ · 601 unmodified lines
612613 Mbuffer buff; /* dynamic structure used by the scanner */
613614 Dyndata dyd; /* dynamic structures used by the parser */
614615 const char *name;
616+ TString *savedlocale;
615617 };
616618
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+
617632 static void f_parser (lua_State *L, void *ud) {
618633 int i;
619634 Proto *tf;
@@ -621,8 +636,7 @@ static void f_parser (lua_State *L, void *ud) { · 1 unmodified line
621636 struct SParser *p = cast(struct SParser *, ud);
622637 int c = zgetc(p->z); /* read first character */
623638 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);
626640 setptvalue2s(L, L->top, tf);
627641 incr_top(L);
628642 cl = luaF_newLclosure(L, tf);
@@ -635,8 +649,9 @@ static void f_parser (lua_State *L, void *ud) { · 6 unmodified lines
635649 int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {
636650 struct SParser p;
637651 int status;
652+ setnilvalue(L->top++); /* reserve space for anchoring locale */
638653 L->nny++; /* cannot yield during parsing */
639− p.z = z; p.name = name;
654+ p.z = z; p.name = name; p.savedlocale = NULL;
640655 p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;
641656 p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
642657 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
647662 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);
648663 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);
649664 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;
650669 return status;
651670 }
652671
src/liolib.c+128−139
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -19,8 +19,6 @@ · 13 unmodified lines
1919 #include "lualib.h"
2020
2121
22−#define MAX_SIZE_T (~(size_t)0)
23−
2422
2523 /*
2624 ** lua_popen spawns a new process connected to the current one through
@@ -51,11 +49,15 @@ · 24 unmodified lines
5149 #endif /* } */
5250
5351
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")
5655
5756
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;
5961
6062
6163 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
6466 }
6567
6668
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)
6872
6973
7074 static int io_type (lua_State *L) {
71− void *ud;
75+ LStream *p;
7276 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)
7579 lua_pushnil(L); /* not a file */
76− else if (*((FILE **)ud) == NULL)
80+ else if (isclosed(p))
7781 lua_pushliteral(L, "closed file");
7882 else
7983 lua_pushliteral(L, "file");
@@ -81,11 +85,22 @@ static int io_type (lua_State *L) { · 1 unmodified line
8185 }
8286
8387
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+
8498 static FILE *tofile (lua_State *L) {
85− FILE **f = tofilep(L);
86− if (*f == NULL)
99+ LStream *p = tolstream(L);
100+ if (isclosed(p))
87101 luaL_error(L, "attempt to use a closed file");
88− return *f;
102+ lua_assert(p->f);
103+ return p->f;
89104 }
90105
91106
@@ -94,40 +109,35 @@ static FILE *tofile (lua_State *L) { · 2 unmodified lines
94109 ** before opening the actual file; so, if there is a memory error, the
95110 ** file is not left opened.
96111 */
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' */
100115 luaL_setmetatable(L, LUA_FILEHANDLE);
101− return pf;
116+ return p;
102117 }
103118
104119
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 */
110125 }
111126
112127
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);
120133 }
121134
122135
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;
131141 }
132142
133143
@@ -135,111 +145,90 @@ static int io_pclose (lua_State *L) { · 1 unmodified line
135145 ** function to close regular files
136146 */
137147 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);
142151 }
143152
144153
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;
175159 }
176160
177161
178162 static int io_open (lua_State *L) {
179163 const char *filename = luaL_checkstring(L, 1);
180164 const char *mode = luaL_optstring(L, 2, "r");
181− FILE **pf;
165+ LStream *p = newfile(L);
182166 int i = 0;
183167 /* check whether 'mode' matches '[rwa]%+?b?' */
184168 if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
185169 (mode[i] != '+' || ++i) && /* skip if char is '+' */
186170 (mode[i] != 'b' || ++i) && /* skip if char is 'b' */
187171 (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;
193176 }
194177
195178
196179 /*
197−** this function has a separated environment, which defines the
198−** correct __close for 'popen' files
180+** function to close 'popen' files
199181 */
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+
200188 static int io_popen (lua_State *L) {
201189 const char *filename = luaL_checkstring(L, 1);
202190 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;
206195 }
207196
208197
209198 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;
213202 }
214203
215204
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;
223212 }
224213
225214
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) {
227216 if (!lua_isnoneornil(L, 1)) {
228217 const char *filename = lua_tostring(L, 1);
229218 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)
233222 fileerror(L, 1, filename);
234223 }
235224 else {
236225 tofile(L); /* check that it's a valid file handle */
237226 lua_pushvalue(L, 1);
238227 }
239− lua_rawseti(L, lua_upvalueindex(1), f);
228+ lua_setfield(L, LUA_REGISTRYINDEX, f);
240229 }
241230 /* return current value */
242− lua_rawgeti(L, lua_upvalueindex(1), f);
231+ lua_getfield(L, LUA_REGISTRYINDEX, f);
243232 return 1;
244233 }
245234
@@ -281,16 +270,16 @@ static int io_lines (lua_State *L) { · 35 unmodified lines
281270 int toclose;
282271 if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
283272 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 */
285274 lua_replace(L, 1); /* put it at index 1 */
286275 tofile(L); /* check that it's a valid file handle */
287276 toclose = 0; /* do not close it after iteration */
288277 }
289278 else { /* open a new file */
290279 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)
294283 fileerror(L, 1, filename);
295284 lua_replace(L, 1); /* put file at index 1 */
296285 toclose = 1; /* close it after iteration */
@@ -350,6 +339,8 @@ static int read_line (lua_State *L, FILE *f, int chop) { · 53 unmodified lines
350339 }
351340
352341
342+#define MAX_SIZE_T (~(size_t)0)
343+
353344 static void read_all (lua_State *L, FILE *f) {
354345 size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
355346 luaL_Buffer b;
@@ -440,15 +431,15 @@ static int f_read (lua_State *L) { · 84 unmodified lines
440431
441432
442433 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));
444435 int i;
445436 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");
448439 lua_settop(L , 1);
449440 for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
450441 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 */
452443 lua_assert(n > 0); /* should return at least a nil */
453444 if (!lua_isnil(L, -n)) /* read at least one value? */
454445 return n; /* return them */
@@ -494,7 +485,7 @@ static int io_write (lua_State *L) { · 39 unmodified lines
494485
495486
496487 static int f_write (lua_State *L) {
497− FILE * f = tofile(L);
488+ FILE *f = tofile(L);
498489 lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
499490 return g_write(L, f, 2);
500491 }
@@ -538,6 +529,9 @@ static int f_flush (lua_State *L) { · 37 unmodified lines
538529 }
539530
540531
532+/*
533+** functions for 'io' library
534+*/
541535 static const luaL_Reg iolib[] = {
542536 {"close", io_close},
543537 {"flush", io_flush},
@@ -554,6 +548,9 @@ static const luaL_Reg iolib[] = { · 10 unmodified lines
554548 };
555549
556550
551+/*
552+** methods for file handles
553+*/
557554 static const luaL_Reg flib[] = {
558555 {"close", io_close},
559556 {"flush", f_flush},
@@ -562,8 +559,8 @@ static const luaL_Reg flib[] = { · 2 unmodified lines
562559 {"seek", f_seek},
563560 {"setvbuf", f_setvbuf},
564561 {"write", f_write},
565− {"__gc", io_gc},
566− {"__tostring", io_tostring},
562+ {"__gc", f_gc},
563+ {"__tostring", f_tostring},
567564 {NULL, NULL}
568565 };
569566
@@ -577,46 +574,38 @@ static void createmeta (lua_State *L) { · 7 unmodified lines
577574 }
578575
579576
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;
589586 }
590587
591588
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 */
599599 }
600600
601601
602602 LUAMOD_API int luaopen_io (lua_State *L) {
603− lua_settop(L, 0);
603+ luaL_newlib(L, iolib); /* new module */
604604 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);
610605 /* create (and set) default files */
611− newenv(L, io_noclose); /* environment for default files at index 3 */
612606 createstdfile(L, stdin, IO_INPUT, "stdin");
613607 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");
620609 return 1;
621610 }
622611
src/llex.c+43−59
@@ -1,11 +1,11 @@
11 /*
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 $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
66
77
8−#include <locale.h>
8+#include <ctype.h>
99 #include <string.h>
1010
1111 #define llex_c
@@ -13,7 +13,6 @@ · 1 unmodified line
1313
1414 #include "lua.h"
1515
16−#include "lctype.h"
1716 #include "ldo.h"
1817 #include "llex.h"
1918 #include "lobject.h"
@@ -38,7 +37,7 @@ static const char *const luaX_tokens [] = { · 18 unmodified lines
3837 "end", "false", "for", "function", "goto", "if",
3938 "in", "local", "nil", "not", "or", "repeat",
4039 "return", "then", "true", "until", "while",
41− "..", "...", "==", ">=", "<=", "~=", "<eof>",
40+ "..", "...", "==", ">=", "<=", "~=", "::", "<eof>",
4241 "<number>", "<name>", "<string>"
4342 };
4443
@@ -75,7 +74,7 @@ void luaX_init (lua_State *L) { · 30 unmodified lines
7574 const char *luaX_token2str (LexState *ls, int token) {
7675 if (token < FIRST_RESERVED) {
7776 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) :
7978 luaO_pushfstring(ls->L, "char(%d)", token);
8079 }
8180 else {
@@ -185,52 +184,24 @@ static int check_next (LexState *ls, const char *set) { · 103 unmodified lines
185184 }
186185
187186
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−
203187
204188 #define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
205189
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−
221190
222191 /* LUA_NUMBER */
223192 static void read_numeral (LexState *ls, SemInfo *seminfo) {
224− lua_assert(lisdigit(ls->current));
193+ lua_assert(isdigit(ls->current));
225194 do {
226195 save_and_next(ls);
227196 if (check_next(ls, "EePp")) /* exponent part? */
228197 check_next(ls, "+-"); /* optional exponent sign */
229− } while (lislalnum(ls->current) || ls->current == '.');
198+ } while (isalnum(ls->current) || ls->current == '.');
230199 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+
234205 }
235206
236207
@@ -287,25 +258,32 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { · 50 unmodified lines
287258
288259
289260 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 */
297268 }
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 */
299275 }
300276
301277
302278 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 */
309287 if (c > UCHAR_MAX) {
310288 luaZ_resetbuffer(ls->buff); /* prepare error message */
311289 save(ls, '\\');
@@ -349,14 +327,14 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 37 unmodified lines
349327 case EOZ: continue; /* will raise an error next loop */
350328 case '*': { /* skip following span of spaces */
351329 next(ls); /* skip the '*' */
352− while (lisspace(ls->current)) {
330+ while (isspace(ls->current)) {
353331 if (currIsNewline(ls)) inclinenumber(ls);
354332 else next(ls);
355333 }
356334 continue; /* do not save 'c' */
357335 }
358336 default: {
359− if (!lisdigit(ls->current))
337+ if (!isdigit(ls->current))
360338 c = ls->current; /* handles \\, \", \', and \? */
361339 else /* digital escape \ddd */
362340 c = readdecesc(ls);
@@ -437,6 +415,11 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 74 unmodified lines
437415 if (ls->current != '=') return '~';
438416 else { next(ls); return TK_NE; }
439417 }
418+ case ':': {
419+ next(ls);
420+ if (ls->current != ':') return ':';
421+ else { next(ls); return TK_DBCOLON; }
422+ }
440423 case '"': case '\'': { /* short literal strings */
441424 read_string(ls, ls->current, seminfo);
442425 return TK_STRING;
@@ -448,7 +431,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 5 unmodified lines
448431 return TK_DOTS; /* '...' */
449432 else return TK_CONCAT; /* '..' */
450433 }
451− else if (!lisdigit(ls->current)) return '.';
434+ else if (!isdigit(ls->current)) return '.';
452435 /* else go through */
453436 }
454437 case '0': case '1': case '2': case '3': case '4':
@@ -460,11 +443,12 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 5 unmodified lines
460443 return TK_EOS;
461444 }
462445 default: {
463− if (lislalpha(ls->current)) { /* identifier or reserved word? */
446+ if (isalpha(ls->current) || ls->current == '_') {
447+ /* identifier or reserved word */
464448 TString *ts;
465449 do {
466450 save_and_next(ls);
467− } while (lislalnum(ls->current));
451+ } while (isalnum(ls->current) || ls->current == '_');
468452 ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
469453 luaZ_bufflen(ls->buff));
470454 seminfo->ts = ts;
src/llex.h+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -26,7 +26,7 @@ enum RESERVED { · 20 unmodified lines
2626 TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
2727 TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
2828 /* 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,
3030 TK_NUMBER, TK_NAME, TK_STRING
3131 };
3232
src/lobject.c+11−11
@@ -1,9 +1,10 @@
11 /*
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 $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
66
7+#include <ctype.h>
78 #include <stdarg.h>
89 #include <stdio.h>
910 #include <stdlib.h>
@@ -14,7 +15,6 @@ · 4 unmodified lines
1415
1516 #include "lua.h"
1617
17−#include "lctype.h"
1818 #include "ldebug.h"
1919 #include "ldo.h"
2020 #include "lmem.h"
@@ -85,9 +85,9 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { · 64 unmodified lines
8585
8686
8787 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;
9191 }
9292
9393
@@ -104,8 +104,8 @@ static int isneg (const char **s) { · 10 unmodified lines
104104
105105
106106 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)++)));
109109 (*count)++;
110110 }
111111 return r;
@@ -121,7 +121,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 9 unmodified lines
121121 int e = 0, i = 0;
122122 int neg = 0; /* 1 if number is negative */
123123 *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 */
125125 neg = isneg(&s); /* check signal */
126126 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
127127 return 0.0; /* invalid format (no '0x') */
@@ -140,9 +140,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 12 unmodified lines
140140 int neg1;
141141 s++; /* skip 'p' */
142142 neg1 = isneg(&s); /* signal */
143− if (!lisdigit(cast_uchar(*s)))
143+ if (!isdigit(cast_uchar(*s)))
144144 goto ret; /* must have at least one digit */
145− while (lisdigit(cast_uchar(*s))) /* read exponent */
145+ while (isdigit(cast_uchar(*s))) /* read exponent */
146146 exp1 = exp1 * 10 + *(s++) - '0';
147147 if (neg1) exp1 = -exp1;
148148 e += exp1;
@@ -163,7 +163,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { · 14 unmodified lines
163163 else
164164 *result = lua_str2number(s, &endptr);
165165 if (endptr == s) return 0; /* nothing recognized */
166− while (lisspace(cast_uchar(*endptr))) endptr++;
166+ while (isspace(cast_uchar(*endptr))) endptr++;
167167 return (endptr == s + len); /* OK if no trailing characters */
168168 }
169169
src/loslib.c+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -21,7 +21,7 @@ · 15 unmodified lines
2121
2222
2323 /*
24−** list of valid conversion specifiers @* for the 'strftime' function
24+** list of valid conversion specifiers for the 'strftime' function
2525 */
2626 #if !defined(LUA_STRFTIMEOPTIONS)
2727
src/lparser.c+31−16
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -367,7 +367,7 @@ static int findlabel (LexState *ls, int g) { · 361 unmodified lines
367367 /* check labels in current block for a match */
368368 for (i = bl->firstlabel; i < dyd->label.n; i++) {
369369 Labeldesc *lb = &dyd->label.arr[i];
370− if (eqstr(lb->name, gt->name)) { /* correct label? */
370+ if (eqstr(lb->name, gt->name) && lb->pc != -1) { /* correct label? */
371371 if (gt->nactvar > lb->nactvar &&
372372 (bl->upval || dyd->label.n > bl->firstlabel))
373373 luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
@@ -411,7 +411,7 @@ static void findgotos (LexState *ls, Labeldesc *lb) { · 37 unmodified lines
411411 /*
412412 ** "export" pending gotos to outer level, to check them against
413413 ** 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
415415 ** upvalue), close those variables being exited.
416416 */
417417 static void movegotosout (FuncState *fs, BlockCnt *bl) {
@@ -460,12 +460,18 @@ static void breaklabel (LexState *ls) { · 42 unmodified lines
460460 static void undefgoto (LexState *ls, Labeldesc *gt) {
461461 const char *msg = (gt->name->tsv.reserved > 0)
462462 ? "<%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";
464464 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
465465 semerror(ls, msg);
466466 }
467467
468468
469+static void invalidatelabels (Labellist *ll, int level) {
470+ for (; level < ll->n; level++)
471+ ll->arr[level].pc = -1; /* mark label as out of scope */
472+}
473+
474+
469475 static void leaveblock (FuncState *fs) {
470476 BlockCnt *bl = fs->bl;
471477 LexState *ls = fs->ls;
@@ -481,7 +487,7 @@ static void leaveblock (FuncState *fs) { · 9 unmodified lines
481487 removevars(fs, bl->nactvar);
482488 lua_assert(bl->nactvar == fs->nactvar);
483489 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 */
485491 if (bl->previous) /* inner block? */
486492 movegotosout(fs, bl); /* update pending gotos to outer block */
487493 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
526532 fs->nlocvars = 0;
527533 fs->nactvar = 0;
528534 fs->firstlocal = ls->dyd->actvar.n;
535+ fs->firstlabel = ls->dyd->label.n;
529536 fs->bl = NULL;
530537 f = luaF_newproto(L);
531538 fs->f = f;
@@ -548,6 +555,7 @@ static void close_func (LexState *ls) { · 16 unmodified lines
548555 Proto *f = fs->f;
549556 luaK_ret(fs, 0, 0); /* final return */
550557 leaveblock(fs);
558+ ls->dyd->label.n = fs->firstlabel; /* remove labels */
551559 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
552560 f->sizecode = fs->pc;
553561 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
11851193 }
11861194
11871195
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++) {
11951201 if (eqstr(label, ll->arr[i].name)) {
11961202 const char *msg = luaO_pushfstring(ls->L,
11971203 "label " LUA_QS " already defined on line %d",
@@ -1199,11 +1205,20 @@ static void labelstat (LexState *ls, TString *label, int line) { · 1 unmodified line
11991205 semerror(ls, msg);
12001206 }
12011207 }
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 */
12031218 /* create new entry for this label */
12041219 l = newlabelentry(ls, ll, label, line, fs->pc);
12051220 /* skip other no-op statements */
1206− while (ls->t.token == ';' || ls->t.token == '@')
1221+ while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
12071222 statement(ls);
12081223 if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
12091224 /* assume that locals are already out of scope */
@@ -1537,8 +1552,8 @@ static void statement (LexState *ls) { · 327 unmodified lines
15371552 localstat(ls);
15381553 break;
15391554 }
1540− case '@': { /* stat -> label */
1541− luaX_next(ls); /* skip '@' */
1555+ case TK_DBCOLON: { /* stat -> label */
1556+ luaX_next(ls); /* skip double colon */
15421557 labelstat(ls, str_checkname(ls), line);
15431558 break;
15441559 }
src/lparser.h+3−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -62,7 +62,7 @@ typedef struct Vardesc { · 56 unmodified lines
6262 /* description of pending goto statements and label statements */
6363 typedef struct Labeldesc {
6464 TString *name; /* label identifier */
65− int pc; /* position in code */
65+ int pc; /* position in code (for labels, -1 means out of scope) */
6666 int line; /* line where it appeared */
6767 lu_byte nactvar; /* local level where it appears in current block */
6868 } Labeldesc;
@@ -107,6 +107,7 @@ typedef struct FuncState { · 38 unmodified lines
107107 int nk; /* number of elements in `k' */
108108 int np; /* number of elements in `p' */
109109 int firstlocal; /* index of first local var of this function */
110+ int firstlabel; /* index of first label of this function */
110111 short nlocvars; /* number of elements in `locvars' */
111112 lu_byte nactvar; /* number of active local variables */
112113 lu_byte nups; /* number of upvalues */
src/lstrlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -45,7 +45,7 @@ static int str_len (lua_State *L) { · 39 unmodified lines
4545 /* translate a relative string position: negative means back from end */
4646 static size_t posrelat (ptrdiff_t pos, size_t len) {
4747 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;
4949 else return len - ((size_t)-pos) + 1;
5050 }
5151
src/ltable.c+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -88,7 +88,7 @@ static Node *hashnum (const Table *t, lua_Number n) { · 82 unmodified lines
8888 int i;
8989 luai_hashnum(i, n);
9090 if (i < 0) {
91− if ((unsigned int)i == -(unsigned int)i)
91+ if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
9292 i = 0; /* handle INT_MIN */
9393 i = -i; /* must be a positive value */
9494 }
src/lua.c+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -183,7 +183,7 @@ static int docall (lua_State *L, int narg, int nres) { · 177 unmodified lines
183183
184184
185185 static void print_version (void) {
186− luai_writestring(LUA_COPYRIGHT, sizeof(LUA_COPYRIGHT));
186+ luai_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
187187 luai_writeline();
188188 }
189189
src/luac.c+3−3
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -162,7 +162,7 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 156 unmodified lines
162162 static int pmain(lua_State* L)
163163 {
164164 int argc=(int)lua_tointeger(L,1);
165− char** argv=lua_touserdata(L,2);
165+ char** argv=(char**)lua_touserdata(L,2);
166166 const Proto* f;
167167 int i;
168168 if (!lua_checkstack(L,argc)) fatal("too many input files");
@@ -193,7 +193,7 @@ int main(int argc, char* argv[]) · 24 unmodified lines
193193 argc-=i; argv+=i;
194194 if (argc<=0) usage("no input files given");
195195 L=luaL_newstate();
196− if (L==NULL) fatal("not enough memory for state");
196+ if (L==NULL) fatal("cannot create state: not enough memory");
197197 lua_pushcfunction(L,&pmain);
198198 lua_pushinteger(L,argc);
199199 lua_pushlightuserdata(L,argv);
src/lundump.c+2−2
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -44,7 +44,7 @@ static void error(LoadState* S, const char* why) · 38 unmodified lines
4444
4545 static void LoadBlock(LoadState* S, void* b, size_t size)
4646 {
47− if (luaZ_read(S->Z,b,size)!=0) error(S,"corrupted");
47+ if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
4848 }
4949
5050 static 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