Merged in changes from Lua 5.1.2 (hopefully didn't miss anything)

Originally committed to SVN as r980.
This commit is contained in:
Niels Martin Hansen 2007-04-03 00:37:09 +00:00
parent 292ad1af33
commit 325b88df19
28 changed files with 5411 additions and 2977 deletions

View File

@ -2,27 +2,59 @@
<HEAD>
<TITLE>Lua 5.1 reference manual - contents</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
<STYLE TYPE="text/css">
ul {
list-style-type: none ;
list-style-position: outside ;
}
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<BODY>
<HR>
<H1>
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A>
Lua 5.1 Reference Manual
</H1>
<SMALL>
<A HREF="http://www.lua.org/copyright.html">Copyright</A>
&copy; 2006 Lua.org, PUC-Rio. All rights reserved.
</SMALL>
<HR>
<H2>Contents</H2>
<UL>
<LI><A HREF="#quick">Quick index</A>
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>
<LI><A HREF="manual.html">Top</A>
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#1">1 - Introduction</A>
<LI><A HREF="manual.html#2">2 - The Language</A>
<UL>
@ -86,6 +118,9 @@ Lua 5.1 Reference Manual
<LI><A HREF="manual.html#5.2">5.2 - Coroutine Manipulation</A>
<LI><A HREF="manual.html#5.3">5.3 - Modules</A>
<LI><A HREF="manual.html#5.4">5.4 - String Manipulation</A>
<UL>
<LI><A HREF="manual.html#5.4.1">5.4.1 - Patterns</A>
</UL>
<LI><A HREF="manual.html#5.5">5.5 - Table Manipulation</A>
<LI><A HREF="manual.html#5.6">5.6 - Mathematical Functions</A>
<LI><A HREF="manual.html#5.7">5.7 - Input and Output Facilities</A>
@ -93,20 +128,53 @@ Lua 5.1 Reference Manual
<LI><A HREF="manual.html#5.9">5.9 - The Debug Library</A>
</UL>
<LI><A HREF="manual.html#6">6 - Lua Stand-alone</A>
<LI><A HREF="manual.html#incompat">Incompatibilities with the Previous Version</A>
<LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>
<LI><A HREF="manual.html#7">7 - Incompatibilities with the Previous Version</A>
<UL>
<LI><A HREF="manual.html#7.1">7.1 - Changes in the Language</A>
<LI><A HREF="manual.html#7.2">7.2 - Changes in the Libraries</A>
<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="quick">Quick index</A></H2>
<TABLE>
<H2><A NAME="index">Index</A></H2>
<TABLE WIDTH="100%">
<TR VALIGN="top">
<TD WIDTH="35%">
<H3><A NAME="functions">Functions</A></H3>
<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>
<A HREF="manual.html#pdf-assert">assert</A><BR>
<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
<A HREF="manual.html#pdf-dofile">dofile</A><BR>
<A HREF="manual.html#pdf-error">error</A><BR>
<A HREF="manual.html#pdf-getfenv">getfenv</A><BR>
<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
<A HREF="manual.html#pdf-load">load</A><BR>
<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
<A HREF="manual.html#pdf-module">module</A><BR>
<A HREF="manual.html#pdf-next">next</A><BR>
<A HREF="manual.html#pdf-pairs">pairs</A><BR>
<A HREF="manual.html#pdf-pcall">pcall</A><BR>
<A HREF="manual.html#pdf-print">print</A><BR>
<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
<A HREF="manual.html#pdf-rawget">rawget</A><BR>
<A HREF="manual.html#pdf-rawset">rawset</A><BR>
<A HREF="manual.html#pdf-require">require</A><BR>
<A HREF="manual.html#pdf-select">select</A><BR>
<A HREF="manual.html#pdf-setfenv">setfenv</A><BR>
<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>
<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
<A HREF="manual.html#pdf-tostring">tostring</A><BR>
<A HREF="manual.html#pdf-type">type</A><BR>
<A HREF="manual.html#pdf-unpack">unpack</A><BR>
<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
</TD>
<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>
<A HREF="manual.html#pdf-coroutine.running">coroutine.running</A><BR>
@ -127,8 +195,6 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-debug.setmetatable">debug.setmetatable</A><BR>
<A HREF="manual.html#pdf-debug.setupvalue">debug.setupvalue</A><BR>
<A HREF="manual.html#pdf-debug.traceback">debug.traceback</A><BR>
<A HREF="manual.html#pdf-dofile">dofile</A><BR>
<A HREF="manual.html#pdf-error">error</A><BR>
<A HREF="manual.html#pdf-file:close">file:close</A><BR>
<A HREF="manual.html#pdf-file:flush">file:flush</A><BR>
<A HREF="manual.html#pdf-file:lines">file:lines</A><BR>
@ -136,8 +202,6 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-file:seek">file:seek</A><BR>
<A HREF="manual.html#pdf-file:setvbuf">file:setvbuf</A><BR>
<A HREF="manual.html#pdf-file:write">file:write</A><BR>
<A HREF="manual.html#pdf-getfenv">getfenv</A><BR>
<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
<A HREF="manual.html#pdf-io.close">io.close</A><BR>
<A HREF="manual.html#pdf-io.flush">io.flush</A><BR>
<A HREF="manual.html#pdf-io.input">io.input</A><BR>
@ -149,10 +213,6 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-io.tmpfile">io.tmpfile</A><BR>
<A HREF="manual.html#pdf-io.type">io.type</A><BR>
<A HREF="manual.html#pdf-io.write">io.write</A><BR>
<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
<A HREF="manual.html#pdf-load">load</A><BR>
<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
@ -166,12 +226,14 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>
<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>
<A HREF="manual.html#pdf-math.frexp">math.frexp</A><BR>
<A HREF="manual.html#pdf-math.huge">math.huge</A><BR>
<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
<A HREF="manual.html#pdf-math.log10">math.log10</A><BR>
<A HREF="manual.html#pdf-math.log">math.log</A><BR>
<A HREF="manual.html#pdf-math.max">math.max</A><BR>
<A HREF="manual.html#pdf-math.min">math.min</A><BR>
<A HREF="manual.html#pdf-math.modf">math.modf</A><BR>
<A HREF="manual.html#pdf-math.pi">math.pi</A><BR>
<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>
<A HREF="manual.html#pdf-math.rad">math.rad</A><BR>
<A HREF="manual.html#pdf-math.random">math.random</A><BR>
@ -181,8 +243,6 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>
<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>
<A HREF="manual.html#pdf-module">module</A><BR>
<A HREF="manual.html#pdf-next">next</A><BR>
<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
<A HREF="manual.html#pdf-os.date">os.date</A><BR>
<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
@ -200,16 +260,6 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-package.path">package.path</A><BR>
<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>
<A HREF="manual.html#pdf-pairs">pairs</A><BR>
<A HREF="manual.html#pdf-pcall">pcall</A><BR>
<A HREF="manual.html#pdf-print">print</A><BR>
<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
<A HREF="manual.html#pdf-rawget">rawget</A><BR>
<A HREF="manual.html#pdf-rawset">rawset</A><BR>
<A HREF="manual.html#pdf-require">require</A><BR>
<A HREF="manual.html#pdf-select">select</A><BR>
<A HREF="manual.html#pdf-setfenv">setfenv</A><BR>
<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>
<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
<A HREF="manual.html#pdf-string.char">string.char</A><BR>
<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
@ -229,15 +279,10 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#pdf-table.maxn">table.maxn</A><BR>
<A HREF="manual.html#pdf-table.remove">table.remove</A><BR>
<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
<A HREF="manual.html#pdf-tostring">tostring</A><BR>
<A HREF="manual.html#pdf-type">type</A><BR>
<A HREF="manual.html#pdf-unpack">unpack</A><BR>
<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
</TD>
<TD>
<H3>API</H3>
<H3>C API</H3>
<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
@ -337,12 +382,13 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
<A HREF="manual.html#lua_type">lua_type</A><BR>
<A HREF="manual.html#lua_typename">lua_typename</A><BR>
<A HREF="manual.html#lua_upvalueindex">lua_upvalueindex</A><BR>
<A HREF="manual.html#lua_xmove">lua_xmove</A><BR>
<A HREF="manual.html#lua_yield">lua_yield</A><BR>
</TD>
<TD>
<H3>Auxiliary library</H3>
<H3>auxiliary library</H3>
<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>
@ -365,6 +411,8 @@ Lua 5.1 Reference Manual
<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
<A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR>
<A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR>
<A HREF="manual.html#luaL_error">luaL_error</A><BR>
<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
@ -398,8 +446,11 @@ Lua 5.1 Reference Manual
<HR>
<SMALL>
Last update:
Fri Feb 10 17:15:37 BRST 2006
Fri Mar 23 08:33:19 BRT 2007
</SMALL>
<!--
Last change: minor edit
-->
</BODY>
</HTML>

View File

@ -2,10 +2,25 @@ 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: inherit ;
text-decoration: none ;
}
a:visited {
background-color: inherit ;
text-decoration: none ;
}
a:link:hover, a:visited:hover {
@ -13,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 ;
}

