summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/amazon.gifbin0 -> 797 bytes
-rw-r--r--doc/contents.html51
-rw-r--r--doc/cover.pngbin0 -> 3305 bytes
-rw-r--r--doc/lua.css23
-rw-r--r--doc/manual.css7
-rw-r--r--doc/manual.html371
-rw-r--r--doc/readme.html14
-rw-r--r--src/lbaselib.c10
-rw-r--r--src/lcode.c44
-rw-r--r--src/ldebug.c10
-rw-r--r--src/loslib.c23
-rw-r--r--src/lparser.c4
-rw-r--r--src/lstrlib.c4
-rw-r--r--src/lua.h8
-rw-r--r--src/print.c3
15 files changed, 364 insertions, 208 deletions
diff --git a/doc/amazon.gif b/doc/amazon.gif
new file mode 100644
index 00000000..f2586d57
--- /dev/null
+++ b/doc/amazon.gif
Binary files differ
diff --git a/doc/contents.html b/doc/contents.html
index c1e4a99d..01b069f7 100644
--- a/doc/contents.html
+++ b/doc/contents.html
@@ -2,31 +2,59 @@
<HEAD>
<TITLE>Lua 5.1 reference manual - contents</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
-<style type="text/css">
+<STYLE TYPE="text/css">
ul {
list-style-type: none ;
list-style-position: outside ;
}
-</style>
+</STYLE>
</HEAD>
<BODY>
<HR>
<H1>
-<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
-Reference manual for Lua 5.1
+<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A>
+Lua 5.1 Reference Manual
</H1>
+This is an online version of
+<BLOCKQUOTE>
+<A HREF="http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20">
+<IMG SRC="cover.png" ALT="" TITLE="buy from Amazon" BORDER=1 ALIGN="left" HSPACE=12>
+</A>
+<B>Lua 5.1 Reference Manual</B>
+<BR>by R. Ierusalimschy, L. H. de Figueiredo, W. Celes
+<BR>Lua.org, August 2006
+<BR>ISBN 85-903798-3-3
+<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20">
+<IMG SRC="amazon.gif" ALT="[Buy from Amazon]" BORDER=0></A>
+<BR CLEAR="all">
+</BLOCKQUOTE>
+<P>
+
+Buy a paper copy and
+<A HREF="http://www.lua.org/donations.html">help to support</A>
+the Lua project.
+<P>
+
+<A HREF="manual.html">start</A>
+&middot;
<A HREF="#contents">contents</A>
&middot;
<A HREF="#index">index</A>
+&middot;
+<A HREF="http://www.lua.org/manual/5.1/errata.html">errata</A>
<HR>
+<SMALL>
+Copyright &copy; 2006-2007 Lua.org, PUC-Rio.
+Freely available under the terms of the
+<a href="http://www.lua.org/license.html#5">Lua license</a>.
+</SMALL>
<P>
<H2><A NAME="contents">Contents</A></H2>
<UL style="padding: 0">
-<LI><A HREF="manual.html">Top</A>
<LI><A HREF="manual.html#1">1 - Introduction</A>
<LI><A HREF="manual.html#2">2 - The Language</A>
<UL>
@@ -107,13 +135,12 @@ Reference manual for Lua 5.1
<LI><A HREF="manual.html#7.3">7.3 - Changes in the API</A>
</UL>
<LI><A HREF="manual.html#8">8 - The Complete Syntax of Lua</A>
-
</UL>
<H2><A NAME="index">Index</A></H2>
-<TABLE>
+<TABLE WIDTH="100%">
<TR VALIGN="top">
-<TD WIDTH="20%">
+<TD>
<H3><A NAME="functions">Lua functions</A></H3>
<A HREF="manual.html#pdf-_G">_G</A><BR>
<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
@@ -146,7 +173,7 @@ Reference manual for Lua 5.1
<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
</TD>
-<TD WIDTH="30%">
+<TD>
<H3>&nbsp;</H3>
<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
<A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>
@@ -254,7 +281,7 @@ Reference manual for Lua 5.1
<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
</TD>
-<TD WIDTH="25%">
+<TD>
<H3>C API</H3>
<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
@@ -419,10 +446,10 @@ Reference manual for Lua 5.1
<HR>
<SMALL>
Last update:
-Tue Jun 6 14:55:31 BRT 2006
+Fri Mar 23 08:33:19 BRT 2007
</SMALL>
<!--
-Last change: reformatted index
+Last change: minor edit
-->
</BODY>
diff --git a/doc/cover.png b/doc/cover.png
new file mode 100644
index 00000000..2dbb1981
--- /dev/null
+++ b/doc/cover.png
Binary files differ
diff --git a/doc/lua.css b/doc/lua.css
index f0072110..039cf116 100644
--- a/doc/lua.css
+++ b/doc/lua.css
@@ -2,16 +2,24 @@ body {
color: #000000 ;
background-color: #FFFFFF ;
font-family: sans-serif ;
+ text-align: justify ;
+ margin-right: 20px ;
+ margin-left: 20px ;
+}
+
+h1, h2, h3, h4 {
+ font-weight: normal ;
+ font-style: italic ;
}
a:link {
color: #000080 ;
- background-color: #FFFFFF ;
+ background-color: inherit ;
text-decoration: none ;
}
a:visited {
- background-color: #FFFFFF ;
+ background-color: inherit ;
text-decoration: none ;
}
@@ -20,3 +28,14 @@ a:link:hover, a:visited:hover {
background-color: #E0E0FF ;
}
+a:link:active, a:visited:active {
+ color: #FF0000 ;
+}
+
+hr {
+ border: 0 ;
+ height: 1px ;
+ color: #a0a0a0 ;
+ background-color: #a0a0a0 ;
+}
+
diff --git a/doc/manual.css b/doc/manual.css
new file mode 100644
index 00000000..93f1ab2d
--- /dev/null
+++ b/doc/manual.css
@@ -0,0 +1,7 @@
+h3 code {
+ font-family: inherit ;
+}
+
+pre {
+ font-size: 105% ;
+}
diff --git a/doc/manual.html b/doc/manual.html
index 16fbb36e..6203f824 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -4,6 +4,7 @@
<head>
<title>Lua 5.1 Reference Manual</title>
<link rel="stylesheet" href="lua.css">
+<link rel="stylesheet" href="manual.css">
</head>
<body>
@@ -17,10 +18,16 @@ Lua 5.1 Reference Manual
by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
<p>
<small>
-<a href="http://www.lua.org/copyright.html">Copyright</a>
-&copy; 2006 Lua.org, PUC-Rio. All rights reserved.
+Copyright &copy; 2006-2007 Lua.org, PUC-Rio.
+Freely available under the terms of the
+<a href="http://www.lua.org/license.html#5">Lua license</a>.
</small>
<hr>
+<p>
+
+<a href="contents.html#contents">contents</A>
+&middot;
+<a href="contents.html#index">index</A>
<!-- ====================================================================== -->
<p>
@@ -71,7 +78,7 @@ this document is dry in places.
For a discussion of the decisions behind the design of Lua,
see the technical papers available at Lua's web site.
For a detailed introduction to programming in Lua,
-see Roberto's book, <em>Programming in Lua</em>.
+see Roberto's book, <em>Programming in Lua (Second Edition)</em>.
@@ -390,8 +397,8 @@ Name denotes identifiers, as defined in <a href="#2.1">&sect;2.1</a>.
<p>
-Variables are assumed to be global unless explicitly declared local
-(see <a href="#2.4.7">&sect;2.4.7</a>).
+Any variable is assumed to be global unless explicitly declared
+as a local (see <a href="#2.4.7">&sect;2.4.7</a>).
Local variables are <em>lexically scoped</em>:
local variables can be freely accessed by functions
defined inside their scope (see <a href="#2.6">&sect;2.6</a>).
@@ -708,18 +715,18 @@ third <em>exp</em>.
More precisely, a <b>for</b> statement like
<pre>
- for var = e1, e2, e3 do block end
+ for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end
</pre><p>
is equivalent to the code:
<pre>
do
- local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
- if not (_var and _limit and _step) then error() end
- while (_step&gt;0 and _var&lt;=_limit) or (_step&lt;=0 and _var&gt;=_limit) do
- local var = _var
+ local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)
+ if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end
+ while (<em>step</em> &gt; 0 and <em>var</em> &lt;= <em>limit</em>) or (<em>step</em> &lt;= 0 and <em>var</em> &gt;= <em>limit</em>) do
+ local v = <em>var</em>
<em>block</em>
- _var = _var + _step
+ <em>var</em> = <em>var</em> + <em>step</em>
end
end
</pre><p>
@@ -734,7 +741,7 @@ They must all result in numbers.
</li>
<li>
-<code>_var</code>, <code>_limit</code>, and <code>_step</code> are invisible variables.
+<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.
The names are here for explanatory purposes only.
</li>
@@ -748,10 +755,10 @@ You can use <b>break</b> to exit a <b>for</b> loop.
</li>
<li>
-The loop variable <code>var</code> is local to the loop;
+The loop variable <code>v</code> is local to the loop;
you cannot use its value after the <b>for</b> ends or is broken.
-If you need the value of the loop variable <code>var</code>,
-then assign it to another variable before breaking or exiting the loop.
+If you need this value,
+assign it to another variable before breaking or exiting the loop.
</li>
</ul>
@@ -770,18 +777,18 @@ The generic <b>for</b> loop has the following syntax:
A <b>for</b> statement like
<pre>
- for var_1, &middot;&middot;&middot;, var_n in explist do block end
+ for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end
</pre><p>
is equivalent to the code:
<pre>
do
- local _f, _s, _var = explist
+ local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>
while true do
- local var_1, &middot;&middot;&middot;, var_n = _f(_s, _var)
- _var = var_1
- if _var == nil then break end
- block
+ local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)
+ <em>var</em> = <em>var_1</em>
+ if <em>var</em> == nil then break end
+ <em>block</em>
end
end
</pre><p>
@@ -790,13 +797,14 @@ Note the following:
<ul>
<li>
-<code>explist</code> is evaluated only once.
+<code><em>explist</em></code> is evaluated only once.
Its results are an <em>iterator</em> function,
-a <em>state</em>, and an initial value for the first <em>iterator variable</em>.
+a <em>state</em>,
+and an initial value for the first <em>iterator variable</em>.
</li>
<li>
-<code>_f</code>, <code>_s</code>, and <code>_var</code> are invisible variables.
+<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.
The names are here for explanatory purposes only.
</li>
@@ -805,7 +813,7 @@ You can use <b>break</b> to exit a <b>for</b> loop.
</li>
<li>
-The loop variables <code>var_i</code> are local to the loop;
+The loop variables <code><em>var_i</em></code> are local to the loop;
you cannot use their values after the <b>for</b> ends.
If you need these values,
then assign them to other variables before breaking or exiting the loop.
@@ -902,13 +910,13 @@ If the expression is used as a statement (see <a href="#2.4.6">&sect;2.4.6</a>)
(only possible for function calls),
then its return list is adjusted to zero elements,
thus discarding all returned values.
-If the expression is used inside another expression
-or in the middle of a list of expressions,
-then its result list is adjusted to one element,
-thus discarding all values except the first one.
-If the expression is used as the last element of a list of expressions,
-then no adjustment is made,
-unless the call is enclosed in parentheses.
+If the expression is used as the last (or the only) element
+of a list of expressions,
+then no adjustment is made
+(unless the call is enclosed in parentheses).
+In all other contexts,
+Lua adjusts the result list to one element,
+discarding all values except the first one.
<p>
@@ -917,17 +925,18 @@ Here are some examples:
<pre>
f() -- adjusted to 0 results
g(f(), x) -- f() is adjusted to 1 result
- g(x, f()) -- g gets x plus all values returned by f()
+ g(x, f()) -- g gets x plus all results from f()
a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil)
a,b = ... -- a gets the first vararg parameter, b gets
- -- the second (both a and b may get nil if there is
- -- no corresponding vararg parameter)
+ -- the second (both a and b may get nil if there
+ -- is no corresponding vararg parameter)
+
a,b,c = x, f() -- f() is adjusted to 2 results
a,b,c = f() -- f() is adjusted to 3 results
- return f() -- returns all values returned by f()
+ return f() -- returns all results from f()
return ... -- returns all received vararg parameters
- return x,y,f() -- returns x, y, and all values returned by f()
- {f()} -- creates a list with all values returned by f()
+ return x,y,f() -- returns x, y, and all results from f()
+ {f()} -- creates a list with all results from f()
{...} -- creates a list with all vararg parameters
{f(), nil} -- f() is adjusted to 1 result
</pre>
@@ -1543,8 +1552,7 @@ you must use the C&nbsp;API for that.
<p>
Tables and userdata have individual metatables
-(although multiple tables and userdata can share
-a same table as their metatable);
+(although multiple tables and userdata can share their metatables);
values of all other types share one single metatable per type.
So, there is one single metatable for all numbers,
and for all strings, etc.
@@ -1592,6 +1600,7 @@ This should be read as
<pre>
rawget(getmetatable(obj) or {}, event)
</pre><p>
+
That is, the access to a metamethod does not invoke other metamethods,
and the access to objects with no metatables does not fail
(it simply results in <b>nil</b>).
@@ -2077,7 +2086,7 @@ A table with both weak keys and weak values allows the collection of
both keys and values.
In any case, if either the key or the value is collected,
the whole pair is removed from the table.
-The weakness of a table is controlled by the value of the
+The weakness of a table is controlled by the
<code>__mode</code> field of its metatable.
If the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',
the keys in the table are weak.
@@ -2156,8 +2165,8 @@ arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code
<p>
-The <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function creates a coroutine,
-just like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
+Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
+the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine,
but instead of returning the coroutine itself,
it returns a function that, when called, resumes the coroutine.
Any arguments passed to this function
@@ -2198,6 +2207,7 @@ When you run it, it produces the following output:
<pre>
co-body 1 10
foo 2
+
main true 4
co-body r
main true 11 -9
@@ -2268,7 +2278,7 @@ then index&nbsp;1 represents the first element
and
index&nbsp;<em>n</em> represents the last element;
index&nbsp;-1 also represents the last element
-(that is, the element at the top)
+(that is, the element at the&nbsp;top)
and index <em>-n</em> represents the first element.
We say that an index is <em>valid</em>
if it lies between&nbsp;1 and the stack top
@@ -2473,21 +2483,25 @@ Lua assumes that the allocator never fails when
<p>
Here is a simple implementation for the allocator function.
-It is used in the auxiliary library by <a href="#lua_newstate"><code>lua_newstate</code></a>.
+It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
<pre>
- static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
- (void)ud; /* not used */
- (void)osize; /* not used */
+ static void *l_alloc (void *ud, void *ptr, size_t osize,
+ size_t nsize) {
+ (void)ud; (void)osize; /* not used */
if (nsize == 0) {
- free(ptr); /* ANSI requires that free(NULL) has no effect */
+ free(ptr);
return NULL;
}
else
- /* ANSI requires that realloc(NULL, size) == malloc(size) */
return realloc(ptr, nsize);
}
-</pre>
+</pre><p>
+This code assumes
+that <code>free(NULL)</code> has no effect and that
+<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
+ANSI&nbsp;C ensures both behaviors.
+
@@ -2557,14 +2571,14 @@ equivalent to this Lua code:
Here it is in&nbsp;C:
<pre>
- lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
- lua_pushstring(L, "how"); /* 1st argument */
- lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
- lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
- lua_remove(L, -2); /* remove 't' from the stack */
- lua_pushinteger(L, 14); /* 3rd argument */
- lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */
- lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable 'a' */
+ lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
+ lua_pushstring(L, "how"); /* 1st argument */
+ lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
+ lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
+ lua_remove(L, -2); /* remove 't' from the stack */
+ lua_pushinteger(L, 14); /* 3rd argument */
+ lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */
+ lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global 'a' */
</pre><p>
Note that the code above is "balanced":
at its end, the stack is back to its original configuration.
@@ -2611,7 +2625,7 @@ of numerical arguments and returns their average and sum:
int i;
for (i = 1; i &lt;= n; i++) {
if (!lua_isnumber(L, i)) {
- lua_pushstring(L, "incorrect argument to function 'average'");
+ lua_pushstring(L, "incorrect argument");
lua_error(L);
}
sum += lua_tonumber(L, i);
@@ -2723,7 +2737,7 @@ to write them.
<p>
The value returned is the error code returned by the last
call to the writer;
-0 means no errors.
+0&nbsp;means no errors.
<p>
@@ -2814,7 +2828,7 @@ The function returns the previous value of the pause.
</li>
<li><b><code>LUA_GCSETSTEPMUL</code>:</b>
-sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of
+sets <code>data</code>/100 as the new value for the <em>step multiplier</em> of
the collector (see <a href="#2.10">&sect;2.10</a>).
The function returns the previous value of the step multiplier.
</li>
@@ -2942,7 +2956,7 @@ The type used by the Lua API to represent integral values.
<p>
By default it is a <code>ptrdiff_t</code>,
-which is usually the largest integral type the machine handles
+which is usually the largest signed integral type the machine handles
"comfortably".
@@ -2954,7 +2968,7 @@ which is usually the largest integral type the machine handles
<p>
Returns 1 if the value at the given acceptable index has type boolean,
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -2965,7 +2979,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a C&nbsp;function,
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -2976,7 +2990,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a function
-(either C or Lua), and 0 otherwise.
+(either C or Lua), and 0&nbsp;otherwise.
@@ -2987,7 +3001,7 @@ Returns 1 if the value at the given acceptable index is a function
<p>
Returns 1 if the value at the given acceptable index is a light userdata,
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -2998,7 +3012,32 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is <b>nil</b>,
-and 0 otherwise.
+and 0&nbsp;otherwise.
+
+
+
+
+
+<hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3>
+<pre>int lua_isnone (lua_State *L, int index);</pre>
+
+<p>
+Returns 1 if the the given acceptable index is not valid
+(that is, it refers to an element outside the current stack),
+and 0&nbsp;otherwise.
+
+
+
+
+
+<hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3>
+<pre>int lua_isnoneornil (lua_State *L, int index);</pre>
+
+<p>
+Returns 1 if the the given acceptable index is not valid
+(that is, it refers to an element outside the current stack)
+or if the value at this index is <b>nil</b>,
+and 0&nbsp;otherwise.
@@ -3010,7 +3049,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a number
or a string convertible to a number,
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -3022,7 +3061,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a string
or a number (which is always convertible to a string),
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -3033,7 +3072,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a table,
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -3044,7 +3083,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a thread,
-and 0 otherwise.
+and 0&nbsp;otherwise.
@@ -3055,7 +3094,7 @@ and 0 otherwise.
<p>
Returns 1 if the value at the given acceptable index is a userdata
-(either full or light), and 0 otherwise.
+(either full or light), and 0&nbsp;otherwise.
@@ -3113,8 +3152,8 @@ and loads it accordingly (see program <code>luac</code>).
<p>
-<a href="#lua_load"><code>lua_load</code></a> uses a user-supplied <code>reader</code> function to read the chunk
-(see <a href="#lua_Reader"><code>lua_Reader</code></a>).
+The <a href="#lua_load"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function
+to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
The <code>data</code> argument is an opaque value passed to the reader function.
@@ -3219,10 +3258,12 @@ A typical traversal looks like this:
/* table is in the stack at index 't' */
lua_pushnil(L); /* first key */
while (lua_next(L, t) != 0) {
- /* 'key' is at index -2 and 'value' at index -1 */
+ /* uses 'key' (at index -2) and 'value' (at index -1) */
printf("%s - %s\n",
- lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)));
- lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */
+ lua_typename(L, lua_type(L, -2)),
+ lua_typename(L, lua_type(L, -1)));
+ /* removes 'value'; keeps 'key' for next iteration */
+ lua_pop(L, 1);
}
</pre>
@@ -3270,7 +3311,7 @@ for other values, it is&nbsp;0.
<hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3>
-<pre>lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre>
+<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre>
<p>
Calls a function in protected mode.
@@ -3396,9 +3437,11 @@ and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code><
<p>
-The call <code>lua_pushcfunction(L, f)</code> is equivalent to
-<code>lua_pushcclosure(L, f, 0)</code>.
+<code>lua_pushcfunction</code> is defined as a macro:
+<pre>
+ #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
+</pre>
@@ -3642,14 +3685,17 @@ The reader function may return pieces of any size greater than zero.
<hr><h3><a name="lua_register"><code>lua_register</code></a></h3>
-<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>
+<pre>void lua_register (lua_State *L,
+ const char *name,
+ lua_CFunction f);</pre>
<p>
Sets the C function <code>f</code> as the new value of global <code>name</code>.
It is defined as a macro:
<pre>
- #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
+ #define lua_register(L,n,f) \
+ (lua_pushcfunction(L, f), lua_setglobal(L, n))
</pre>
@@ -3905,8 +3951,7 @@ it is truncated in some non-specified way.
<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>
<p>
-Converts the Lua value at the given acceptable index to a string
-(<code>const char*</code>).
+Converts the Lua value at the given acceptable index to a C&nbsp;string.
If <code>len</code> is not <code>NULL</code>,
it also sets <code>*len</code> with the string length.
The Lua value must be a string or a number;
@@ -3937,7 +3982,7 @@ will be valid after the corresponding value is removed from the stack.
<p>
Converts the Lua value at the given acceptable index
-to a number (see <a href="#lua_Number"><code>lua_Number</code></a>).
+to the C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>).
The Lua value must be a number or a string convertible to a number
(see <a href="#2.2.1">&sect;2.2.1</a>);
otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns&nbsp;0.
@@ -4054,7 +4099,7 @@ and the <code>data</code> parameter supplied to <a href="#lua_dump"><code>lua_du
<p>
The writer returns an error code:
-0 means no errors;
+0&nbsp;means no errors;
any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
calling the writer again.
@@ -4279,8 +4324,8 @@ a value to be pushed on the stack:
</li>
<li><b>'<code>S</code>':</b>
-fills in the fields <code>source</code>, <code>linedefined</code>,
-<code>lastlinedefined</code>, <code>what</code>, and <code>short_src</code>;
+fills in the fields <code>source</code>, <code>short_src</code>,
+<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
</li>
<li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>;
@@ -4313,7 +4358,7 @@ This function returns 0 on error
<hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3>
-<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre>
+<pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>
<p>
Gets information about a local variable of a given activation record.
@@ -4424,14 +4469,14 @@ this execution occurs without any calls to hooks.
<hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3>
-<pre>int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);</pre>
+<pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>
<p>
Sets the debugging hook function.
<p>
-<code>func</code> is the hook function.
+Argument <code>f</code> is the hook function.
<code>mask</code> specifies on which events the hook will be called:
it is formed by a bitwise or of the constants
<a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,
@@ -4475,7 +4520,7 @@ A hook is disabled by setting <code>mask</code> to zero.
<hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3>
-<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre>
+<pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre>
<p>
Sets the value of a local variable of a given activation record.
@@ -4500,11 +4545,11 @@ the number of active local variables.
<p>
Sets the value of a closure's upvalue.
-Parameters <code>funcindex</code> and <code>n</code> are as in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
-(see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>).
It assigns the value at the top of the stack
to the upvalue and returns its name.
It also pops the value from the stack.
+Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
+(see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>).
<p>
@@ -4588,9 +4633,9 @@ The string may contain embedded zeros.
<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>
<p>
-Adds a string of length <code>n</code> previously copied to the
-buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to the buffer <code>B</code>
-(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
+Adds to the buffer <code>B</code> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>)
+a string of length <code>n</code> previously copied to the
+buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
@@ -4631,7 +4676,7 @@ which is the value to be added to the buffer.
<hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3>
<pre>void luaL_argcheck (lua_State *L,
int cond,
- int numarg,
+ int narg,
const char *extramsg);</pre>
<p>
@@ -4640,21 +4685,21 @@ If not, raises an error with the following message,
where <code>func</code> is retrieved from the call stack:
<pre>
- bad argument #&lt;numarg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
+ bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
</pre>
<hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3>
-<pre>int luaL_argerror (lua_State *L, int numarg, const char *extramsg);</pre>
+<pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre>
<p>
Raises an error with the following message,
where <code>func</code> is retrieved from the call stack:
<pre>
- bad argument #&lt;numarg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
+ bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
</pre>
<p>
@@ -5079,9 +5124,10 @@ with <code>tname</code> in the registry.
<pre>lua_State *luaL_newstate (void);</pre>
<p>
-Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an
-allocation function based on the standard&nbsp;C <code>realloc</code> function
-and setting a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
+Creates a new Lua state.
+It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
+allocator based on the standard&nbsp;C <code>realloc</code> function
+and then sets a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
an error message to the standard error output in case of fatal
errors.
@@ -5119,7 +5165,9 @@ Otherwise, raises an error.
<hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3>
-<pre>lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer d);</pre>
+<pre>lua_Integer luaL_optinteger (lua_State *L,
+ int narg,
+ lua_Integer d);</pre>
<p>
If the function argument <code>narg</code> is a number,
@@ -5183,7 +5231,9 @@ Otherwise, raises an error.
<hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3>
-<pre>const char *luaL_optstring (lua_State *L, int narg, const char *d);</pre>
+<pre>const char *luaL_optstring (lua_State *L,
+ int narg,
+ const char *d);</pre>
<p>
If the function argument <code>narg</code> is a string,
@@ -5285,7 +5335,7 @@ it simply registers all functions in the list <code>l</code>
<p>
When called with a non-null <code>libname</code>,
-creates a new table <code>t</code>,
+<code>luaL_register</code> creates a new table <code>t</code>,
sets it as the value of the global variable <code>libname</code>,
sets it as the value of <code>package.loaded[libname]</code>,
and registers on it all functions in the list <code>l</code>.
@@ -5316,14 +5366,14 @@ Returns the name of the type of the value at index <code>idx</code>.
<pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre>
<p>
-Generates an error with a message like
+Generates an error with a message like the following:
<pre>
- &lt;location&gt;: bad argument &lt;narg&gt; to &lt;function&gt; (&lt;tname&gt; expected, got &lt;realt&gt;)
+ <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>)
</pre><p>
-where <code>&lt;location&gt;</code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
-<code>&lt;function&gt;</code> is the name of the current function,
-and <code>&lt;realt&gt;</code> is the type name of the actual argument.
+where <code><em>location</em></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
+<code><em>func</em></code> is the name of the current function,
+and <code><em>rt</em></code> is the type name of the actual argument.
@@ -5354,7 +5404,11 @@ If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a
<p>
Pushes onto the stack a string identifying the current position
of the control at level <code>lvl</code> in the call stack.
-Typically this string has the format <code>&lt;chunkname&gt;:&lt;currentline&gt;:</code>.
+Typically this string has the following format:
+
+<pre>
+ <em>chunkname</em>:<em>currentline</em>:
+</pre><p>
Level&nbsp;0 is the running function,
level&nbsp;1 is the function that called the running function,
etc.
@@ -5413,9 +5467,8 @@ or as methods of its objects.
<p>
To have access to these libraries,
-the C&nbsp;host program must call
-<a href="#luaL_openlibs"><code>luaL_openlibs</code></a>,
-which open all standard libraries.
+the C&nbsp;host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> function,
+which opens all standard libraries.
Alternatively,
it can open them individually by calling
<a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
@@ -5547,7 +5600,7 @@ nor vice-versa.
<p>
-<hr><h3><a name="pdf-getfenv"><code>getfenv (f)</code></a></h3>
+<hr><h3><a name="pdf-getfenv"><code>getfenv ([f])</code></a></h3>
Returns the current environment in use by the function.
<code>f</code> can be a Lua function or a number
that specifies the function at that stack level:
@@ -5589,10 +5642,6 @@ will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middo
up to the first integer key absent from the table.
-<p>
-See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
-
-
<p>
@@ -5704,7 +5753,8 @@ will iterate over all key&ndash;value pairs of table <code>t</code>.
<p>
-See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
+See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
+the table during its traversal.
@@ -5911,7 +5961,7 @@ The current contents of this variable is "<code>Lua 5.1</code>".
<p>
-This function is similar to <code>pcall</code>,
+This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
except that you can set a new error handler.
@@ -6101,7 +6151,7 @@ where each option is a function to be applied over the module.
<p>
Loads the given module.
-The function starts by looking into the table <a href="#pdf-package.loaded"><code>package.loaded</code></a>
+The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></a> table
to determine whether <code>modname</code> is already loaded.
If it is, then <code>require</code> returns the value stored
at <code>package.loaded[modname]</code>.
@@ -6156,7 +6206,7 @@ with each submodule keeping its original open function.
Once a loader is found,
<code>require</code> calls the loader with a single argument, <code>modname</code>.
If the loader returns any value,
-<code>require</code> assigns it to <code>package.loaded[modname]</code>.
+<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
If the loader returns no value and
has not assigned any value to <code>package.loaded[modname]</code>,
then <code>require</code> assigns <b>true</b> to this entry.
@@ -6190,6 +6240,7 @@ using the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a
<p>
+
<hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>
@@ -6426,7 +6477,8 @@ whereas <code>q</code> and <code>s</code> expect a string.
<p>
This function does not accept string values
-containing embedded zeros.
+containing embedded zeros,
+except as arguments to the <code>q</code> option.
@@ -6436,9 +6488,6 @@ containing embedded zeros.
Returns an iterator function that,
each time it is called,
returns the next captures from <code>pattern</code> over string <code>s</code>.
-
-
-<p>
If <code>pattern</code> specifies no captures,
then the whole match is produced in each call.
@@ -6465,6 +6514,11 @@ given string into a table:
end
</pre>
+<p>
+For this function, a '<code>^</code>' at the start of a pattern does not
+work as an anchor, as this would prevent the iteration.
+
+
<p>
@@ -6540,7 +6594,7 @@ Here are some examples:
--&gt; x="4+5 = 9"
local t = {name="lua", version="5.1"}
- x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t)
+ x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
--&gt; x="lua-5.1.tar.gz"
</pre>
@@ -6824,7 +6878,8 @@ we mean the result of the length operator.
<p>
<hr><h3><a name="pdf-table.concat"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3>
-Returns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.
+Given an array where all elements are strings or numbers,
+returns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.
The default value for <code>sep</code> is the empty string,
the default for <code>i</code> is 1,
and the default for <code>j</code> is the length of the table.
@@ -7122,7 +7177,7 @@ the integral part of <code>x</code> and the fractional part of <code>x</code>.
<p>
-The value PI.
+The value of <em>pi</em>.
@@ -7266,7 +7321,8 @@ three predefined file descriptors with their usual meanings from C:
<p>
Unless otherwise stated,
all I/O functions return <b>nil</b> on failure
-(plus an error message as a second result)
+(plus an error message as a second result and
+a system-dependent error code as a third result)
and some value different from <b>nil</b> on success.
@@ -7331,7 +7387,7 @@ it returns <b>nil</b> (to finish the loop) and automatically closes the file.
<p>
-The call <code>io.lines()</code> (without a file name) is equivalent
+The call <code>io.lines()</code> (with no file name) is equivalent
to <code>io.input():lines()</code>;
that is, it iterates over the lines of the default input file.
In this case it does not close the file when the loop ends.
@@ -7381,7 +7437,7 @@ Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over
<p>
-<hr><h3><a name="pdf-io.popen"><code>io.popen ([prog [, mode]])</code></a></h3>
+<hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3>
<p>
@@ -7596,7 +7652,7 @@ or there is any input from some special files
</li>
</ul><p>
-For the last two cases, <code>sizes</code>
+For the last two cases, <code>size</code>
specifies the size of the buffer, in bytes.
The default is an appropriate size.
@@ -7657,7 +7713,7 @@ Otherwise, <code>date</code> formats the current time.
If <code>format</code> starts with '<code>!</code>',
then the date is formatted in Coordinated Universal Time.
After this optional character,
-if <code>format</code> is <code>*t</code>,
+if <code>format</code> is the string "<code>*t</code>",
then <code>date</code> returns a table with the following fields:
<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),
<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),
@@ -7667,7 +7723,7 @@ and <code>isdst</code> (daylight saving flag, a boolean).
<p>
-If <code>format</code> is not <code>*t</code>,
+If <code>format</code> is not "<code>*t</code>",
then <code>date</code> returns the date as a string,
formatted according to the same rules as the C&nbsp;function <code>strftime</code>.
@@ -7772,6 +7828,13 @@ or <b>nil</b> if the request cannot be honored.
<p>
+If <code>locale</code> is the empty string,
+the current locate is set to an implementation-defined native locale.
+If <code>locate</code> is the string "<code>C</code>",
+the current locate is set to the standard C locale.
+
+
+<p>
When called with <b>nil</b> as the first argument,
this function only returns the name of the current locale
for the given category.
@@ -7921,7 +7984,8 @@ valid lines.
<p>
For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
a name of the current function, if a reasonable name can be found,
-and <code>debug.getinfo(print)</code> returns a table with all available information
+and the expression <code>debug.getinfo(print)</code>
+returns a table with all available information
about the <a href="#pdf-print"><code>print</code></a> function.
@@ -8080,15 +8144,16 @@ Otherwise, it returns the name of the upvalue.
<p>
-<hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message])</code></a></h3>
+<hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message] [, level])</code></a></h3>
<p>
Returns a string with a traceback of the call stack.
An optional <code>message</code> string is appended
-at the beginning of the traceback.
-This function is typically used with <a href="#pdf-xpcall"><code>xpcall</code></a> to produce
-better error messages.
+at the beginning of the traceback.
+An optional <code>level</code> number tells at which level
+to start the traceback
+(default is 1, the function calling <code>traceback</code>).
@@ -8232,7 +8297,7 @@ is a more portable solution.)
<h1>7 - <a name="7">Incompatibilities with the Previous Version</a></h1>
<p>
-Here we list the incompatibilities that may be found when moving a program
+Here we list the incompatibilities that you may found when moving a program
from Lua&nbsp;5.0 to Lua&nbsp;5.1.
You can avoid most of the incompatibilities compiling Lua with
appropriate options (see file <code>luaconf.h</code>).
@@ -8247,7 +8312,7 @@ all these compatibility options will be removed in the next version of Lua.
<li>
The vararg system changed from the pseudo-argument <code>arg</code> with a
table with the extra arguments to the vararg expression.
-(Option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)
+(See compile-time option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)
</li>
<li>
@@ -8259,7 +8324,7 @@ variables of the <b>for</b> statement and for the <b>repeat</b> statement.
The long string/long comment syntax (<code>[[<em>string</em>]]</code>)
does not allow nesting.
You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases.
-(Option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)
+(See compile-time option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)
</li>
</ul>
@@ -8272,7 +8337,7 @@ You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases.
<li>
Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.
-(Option <code>LUA_COMPAT_GFIND</code>)
+(See compile-time option <code>LUA_COMPAT_GFIND</code> in <code>luaconf.h</code>.)
</li>
<li>
@@ -8288,17 +8353,17 @@ Function <code>table.setn</code> was deprecated.
Function <code>table.getn</code> corresponds
to the new length operator (<code>#</code>);
use the operator instead of the function.
-(Option <code>LUA_COMPAT_GETN</code>)
+(See compile-time option <code>LUA_COMPAT_GETN</code> in <code>luaconf.h</code>.)
</li>
<li>
Function <code>loadlib</code> was renamed <a href="#pdf-package.loadlib"><code>package.loadlib</code></a>.
-(Option <code>LUA_COMPAT_LOADLIB</code>)
+(See compile-time option <code>LUA_COMPAT_LOADLIB</code> in <code>luaconf.h</code>.)
</li>
<li>
Function <code>math.mod</code> was renamed <a href="#pdf-math.fmod"><code>math.fmod</code></a>.
-(Option <code>LUA_COMPAT_MOD</code>)
+(See compile-time option <code>LUA_COMPAT_MOD</code> in <code>luaconf.h</code>.)
</li>
<li>
@@ -8446,10 +8511,10 @@ Here is the complete syntax of Lua in extended BNF.
<HR>
<SMALL>
Last update:
-Mon Jun 5 17:05:27 BRT 2006
+Fri Mar 23 14:37:09 BRT 2007
</SMALL>
<!--
-Last change: ready for Lua 5.1.1
+Last change: ready for Lua 5.1.2
-->
</body></html>
diff --git a/doc/readme.html b/doc/readme.html
index db20a69a..28b1d147 100644
--- a/doc/readme.html
+++ b/doc/readme.html
@@ -4,7 +4,7 @@
<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
</HEAD>
-<BODY BGCOLOR="#FFFFFF">
+<BODY>
<HR>
<H1>
@@ -12,8 +12,9 @@
Documentation
</H1>
+This is the documentation included in the source distribution of Lua 5.1.2.
+
<UL>
-<LI><A HREF="http://www.lua.org/">Official web site</A>
<LI><A HREF="contents.html">Reference manual</A>
<LI><A HREF="lua.html">lua man page</A>
<LI><A HREF="luac.html">luac man page</A>
@@ -22,10 +23,17 @@ Documentation
<LI><A HREF="../test/README">lua/test/README</A>
</UL>
+Lua's
+<A HREF="http://www.lua.org/">official web site</A>
+contains updated documentation,
+especially the
+<A HREF="http://www.lua.org/manual/5.1/">reference manual</A>.
+<P>
+
<HR>
<SMALL>
Last update:
-Wed Sep 7 12:57:50 BRST 2005
+Fri Mar 23 14:19:36 BRT 2007
</SMALL>
</BODY>
diff --git a/src/lbaselib.c b/src/lbaselib.c
index 2df437b0..147a727e 100644
--- a/src/lbaselib.c
+++ b/src/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp $
+** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) {
}
-static void getfunc (lua_State *L) {
+static void getfunc (lua_State *L, int opt) {
if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
else {
lua_Debug ar;
- int level = luaL_optint(L, 1, 1);
+ int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
if (lua_getstack(L, level, &ar) == 0)
luaL_argerror(L, 1, "invalid level");
@@ -131,7 +131,7 @@ static void getfunc (lua_State *L) {
static int luaB_getfenv (lua_State *L) {
- getfunc(L);
+ getfunc(L, 1);
if (lua_iscfunction(L, -1)) /* is a C function? */
lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
else
@@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) {
static int luaB_setfenv (lua_State *L) {
luaL_checktype(L, 2, LUA_TTABLE);
- getfunc(L);
+ getfunc(L, 0);
lua_pushvalue(L, 2);
if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
/* change environment of current thread */
diff --git a/src/lcode.c b/src/lcode.c
index b71acd84..9ce515ab 100644
--- a/src/lcode.c
+++ b/src/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $
+** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) {
void luaK_nil (FuncState *fs, int from, int n) {
Instruction *previous;
if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
- if (fs->pc == 0) /* function start? */
- return; /* positions are already clean */
- if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
- int pfrom = GETARG_A(*previous);
- int pto = GETARG_B(*previous);
- if (pfrom <= from && from <= pto+1) { /* can connect both? */
- if (from+n-1 > pto)
- SETARG_B(*previous, from+n-1);
- return;
+ if (fs->pc == 0) { /* function start? */
+ if (from >= fs->nactvar)
+ return; /* positions are already clean */
+ }
+ else {
+ previous = &fs->f->code[fs->pc-1];
+ if (GET_OPCODE(*previous) == OP_LOADNIL) {
+ int pfrom = GETARG_A(*previous);
+ int pto = GETARG_B(*previous);
+ if (pfrom <= from && from <= pto+1) { /* can connect both? */
+ if (from+n-1 > pto)
+ SETARG_B(*previous, from+n-1);
+ return;
+ }
}
}
}
@@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
if (constfolding(op, e1, e2))
return;
else {
- int o1 = luaK_exp2RK(fs, e1);
int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
- freeexp(fs, e2);
- freeexp(fs, e1);
+ int o1 = luaK_exp2RK(fs, e1);
+ if (o1 > o2) {
+ freeexp(fs, e1);
+ freeexp(fs, e2);
+ }
+ else {
+ freeexp(fs, e2);
+ freeexp(fs, e1);
+ }
e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
e1->k = VRELOCABLE;
}
@@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
break;
}
- default: {
+ case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
+ case OPR_MOD: case OPR_POW: {
if (!isnumeral(v)) luaK_exp2RK(fs, v);
break;
}
+ default: {
+ luaK_exp2RK(fs, v);
+ break;
+ }
}
}
diff --git a/src/ldebug.c b/src/ldebug.c
index 8919a017..9c8bdf2f 100644
--- a/src/ldebug.c
+++ b/src/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $
+** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
break;
}
case OP_CLOSURE: {
- int nup;
+ int nup, j;
check(b < pt->sizep);
nup = pt->p[b]->nups;
check(pc + nup < pt->sizecode);
- for (; nup>0; nup--) {
- OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
+ for (j = 1; j <= nup; j++) {
+ OpCode op1 = GET_OPCODE(pt->code[pc + j]);
check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
}
+ if (reg != NO_REG) /* tracing? */
+ pc += nup; /* do not 'execute' these pseudo-instructions */
break;
}
case OP_VARARG: {
diff --git a/src/loslib.c b/src/loslib.c
index 7c6c5d61..fdda4741 100644
--- a/src/loslib.c
+++ b/src/loslib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $
+** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@@ -146,11 +146,22 @@ static int os_date (lua_State *L) {
setboolfield(L, "isdst", stm->tm_isdst);
}
else {
- char b[256];
- if (strftime(b, sizeof(b), s, stm))
- lua_pushstring(L, b);
- else
- return luaL_error(L, LUA_QL("date") " format too long");
+ char cc[3];
+ luaL_Buffer b;
+ cc[0] = '%'; cc[2] = '\0';
+ luaL_buffinit(L, &b);
+ for (; *s; s++) {
+ if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
+ luaL_addchar(&b, *s);
+ else {
+ size_t reslen;
+ char buff[200]; /* should be big enough for any conversion result */
+ cc[1] = *(++s);
+ reslen = strftime(buff, sizeof(buff), cc, stm);
+ luaL_addlstring(&b, buff, reslen);
+ }
+ }
+ luaL_pushresult(&b);
}
return 1;
}
diff --git a/src/lparser.c b/src/lparser.c
index a9be740e..6c473c41 100644
--- a/src/lparser.c
+++ b/src/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp $
+** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -489,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
static void listfield (LexState *ls, struct ConsControl *cc) {
expr(ls, &cc->v);
- luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor");
+ luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
cc->na++;
cc->tostore++;
}
diff --git a/src/lstrlib.c b/src/lstrlib.c
index f93a8af0..fc7ae489 100644
--- a/src/lstrlib.c
+++ b/src/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $
+** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
const char *p = strfrmt;
- while (strchr(FLAGS, *p)) p++; /* skip flags */
+ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
luaL_error(L, "invalid format (repeated flags)");
if (isdigit(uchar(*p))) p++; /* skip width */
diff --git a/src/lua.h b/src/lua.h
index 064ff6fb..2865a7fa 100644
--- a/src/lua.h
+++ b/src/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.218 2006/06/02 15:34:00 roberto Exp $
+** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@@ -17,9 +17,9 @@
#define LUA_VERSION "Lua 5.1"
-#define LUA_RELEASE "Lua 5.1.1"
+#define LUA_RELEASE "Lua 5.1.2"
#define LUA_VERSION_NUM 501
-#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
+#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@@ -359,7 +359,7 @@ struct lua_Debug {
/******************************************************************************
-* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.
+* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
diff --git a/src/print.c b/src/print.c
index 2a4fb3ed..430af836 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,5 +1,5 @@
/*
-** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $
+** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
*/
@@ -32,6 +32,7 @@ static void PrintString(const TString* ts)
switch (c)
{
case '"': printf("\\\""); break;
+ case '\\': printf("\\\\"); break;
case '\a': printf("\\a"); break;
case '\b': printf("\\b"); break;
case '\f': printf("\\f"); break;