File diff suppressed because it is too large Load Diff

View File

@ -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>

View File

@ -20,7 +20,7 @@ MYLIBS=
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
PLATS= aix ansi bsd generic linux macosx mingw posix solaris
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
LUA_A= liblua.a
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
@ -77,10 +77,11 @@ echo:
# convenience targets for popular platforms
none:
@echo "Please choose a platform: $(PLATS)"
@echo "Please choose a platform:"
@echo " $(PLATS)"
aix:
$(MAKE) all CC="xlc" CFLAGS="-O2" MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
$(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
ansi:
$(MAKE) all MYCFLAGS=-DLUA_ANSI
@ -88,6 +89,9 @@ ansi:
bsd:
$(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
freebsd:
$(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
generic:
$(MAKE) all MYCFLAGS=
@ -103,6 +107,7 @@ mingw:
$(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
"MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
$(MAKE) "LUAC_T=luac.exe" luac.exe
posix:
$(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
@ -121,15 +126,15 @@ lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
ldo.h lgc.h
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
ltable.h
ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \
llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \
ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h
llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
lfunc.h lstring.h lgc.h ltable.h lvm.h
ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
lstring.h lundump.h lvm.h
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \
ltable.h lundump.h lvm.h
ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
lzio.h lmem.h lundump.h
lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
@ -139,7 +144,7 @@ lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
ltm.h lzio.h lmem.h ldo.h
@ -150,8 +155,8 @@ lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
ldo.h lfunc.h lstring.h lgc.h
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
lfunc.h lstring.h lgc.h ltable.h
lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \

View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.53 2006/01/10 12:50:00 roberto Exp $
** $Id: lapi.c,v 2.55 2006/06/07 12:37:17 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@ -32,7 +32,7 @@
const char lua_ident[] =
"$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
"$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n"
"$Authors: " LUA_AUTHORS " $\n"
"$URL: www.lua.org $\n";
@ -199,6 +199,9 @@ LUA_API void lua_insert (lua_State *L, int idx) {
LUA_API void lua_replace (lua_State *L, int idx) {
StkId o;
lua_lock(L);
/* explicit test for incompatible code */
if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)
luaG_runerror(L, "no calling environment");
api_checknelems(L, 1);
o = index2adr(L, idx);
api_checkvalidindex(L, o);

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 roberto Exp $
** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -123,11 +123,17 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
luaL_typerror(L, ud, tname);
lua_pop(L, 2); /* remove both metatables */
return p;
if (p != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
lua_pop(L, 2); /* remove both metatables */
return p;
}
}
}
luaL_typerror(L, ud, tname); /* else error */
return NULL; /* to avoid warnings */
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp $
** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -108,9 +108,11 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) (luaL_loadfile(L, fn) || lua_pcall(L, 0, 0, 0))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) (luaL_loadstring(L, s) || lua_pcall(L, 0, 0, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))

View File

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.189 2006/01/18 11:49:12 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 */

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 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;
}
}
}
@ -731,17 +747,15 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
case OPR_AND: {
lua_assert(e1->t == NO_JUMP); /* list must be closed */
luaK_dischargevars(fs, e2);
luaK_concat(fs, &e1->f, e2->f);
e1->k = e2->k; e1->u.s.info = e2->u.s.info;
e1->u.s.aux = e2->u.s.aux; e1->t = e2->t;
luaK_concat(fs, &e2->f, e1->f);
*e1 = *e2;
break;
}
case OPR_OR: {
lua_assert(e1->f == NO_JUMP); /* list must be closed */
luaK_dischargevars(fs, e2);
luaK_concat(fs, &e1->t, e2->t);
e1->k = e2->k; e1->u.s.info = e2->u.s.info;
e1->u.s.aux = e2->u.s.aux; e1->f = e2->f;
luaK_concat(fs, &e2->t, e1->t);
*e1 = *e2;
break;
}
case OPR_CONCAT: {
@ -750,7 +764,7 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
freeexp(fs, e1);
SETARG_B(getcode(fs, e2), e1->u.s.info);
e1->k = e2->k; e1->u.s.info = e2->u.s.info;
e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;
}
else {
luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp $
** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -32,7 +32,6 @@ typedef enum BinOpr {
OPR_NOBINOPR
} BinOpr;
#define binopistest(op) ((op) >= OPR_NE)
typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;

View File

@ -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: {

View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp $
** $Id: ldo.c,v 2.38 2006/06/05 19:36:14 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -383,12 +383,14 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
static void resume (lua_State *L, void *ud) {
StkId firstArg = cast(StkId, ud);
CallInfo *ci = L->ci;
if (L->status != LUA_YIELD) { /* start coroutine */
if (L->status == 0) { /* start coroutine? */
lua_assert(ci == L->base_ci && firstArg > L->base);
if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)
return;
}
else { /* resuming from previous yield */
lua_assert(L->status == LUA_YIELD);
L->status = 0;
if (!f_isLua(ci)) { /* `common' yield? */
/* finish interrupted execution of `OP_CALL' */
lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
@ -399,7 +401,6 @@ static void resume (lua_State *L, void *ud) {
else /* yielded inside a hook: just continue its execution */
L->base = L->ci->base;
}
L->status = 0;
luaV_execute(L, cast_int(L->ci - L->base_ci));
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $
** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@ -55,7 +55,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
GCObject **pp = &L->openupval;
UpVal *p;
UpVal *uv;
while ((p = ngcotouv(*pp)) != NULL && p->v >= level) {
while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
lua_assert(p->v != &p->u.value);
if (p->v == level) { /* found a corresponding upvalue? */
if (isdead(g, obj2gco(p))) /* is it dead? */
@ -96,7 +96,7 @@ void luaF_freeupval (lua_State *L, UpVal *uv) {
void luaF_close (lua_State *L, StkId level) {
UpVal *uv;
global_State *g = G(L);
while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) {
while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
GCObject *o = obj2gco(uv);
lua_assert(!isblack(o) && uv->v != &uv->u.value);
L->openupval = uv->next; /* remove from `open' list */

View File

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $
** $Id: lgc.c,v 2.38 2006/05/24 14:34:06 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -320,8 +320,10 @@ static l_mem propagatemark (global_State *g) {
}
static void propagateall (global_State *g) {
while (g->gray) propagatemark(g);
static size_t propagateall (global_State *g) {
size_t m = 0;
while (g->gray) m += propagatemark(g);
return m;
}
@ -540,7 +542,7 @@ static void atomic (lua_State *L) {
propagateall(g);
udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
marktmu(g); /* mark `preserved' userdata */
propagateall(g); /* remark, to propagate `preserveness' */
udsize += propagateall(g); /* remark, to propagate `preserveness' */
cleartable(g->weak); /* remove collected objects from weak tables */
/* flip current white */
g->currentwhite = cast_byte(otherwhite(g));
@ -590,6 +592,8 @@ static l_mem singlestep (lua_State *L) {
case GCSfinalize: {
if (g->tmudata) {
GCTM(L);
if (g->estimate > GCFINALIZECOST)
g->estimate -= GCFINALIZECOST;
return GCFINALIZECOST;
}
else {

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 2.72 2006/01/28 12:59:13 roberto Exp $
** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -117,7 +117,7 @@ static FILE **newfile (lua_State *L) {
static int io_pclose (lua_State *L) {
FILE **p = topfile(L);
int ok = lua_pclose(L, *p);
if (ok) *p = NULL;
*p = NULL;
return pushresult(L, ok, NULL);
}
@ -125,7 +125,7 @@ static int io_pclose (lua_State *L) {
static int io_fclose (lua_State *L) {
FILE **p = topfile(L);
int ok = (fclose(*p) == 0);
if (ok) *p = NULL;
*p = NULL;
return pushresult(L, ok, NULL);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 2.19 2006/02/06 18:28:16 roberto Exp $
** $Id: llex.c,v 2.20 2006/03/09 18:14:31 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -20,6 +20,7 @@
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "lzio.h"

View File

@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $
** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -68,9 +68,9 @@ typedef struct LexState {
LUAI_FUNC void luaX_init (lua_State *L);
LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,
LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
TString *source);
LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);
LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
LUAI_FUNC void luaX_next (LexState *ls);
LUAI_FUNC void luaX_lookahead (LexState *ls);
LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);

View File

@ -1,5 +1,5 @@
/*
** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $
** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@ -16,16 +16,12 @@
#define loadlib_c
#define LUA_LIB
#include "lauxlib.h"
#include "lobject.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
/* environment variables that hold the search path for packages */
#define LUA_PATH "LUA_PATH"
#define LUA_CPATH "LUA_CPATH"
/* prefix for open functions in C libraries */
#define LUA_POF "luaopen_"
@ -375,15 +371,16 @@ static const char *findfile (lua_State *L, const char *name,
path = lua_tostring(L, -1);
if (path == NULL)
luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
lua_pushstring(L, ""); /* error accumulator */
lua_pushliteral(L, ""); /* error accumulator */
while ((path = pushnexttemplate(L, path)) != NULL) {
const char *filename;
filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
lua_remove(L, -2); /* remove path template */
if (readable(filename)) /* does file exist and is readable? */
return filename; /* return that file name */
lua_pop(L, 2); /* remove path template and file name */
luaO_pushfstring(L, "\n\tno file " LUA_QS, filename);
lua_concat(L, 2);
lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
lua_remove(L, -2); /* remove file name */
lua_concat(L, 2); /* add entry to possible error message */
}
return NULL; /* not found */
}
@ -442,8 +439,8 @@ static int loader_Croot (lua_State *L) {
funcname = mkfuncname(L, name);
if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
if (stat != ERRFUNC) loaderror(L, filename); /* real error */
luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
name, filename);
lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
name, filename);
return 1; /* function not found */
}
return 1;
@ -457,7 +454,7 @@ static int loader_preload (lua_State *L) {
luaL_error(L, LUA_QL("package.preload") " must be a table");
lua_getfield(L, -1, name);
if (lua_isnil(L, -1)) /* not found? */
luaO_pushfstring(L, "\n\tno field package.preload['%s']", name);
lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
return 1;
}
@ -481,7 +478,7 @@ static int ll_require (lua_State *L) {
lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
if (!lua_istable(L, -1))
luaL_error(L, LUA_QL("package.loaders") " must be a table");
lua_pushstring(L, ""); /* error message accumulator */
lua_pushliteral(L, ""); /* error message accumulator */
for (i=1; ; i++) {
lua_rawgeti(L, -2, i); /* get a loader */
if (lua_isnil(L, -1))
@ -665,8 +662,8 @@ LUALIB_API int luaopen_package (lua_State *L) {
setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */
setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
/* store config information */
lua_pushstring(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
LUA_EXECDIR "\n" LUA_IGMARK);
lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
LUA_EXECDIR "\n" LUA_IGMARK);
lua_setfield(L, -2, "config");
/* set field `loaded' */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);

View File

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $
** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -197,8 +197,8 @@ OP_FORLOOP,/* A sBx R(A)+=R(A+2);
if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
OP_TFORLOOP,/* A C R(A+3), ... ,R(A+3+C) := R(A)(R(A+1), R(A+2));
if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); } */
OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */
OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/

View File

@ -1,5 +1,5 @@
/*
** $Id: loslib.c,v 1.17 2006/01/27 13:54:31 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
*/
@ -33,10 +33,7 @@ static int os_pushresult (lua_State *L, int i, const char *filename) {
}
else {
lua_pushnil(L);
if (filename)
lua_pushfstring(L, "%s: %s", filename, strerror(en));
else
lua_pushfstring(L, "%s", strerror(en));
lua_pushfstring(L, "%s: %s", filename, strerror(en));
lua_pushinteger(L, en);
return 3;
}
@ -176,8 +173,7 @@ static int getfield (lua_State *L, const char *key, int d) {
static int os_date (lua_State *L) {
const char *s = luaL_optstring(L, 1, "%c");
time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
(time_t)luaL_checknumber(L, 2);
time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
struct tm *stm;
if (*s == '!') { /* UTC? */
stm = gmtime(&t);
@ -200,11 +196,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)) // TODO: call widechar version on win32
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); // TODO, call W version on win32
luaL_addlstring(&b, buff, reslen);
}
}
luaL_pushresult(&b);
}
return 1;
}
@ -250,9 +257,8 @@ static int os_setlocale (lua_State *L) {
LC_NUMERIC, LC_TIME};
static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
"numeric", "time", NULL};
const char *l = lua_tostring(L, 1);
const char *l = luaL_optstring(L, 1, NULL);
int op = luaL_checkoption(L, 2, "all", catnames);
luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected");
lua_pushstring(L, setlocale(cat[op], l));
return 1;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $
** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -23,7 +23,7 @@
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
@ -299,7 +299,8 @@ static void leaveblock (FuncState *fs) {
removevars(fs->ls, bl->nactvar);
if (bl->upval)
luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
lua_assert(!bl->isbreakable || !bl->upval); /* loops have no body */
/* a block either controls scope or breaks (never both) */
lua_assert(!bl->isbreakable || !bl->upval);
lua_assert(bl->nactvar == fs->nactvar);
fs->freereg = fs->nactvar; /* free registers */
luaK_patchtohere(fs, bl->breaklist);
@ -444,6 +445,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
FuncState *fs = ls->fs;
int reg = ls->fs->freereg;
expdesc key, val;
int rkkey;
if (ls->t.token == TK_NAME) {
luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
checkname(ls, &key);
@ -452,10 +454,9 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
yindex(ls, &key);
cc->nh++;
checknext(ls, '=');
luaK_exp2RK(fs, &key);
rkkey = luaK_exp2RK(fs, &key);
expr(ls, &val);
luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key),
luaK_exp2RK(fs, &val));
luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
fs->freereg = reg; /* free registers */
}
@ -488,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++;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp $
** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -9,7 +9,6 @@
#include "llimits.h"
#include "lobject.h"
#include "ltable.h"
#include "lzio.h"

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp $
** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $
** Global State
** See Copyright Notice in lua.h
*/
@ -198,7 +198,6 @@ static void callallgcTM (lua_State *L, void *ud) {
LUA_API void lua_close (lua_State *L) {
L = G(L)->mainthread; /* only the main thread can be closed */
luai_userstateclose(L);
lua_lock(L);
luaF_close(L, L->stack); /* close all upvalues for this thread */
luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
@ -209,6 +208,7 @@ LUA_API void lua_close (lua_State *L) {
L->nCcalls = 0;
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
lua_assert(G(L)->tmudata == NULL);
luai_userstateclose(L);
close_state(L);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 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
*/
@ -703,6 +703,10 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
luaL_addchar(b, *s);
break;
}
case '\r': {
luaL_addlstring(b, "\\r", 2);
break;
}
case '\0': {
luaL_addlstring(b, "\\000", 4);
break;
@ -719,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 */
@ -805,7 +809,8 @@ static int str_format (lua_State *L) {
}
}
default: { /* also treat cases `pnLlh' */
return luaL_error(L, "invalid option to " LUA_QL("format"));
return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
LUA_QL("format"), *(strfrmt - 1));
}
}
luaL_addlstring(&b, buff, strlen(buff));

View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.216 2006/01/10 12:50:13 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,8 +17,9 @@
#define LUA_VERSION "Lua 5.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"
@ -358,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

View File

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.81 2006/02/10 17:44:06 roberto Exp $
** $Id: luaconf.h,v 1.82a 2006/04/10 18:27:23 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -59,6 +59,18 @@
#endif
/*
@@ LUA_PATH and LUA_CPATH are the names of the environment variables that
@* Lua check to set its paths.
@@ LUA_INIT is the name of the environment variable that Lua
@* checks for initialization code.
** CHANGE them if you want different names.
*/
#define LUA_PATH "LUA_PATH"
#define LUA_CPATH "LUA_CPATH"
#define LUA_INIT "LUA_INIT"
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@* Lua libraries.
@ -348,7 +360,7 @@
/*
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@* behavior.
** CHANGE it to undefined as soon as you replace to 'luaL_registry'
** CHANGE it to undefined as soon as you replace to 'luaL_register'
** your uses of 'luaL_openlib'
*/
#define LUA_COMPAT_OPENLIB
@ -543,11 +555,25 @@
/* On a Pentium, resort to a trick */
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
(defined(__i386) || defined (_M_IX86) || defined(__i386__))
/* On a Microsoft compiler, use assembler */
#if defined(_MSC_VER)
#define lua_number2int(i,d) __asm fld d __asm fistp i
#define lua_number2integer(i,n) lua_number2int(i, n)
/* the next trick should work on any Pentium, but sometimes clashes
with a DirectX idiosyncrasy */
#else
union luai_Cast { double l_d; long l_l; };
#define lua_number2int(i,d) \
{ volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
#define lua_number2integer(i,n) lua_number2int(i, n)
#endif
/* this option always works, but may be slow */
#else
#define lua_number2int(i,d) ((i)=(int)(d))

View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.62 2006/01/23 19:51:43 roberto Exp $
** $Id: lvm.c,v 2.63a 2006/06/05 15:58:59 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -165,7 +165,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
if (ttisnil(tm))
tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
if (!ttisfunction(tm)) return 0;
if (ttisnil(tm)) return 0;
callTMres(L, res, tm, p1, p2);
return 1;
}
@ -281,10 +281,12 @@ void luaV_concat (lua_State *L, int total, int last) {
do {
StkId top = L->base + last + 1;
int n = 2; /* number of elements handled in this pass (at least 2) */
if (!tostring(L, top-2) || !tostring(L, top-1)) {
if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
} else if (tsvalue(top-1)->len == 0) /* second op is empty? */
(void)tostring(L, top - 2); /* result is first op (as string) */
else {
/* at least two string values; get as many as possible */
size_t tl = tsvalue(top-1)->len;
char *buffer;
@ -376,6 +378,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
TValue *k;
const Instruction *pc;
reentry: /* entry point */
lua_assert(isLua(L->ci));
pc = L->savedpc;
cl = &clvalue(L->ci->func)->l;
base = L->base;