diff options
author | Lua Team <team@lua.org> | 2008-01-17 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2008-01-17 12:00:00 +0000 |
commit | b2874e1bcdc4d4a56d8a232a88d5e17c6a9826f5 (patch) | |
tree | c173f097145da6d8df8e8fea09b6ec6bba8c5476 | |
parent | f3572f5f7e364810f6ac5f99e0eced99c4722418 (diff) | |
download | lua-github-b2874e1bcdc4d4a56d8a232a88d5e17c6a9826f5.tar.gz |
Lua 5.1.3-rc15.1.3-rc1
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | doc/contents.html | 70 | ||||
-rw-r--r-- | doc/manual.css | 6 | ||||
-rw-r--r-- | doc/manual.html | 798 | ||||
-rw-r--r-- | doc/readme.html | 4 | ||||
-rw-r--r-- | etc/lua.pc | 2 | ||||
-rw-r--r-- | src/Makefile | 3 | ||||
-rw-r--r-- | src/lapi.c | 9 | ||||
-rw-r--r-- | src/lapi.h | 2 | ||||
-rw-r--r-- | src/lauxlib.c | 4 | ||||
-rw-r--r-- | src/lauxlib.h | 2 | ||||
-rw-r--r-- | src/lbaselib.c | 73 | ||||
-rw-r--r-- | src/lcode.c | 4 | ||||
-rw-r--r-- | src/lcode.h | 2 | ||||
-rw-r--r-- | src/ldblib.c | 2 | ||||
-rw-r--r-- | src/ldebug.c | 6 | ||||
-rw-r--r-- | src/ldebug.h | 2 | ||||
-rw-r--r-- | src/ldo.c | 22 | ||||
-rw-r--r-- | src/ldo.h | 2 | ||||
-rw-r--r-- | src/ldump.c | 2 | ||||
-rw-r--r-- | src/lfunc.c | 2 | ||||
-rw-r--r-- | src/lfunc.h | 2 | ||||
-rw-r--r-- | src/lgc.c | 2 | ||||
-rw-r--r-- | src/lgc.h | 2 | ||||
-rw-r--r-- | src/linit.c | 2 | ||||
-rw-r--r-- | src/liolib.c | 12 | ||||
-rw-r--r-- | src/llex.c | 2 | ||||
-rw-r--r-- | src/llex.h | 2 | ||||
-rw-r--r-- | src/llimits.h | 2 | ||||
-rw-r--r-- | src/lmathlib.c | 2 | ||||
-rw-r--r-- | src/lmem.c | 2 | ||||
-rw-r--r-- | src/lmem.h | 2 | ||||
-rw-r--r-- | src/loadlib.c | 2 | ||||
-rw-r--r-- | src/lobject.c | 2 | ||||
-rw-r--r-- | src/lobject.h | 2 | ||||
-rw-r--r-- | src/lopcodes.c | 2 | ||||
-rw-r--r-- | src/lopcodes.h | 2 | ||||
-rw-r--r-- | src/loslib.c | 2 | ||||
-rw-r--r-- | src/lparser.c | 4 | ||||
-rw-r--r-- | src/lparser.h | 2 | ||||
-rw-r--r-- | src/lstate.c | 6 | ||||
-rw-r--r-- | src/lstate.h | 3 | ||||
-rw-r--r-- | src/lstring.c | 2 | ||||
-rw-r--r-- | src/lstring.h | 2 | ||||
-rw-r--r-- | src/lstrlib.c | 10 | ||||
-rw-r--r-- | src/ltable.c | 6 | ||||
-rw-r--r-- | src/ltable.h | 2 | ||||
-rw-r--r-- | src/ltablib.c | 5 | ||||
-rw-r--r-- | src/ltm.c | 2 | ||||
-rw-r--r-- | src/ltm.h | 2 | ||||
-rw-r--r-- | src/lua.c | 6 | ||||
-rw-r--r-- | src/lua.h | 11 | ||||
-rw-r--r-- | src/luaconf.h | 5 | ||||
-rw-r--r-- | src/lualib.h | 2 | ||||
-rw-r--r-- | src/lundump.c | 2 | ||||
-rw-r--r-- | src/lundump.h | 2 | ||||
-rw-r--r-- | src/lvm.c | 10 | ||||
-rw-r--r-- | src/lvm.h | 2 | ||||
-rw-r--r-- | src/lzio.c | 2 | ||||
-rw-r--r-- | src/lzio.h | 2 |
60 files changed, 732 insertions, 439 deletions
@@ -20,20 +20,15 @@ INSTALL_MAN= $(INSTALL_TOP)/man/man1 INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V -# How to install. You may prefer "install" instead of "cp" if you have it. -# To remove debug information from binaries, use "install -s" in INSTALL_EXEC. -# -INSTALL_EXEC= $(CP) -INSTALL_DATA= $(CP) -#INSTALL_EXEC= $(INSTALL) -m 0755 -#INSTALL_DATA= $(INSTALL) -m 0644 +# How to install. If you don't have "install" (unlikely) then get install-sh at +# http://dev.w3.org/cvsweb/libwww/config/install-sh +# or use cp instead. +INSTALL_EXEC= $(INSTALL) -p -m 0755 +INSTALL_DATA= $(INSTALL) -p -m 0644 # Utilities. -CP= cp -FIND= find INSTALL= install MKDIR= mkdir -RANLIB= ranlib # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= @@ -48,7 +43,7 @@ TO_MAN= lua.1 luac.1 # Lua version and release. V= 5.1 -R= 5.1.2 +R= 5.1.3 all: $(PLAT) @@ -64,10 +59,9 @@ install: dummy cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) -# $(RANLIB) $(INSTALL_LIB)/$(TO_LIB) local: - $(MAKE) install INSTALL_TOP=.. INSTALL_EXEC="cp -p" INSTALL_DATA="cp -p" + $(MAKE) install INSTALL_TOP=.. none: @echo "Please do" diff --git a/doc/contents.html b/doc/contents.html index 01b069f7..98562560 100644 --- a/doc/contents.html +++ b/doc/contents.html @@ -1,6 +1,6 @@ <HTML> <HEAD> -<TITLE>Lua 5.1 reference manual - contents</TITLE> +<TITLE>Lua 5.1 Reference Manual - contents</TITLE> <LINK REL="stylesheet" TYPE="text/css" HREF="lua.css"> <STYLE TYPE="text/css"> ul { @@ -33,21 +33,28 @@ This is an online version of </BLOCKQUOTE> <P> -Buy a paper copy and +Buy a copy of this book and <A HREF="http://www.lua.org/donations.html">help to support</A> the Lua project. <P> +The reference manual is the official definition of the Lua language. +For a complete introduction to Lua programming, see the book +<A HREF="http://www.lua.org/docs.html#books">Programming in Lua</A>. +<P> + <A HREF="manual.html">start</A> · <A HREF="#contents">contents</A> · <A HREF="#index">index</A> · -<A HREF="http://www.lua.org/manual/5.1/errata.html">errata</A> +<A HREF="http://www.lua.org/manual/5.1/pt/">português</A> +· +<A HREF="http://www.lua.org/manual/5.1/es/">español</A> <HR> <SMALL> -Copyright © 2006-2007 Lua.org, PUC-Rio. +Copyright © 2006-2008 Lua.org, PUC-Rio. Freely available under the terms of the <a href="http://www.lua.org/license.html#5">Lua license</a>. </SMALL> @@ -55,7 +62,8 @@ Freely available under the terms of the <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">1 - Introduction</A> +<P> <LI><A HREF="manual.html#2">2 - The Language</A> <UL> <LI><A HREF="manual.html#2.1">2.1 - Lexical Conventions</A> @@ -97,6 +105,7 @@ Freely available under the terms of the </UL> <LI><A HREF="manual.html#2.11">2.11 - Coroutines</A> </UL> +<P> <LI><A HREF="manual.html#3">3 - The Application Program Interface</A> <UL> <LI><A HREF="manual.html#3.1">3.1 - The Stack</A> @@ -108,10 +117,12 @@ Freely available under the terms of the <LI><A HREF="manual.html#3.7">3.7 - Functions and Types</A> <LI><A HREF="manual.html#3.8">3.8 - The Debug Interface</A> </UL> +<P> <LI><A HREF="manual.html#4">4 - The Auxiliary Library</A> <UL> <LI><A HREF="manual.html#4.1">4.1 - Functions and Types</A> </UL> +<P> <LI><A HREF="manual.html#5">5 - Standard Libraries</A> <UL> <LI><A HREF="manual.html#5.1">5.1 - Basic Functions</A> @@ -127,13 +138,16 @@ Freely available under the terms of the <LI><A HREF="manual.html#5.8">5.8 - Operating System Facilities</A> <LI><A HREF="manual.html#5.9">5.9 - The Debug Library</A> </UL> +<P> <LI><A HREF="manual.html#6">6 - Lua Stand-alone</A> +<P> <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> +<P> <LI><A HREF="manual.html#8">8 - The Complete Syntax of Lua</A> </UL> @@ -171,16 +185,16 @@ Freely available under the terms of the <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> +<P> -</TD> -<TD> -<H3> </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> <A HREF="manual.html#pdf-coroutine.status">coroutine.status</A><BR> <A HREF="manual.html#pdf-coroutine.wrap">coroutine.wrap</A><BR> <A HREF="manual.html#pdf-coroutine.yield">coroutine.yield</A><BR> +<P> + <A HREF="manual.html#pdf-debug.debug">debug.debug</A><BR> <A HREF="manual.html#pdf-debug.getfenv">debug.getfenv</A><BR> <A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR> @@ -195,6 +209,10 @@ Freely available under the terms of the <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> + +</TD> +<TD> +<H3> </H3> <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> @@ -202,6 +220,8 @@ Freely available under the terms of the <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> +<P> + <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> @@ -210,17 +230,22 @@ Freely available under the terms of the <A HREF="manual.html#pdf-io.output">io.output</A><BR> <A HREF="manual.html#pdf-io.popen">io.popen</A><BR> <A HREF="manual.html#pdf-io.read">io.read</A><BR> +<A HREF="manual.html#pdf-io.stderr">io.stderr</A><BR> +<A HREF="manual.html#pdf-io.stdin">io.stdin</A><BR> +<A HREF="manual.html#pdf-io.stdout">io.stdout</A><BR> <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> +<P> + <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> -<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR> <A HREF="manual.html#pdf-math.atan">math.atan</A><BR> +<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR> <A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR> -<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR> <A HREF="manual.html#pdf-math.cos">math.cos</A><BR> +<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR> <A HREF="manual.html#pdf-math.deg">math.deg</A><BR> <A HREF="manual.html#pdf-math.exp">math.exp</A><BR> <A HREF="manual.html#pdf-math.floor">math.floor</A><BR> @@ -228,8 +253,8 @@ Freely available under the terms of the <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.log10">math.log10</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> @@ -238,11 +263,13 @@ Freely available under the terms of the <A HREF="manual.html#pdf-math.rad">math.rad</A><BR> <A HREF="manual.html#pdf-math.random">math.random</A><BR> <A HREF="manual.html#pdf-math.randomseed">math.randomseed</A><BR> -<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR> <A HREF="manual.html#pdf-math.sin">math.sin</A><BR> +<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR> <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-math.tanh">math.tanh</A><BR> +<P> + <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> @@ -254,12 +281,17 @@ Freely available under the terms of the <A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR> <A HREF="manual.html#pdf-os.time">os.time</A><BR> <A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR> +<P> + <A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR> <A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR> +<A HREF="manual.html#pdf-package.loaders">package.loaders</A><BR> <A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR> <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> +<P> + <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> @@ -274,6 +306,8 @@ Freely available under the terms of the <A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR> <A HREF="manual.html#pdf-string.sub">string.sub</A><BR> <A HREF="manual.html#pdf-string.upper">string.upper</A><BR> +<P> + <A HREF="manual.html#pdf-table.concat">table.concat</A><BR> <A HREF="manual.html#pdf-table.insert">table.insert</A><BR> <A HREF="manual.html#pdf-table.maxn">table.maxn</A><BR> @@ -292,6 +326,8 @@ Freely available under the terms of the <A HREF="manual.html#lua_Reader">lua_Reader</A><BR> <A HREF="manual.html#lua_State">lua_State</A><BR> <A HREF="manual.html#lua_Writer">lua_Writer</A><BR> +<P> + <A HREF="manual.html#lua_atpanic">lua_atpanic</A><BR> <A HREF="manual.html#lua_call">lua_call</A><BR> <A HREF="manual.html#lua_checkstack">lua_checkstack</A><BR> @@ -323,6 +359,8 @@ Freely available under the terms of the <A HREF="manual.html#lua_isfunction">lua_isfunction</A><BR> <A HREF="manual.html#lua_islightuserdata">lua_islightuserdata</A><BR> <A HREF="manual.html#lua_isnil">lua_isnil</A><BR> +<A HREF="manual.html#lua_isnone">lua_isnone</A><BR> +<A HREF="manual.html#lua_isnoneornil">lua_isnoneornil</A><BR> <A HREF="manual.html#lua_isnumber">lua_isnumber</A><BR> <A HREF="manual.html#lua_isstring">lua_isstring</A><BR> <A HREF="manual.html#lua_istable">lua_istable</A><BR> @@ -391,6 +429,8 @@ Freely available under the terms of the <H3>auxiliary library</H3> <A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR> <A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR> +<P> + <A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR> <A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR> <A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR> @@ -446,10 +486,10 @@ Freely available under the terms of the <HR> <SMALL> Last update: -Fri Mar 23 08:33:19 BRT 2007 +Thu Jan 17 14:50:23 BRST 2008 </SMALL> <!-- -Last change: minor edit +Last change: revised for Lua 5.1.3 --> </BODY> diff --git a/doc/manual.css b/doc/manual.css index 93f1ab2d..eed5afd9 100644 --- a/doc/manual.css +++ b/doc/manual.css @@ -5,3 +5,9 @@ h3 code { pre { font-size: 105% ; } + +span.apii { + float: right ; + font-family: inherit ; +} + diff --git a/doc/manual.html b/doc/manual.html index 6b137ff6..4df4d4be 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -18,7 +18,7 @@ Lua 5.1 Reference Manual by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes <p> <small> -Copyright © 2006-2007 Lua.org, PUC-Rio. +Copyright © 2006-2008 Lua.org, PUC-Rio. Freely available under the terms of the <a href="http://www.lua.org/license.html#5">Lua license</a>. </small> @@ -32,6 +32,7 @@ Freely available under the terms of the <!-- ====================================================================== --> <p> +<!-- $Id: manual.of,v 1.43 2008/01/17 16:19:44 roberto Exp $ --> @@ -554,9 +555,9 @@ and a list of expressions on the right side. The elements in both lists are separated by commas: <pre> - stat ::= varlist1 `<b>=</b>´ explist1 - varlist1 ::= var {`<b>,</b>´ var} - explist1 ::= exp {`<b>,</b>´ exp} + stat ::= varlist `<b>=</b>´ explist + varlist ::= var {`<b>,</b>´ var} + explist ::= exp {`<b>,</b>´ exp} </pre><p> Expressions are discussed in <a href="#2.5">§2.5</a>. @@ -663,7 +664,7 @@ Functions and chunks may return more than one value, so the syntax for the <b>return</b> statement is <pre> - stat ::= <b>return</b> [explist1] + stat ::= <b>return</b> [explist] </pre> <p> @@ -771,7 +772,7 @@ stopping when this new value is <b>nil</b>. The generic <b>for</b> loop has the following syntax: <pre> - stat ::= <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> + stat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> namelist ::= Name {`<b>,</b>´ Name} </pre><p> A <b>for</b> statement like @@ -843,7 +844,7 @@ Local variables may be declared anywhere inside a block. The declaration may include an initial assignment: <pre> - stat ::= <b>local</b> namelist [`<b>=</b>´ explist1] + stat ::= <b>local</b> namelist [`<b>=</b>´ explist] </pre><p> If present, an initial assignment has the same semantics of a multiple assignment (see <a href="#2.4.3">§2.4.3</a>). @@ -1221,7 +1222,7 @@ except that <code>v</code> is evaluated only once. Arguments have the following syntax: <pre> - args ::= `<b>(</b>´ [explist1] `<b>)</b>´ + args ::= `<b>(</b>´ [explist] `<b>)</b>´ args ::= tableconstructor args ::= String </pre><p> @@ -1286,7 +1287,7 @@ The syntax for function definition is <pre> function ::= <b>function</b> funcbody - funcbody ::= `<b>(</b>´ [parlist1] `<b>)</b>´ block <b>end</b> + funcbody ::= `<b>(</b>´ [parlist] `<b>)</b>´ block <b>end</b> </pre> <p> @@ -1355,7 +1356,7 @@ Parameters act as local variables that are initialized with the argument values: <pre> - parlist1 ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ + parlist ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ </pre><p> When a function is called, the list of arguments is adjusted to @@ -1551,11 +1552,11 @@ you must use the C API for that. <p> -Tables and userdata have individual metatables +Tables and full userdata have individual metatables (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. +one for all strings, etc. <p> @@ -1638,7 +1639,7 @@ the behavior of the <code>op1 + op2</code> is local h = getbinhandler(op1, op2, "__add") if h then -- call the handler with both operands - return h(op1, op2) + return (h(op1, op2)) else -- no handler available: default behavior error(···) end @@ -1695,7 +1696,7 @@ the unary <code>-</code> operation. local h = metatable(op).__unm if h then -- call the handler with the operand - return h(op) + return (h(op)) else -- no handler available: default behavior error(···) end @@ -1716,7 +1717,7 @@ the <code>..</code> (concatenation) operation. else local h = getbinhandler(op1, op2, "__concat") if h then - return h(op1, op2) + return (h(op1, op2)) else error(···) end @@ -1739,7 +1740,7 @@ the <code>#</code> operation. local h = metatable(op).__len if h then -- call the handler with the operand - return h(op) + return (h(op)) else -- no handler available: default behavior error(···) end @@ -1779,7 +1780,7 @@ The "eq" event is defined as follows: -- try metamethod local h = getcomphandler(op1, op2, "__eq") if h then - return h(op1, op2) + return (h(op1, op2)) else return false end @@ -1801,7 +1802,7 @@ the <code><</code> operation. else local h = getcomphandler(op1, op2, "__lt") if h then - return h(op1, op2) + return (h(op1, op2)) else error(···); end @@ -1824,7 +1825,7 @@ the <code><=</code> operation. else local h = getcomphandler(op1, op2, "__le") if h then - return h(op1, op2) + return (h(op1, op2)) else h = getcomphandler(op1, op2, "__lt") if h then @@ -1861,8 +1862,8 @@ The indexing access <code>table[key]</code>. end end if type(h) == "function" then - return h(table, key) -- call the handler - else return h[key] -- or repeat operation on it + return (h(table, key)) -- call the handler + else return h[key] -- or repeat operation on it end end </pre><p> @@ -1887,7 +1888,7 @@ The indexing assignment <code>table[key] = value</code>. end end if type(h) == "function" then - return h(table, key,value) -- call the handler + h(table, key,value) -- call the handler else h[key] = value -- or repeat operation on it end end @@ -2062,6 +2063,7 @@ order of their creation, among those collected in that cycle. That is, the first finalizer to be called is the one associated with the userdata created last in the program. +The userdata itself is freed only in the next garbage-collection cycle. @@ -2427,17 +2429,14 @@ any error jumps to the most recent active recover point. <p> -Almost any function in the API may raise an error, +Most functions in the API may throw an error, for instance due to a memory allocation error. -The following functions run in protected mode -(that is, they create a protected environment to run), -so they never raise an error: -<a href="#lua_newstate"><code>lua_newstate</code></a>, <a href="#lua_close"><code>lua_close</code></a>, <a href="#lua_load"><code>lua_load</code></a>, -<a href="#lua_pcall"><code>lua_pcall</code></a>, and <a href="#lua_cpcall"><code>lua_cpcall</code></a>. +The documentation for each function indicates whether +it can throw errors. <p> -Inside a C function you can raise an error by calling <a href="#lua_error"><code>lua_error</code></a>. +Inside a C function you can throw an error by calling <a href="#lua_error"><code>lua_error</code></a>. @@ -2448,6 +2447,30 @@ Inside a C function you can raise an error by calling <a href="#lua_error"> <p> Here we list all functions and types from the C API in alphabetical order. +Each function has an indicator like this: +<span class="apii">[-o, +p, <em>x</em>]</span> + + +<p> +The first field, <code>o</code>, +is how many elements the function pops from the stack. +The second field, <code>p</code>, +is how many elements the function pushes onto the stack. +(Any function always pushes its results after popping its arguments.) +A field in the form <code>x|y</code> means the function may push (or pop) +<code>x</code> or <code>y</code> elements, +depending on the situation; +an interrogation mark '<code>?</code>' means that +we cannot know how many elements the function pops/pushes +by looking only at its arguments +(e.g., they may depend on what is on the stack). +The third field, <code>x</code>, +tells whether the function may throw errors: +'<code>-</code>' means the function never throws any error; +'<code>m</code>' means the function may throw an error +only due to not enough memory; +'<code>e</code>' means the function may throw other kinds of errors; +'<code>v</code>' means the function may throw an error on purpose. @@ -2506,7 +2529,8 @@ ANSI C ensures both behaviors. -<hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3> +<hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre> <p> @@ -2529,7 +2553,8 @@ The panic function can access the error message at the top of the stack. -<hr><h3><a name="lua_call"><code>lua_call</code></a></h3> +<hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p> +<span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span> <pre>void lua_call (lua_State *L, int nargs, int nresults);</pre> <p> @@ -2639,7 +2664,8 @@ of numerical arguments and returns their average and sum: -<hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3> +<hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_checkstack (lua_State *L, int extra);</pre> <p> @@ -2653,7 +2679,8 @@ it is left unchanged. -<hr><h3><a name="lua_close"><code>lua_close</code></a></h3> +<hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>void lua_close (lua_State *L);</pre> <p> @@ -2671,23 +2698,25 @@ to avoid growing too large. -<hr><h3><a name="lua_concat"><code>lua_concat</code></a></h3> +<hr><h3><a name="lua_concat"><code>lua_concat</code></a></h3><p> +<span class="apii">[-n, +1, <em>e</em>]</span> <pre>void lua_concat (lua_State *L, int n);</pre> <p> Concatenates the <code>n</code> values at the top of the stack, pops them, and leaves the result at the top. -If <code>n</code> is 1, the result is the single string on the stack +If <code>n</code> is 1, the result is the single value on the stack (that is, the function does nothing); if <code>n</code> is 0, the result is the empty string. -Concatenation is done following the usual semantics of Lua +Concatenation is performed following the usual semantics of Lua (see <a href="#2.5.4">§2.5.4</a>). -<hr><h3><a name="lua_cpcall"><code>lua_cpcall</code></a></h3> +<hr><h3><a name="lua_cpcall"><code>lua_cpcall</code></a></h3><p> +<span class="apii">[-0, +(0|1), <em>-</em>]</span> <pre>int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);</pre> <p> @@ -2704,7 +2733,8 @@ All values returned by <code>func</code> are discarded. -<hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3> +<hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre> <p> @@ -2719,7 +2749,8 @@ Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</c -<hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3> +<hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>int lua_dump (lua_State *L, lua_Writer writer, void *data);</pre> <p> @@ -2747,7 +2778,8 @@ This function does not pop the Lua function from the stack. -<hr><h3><a name="lua_equal"><code>lua_equal</code></a></h3> +<hr><h3><a name="lua_equal"><code>lua_equal</code></a></h3><p> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>int lua_equal (lua_State *L, int index1, int index2);</pre> <p> @@ -2762,7 +2794,8 @@ Also returns 0 if any of the indices is non valid. -<hr><h3><a name="lua_error"><code>lua_error</code></a></h3> +<hr><h3><a name="lua_error"><code>lua_error</code></a></h3><p> +<span class="apii">[-1, +0, <em>v</em>]</span> <pre>int lua_error (lua_State *L);</pre> <p> @@ -2777,7 +2810,8 @@ and therefore never returns. -<hr><h3><a name="lua_gc"><code>lua_gc</code></a></h3> +<hr><h3><a name="lua_gc"><code>lua_gc</code></a></h3><p> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>int lua_gc (lua_State *L, int what, int data);</pre> <p> @@ -2838,7 +2872,8 @@ The function returns the previous value of the step multiplier. -<hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3> +<hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre> <p> @@ -2850,7 +2885,8 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. -<hr><h3><a name="lua_getfenv"><code>lua_getfenv</code></a></h3> +<hr><h3><a name="lua_getfenv"><code>lua_getfenv</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_getfenv (lua_State *L, int index);</pre> <p> @@ -2861,12 +2897,13 @@ the value at the given index. -<hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3> +<hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void lua_getfield (lua_State *L, int index, const char *k);</pre> <p> Pushes onto the stack the value <code>t[k]</code>, -where <code>t</code> is the value at the given valid index <code>index</code>. +where <code>t</code> is the value at the given valid index. As in Lua, this function may trigger a metamethod for the "index" event (see <a href="#2.8">§2.8</a>). @@ -2874,7 +2911,8 @@ for the "index" event (see <a href="#2.8">§2.8</a>). -<hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3> +<hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void lua_getglobal (lua_State *L, const char *name);</pre> <p> @@ -2888,7 +2926,8 @@ It is defined as a macro: -<hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3> +<hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p> +<span class="apii">[-0, +(0|1), <em>-</em>]</span> <pre>int lua_getmetatable (lua_State *L, int index);</pre> <p> @@ -2902,12 +2941,13 @@ the function returns 0 and pushes nothing on the stack. -<hr><h3><a name="lua_gettable"><code>lua_gettable</code></a></h3> +<hr><h3><a name="lua_gettable"><code>lua_gettable</code></a></h3><p> +<span class="apii">[-1, +1, <em>e</em>]</span> <pre>void lua_gettable (lua_State *L, int index);</pre> <p> Pushes onto the stack the value <code>t[k]</code>, -where <code>t</code> is the value at the given valid index <code>index</code> +where <code>t</code> is the value at the given valid index and <code>k</code> is the value at the top of the stack. @@ -2921,7 +2961,8 @@ for the "index" event (see <a href="#2.8">§2.8</a>). -<hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3> +<hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_gettop (lua_State *L);</pre> <p> @@ -2934,7 +2975,8 @@ this result is equal to the number of elements in the stack -<hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3> +<hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p> +<span class="apii">[-1, +1, <em>-</em>]</span> <pre>void lua_insert (lua_State *L, int index);</pre> <p> @@ -2963,7 +3005,8 @@ which is usually the largest signed integral type the machine handles -<hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3> +<hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isboolean (lua_State *L, int index);</pre> <p> @@ -2974,7 +3017,8 @@ and 0 otherwise. -<hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3> +<hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_iscfunction (lua_State *L, int index);</pre> <p> @@ -2985,7 +3029,8 @@ and 0 otherwise. -<hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3> +<hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isfunction (lua_State *L, int index);</pre> <p> @@ -2996,7 +3041,8 @@ Returns 1 if the value at the given acceptable index is a function -<hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3> +<hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_islightuserdata (lua_State *L, int index);</pre> <p> @@ -3007,7 +3053,8 @@ and 0 otherwise. -<hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3> +<hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isnil (lua_State *L, int index);</pre> <p> @@ -3018,11 +3065,12 @@ and 0 otherwise. -<hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3> +<hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isnone (lua_State *L, int index);</pre> <p> -Returns 1 if the the given acceptable index is not valid +Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack), and 0 otherwise. @@ -3030,11 +3078,12 @@ and 0 otherwise. -<hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3> +<hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isnoneornil (lua_State *L, int index);</pre> <p> -Returns 1 if the the given acceptable index is not valid +Returns 1 if 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 otherwise. @@ -3043,7 +3092,8 @@ and 0 otherwise. -<hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3> +<hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isnumber (lua_State *L, int index);</pre> <p> @@ -3055,7 +3105,8 @@ and 0 otherwise. -<hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3> +<hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>int lua_isstring (lua_State *L, int index);</pre> <p> @@ -3067,7 +3118,8 @@ and 0 otherwise. -<hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3> +<hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_istable (lua_State *L, int index);</pre> <p> @@ -3078,7 +3130,8 @@ and 0 otherwise. -<hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3> +<hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isthread (lua_State *L, int index);</pre> <p> @@ -3089,7 +3142,8 @@ and 0 otherwise. -<hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3> +<hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_isuserdata (lua_State *L, int index);</pre> <p> @@ -3100,7 +3154,8 @@ Returns 1 if the value at the given acceptable index is a userdata -<hr><h3><a name="lua_lessthan"><code>lua_lessthan</code></a></h3> +<hr><h3><a name="lua_lessthan"><code>lua_lessthan</code></a></h3><p> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>int lua_lessthan (lua_State *L, int index1, int index2);</pre> <p> @@ -3115,7 +3170,8 @@ Also returns 0 if any of the indices is non valid. -<hr><h3><a name="lua_load"><code>lua_load</code></a></h3> +<hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>int lua_load (lua_State *L, lua_Reader reader, void *data, @@ -3165,7 +3221,8 @@ which is used for error messages and in debug information (see <a href="#3.8">&s -<hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3> +<hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre> <p> @@ -3181,7 +3238,8 @@ simply passes to the allocator in every call. -<hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3> +<hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void lua_newtable (lua_State *L);</pre> <p> @@ -3192,7 +3250,8 @@ It is equivalent to <code>lua_createtable(L, 0, 0)</code>. -<hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3> +<hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>lua_State *lua_newthread (lua_State *L);</pre> <p> @@ -3212,7 +3271,8 @@ like any Lua object. -<hr><h3><a name="lua_newuserdata"><code>lua_newuserdata</code></a></h3> +<hr><h3><a name="lua_newuserdata"><code>lua_newuserdata</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void *lua_newuserdata (lua_State *L, size_t size);</pre> <p> @@ -3240,7 +3300,8 @@ Lua frees its corresponding memory. -<hr><h3><a name="lua_next"><code>lua_next</code></a></h3> +<hr><h3><a name="lua_next"><code>lua_next</code></a></h3><p> +<span class="apii">[-1, +(2|0), <em>e</em>]</span> <pre>int lua_next (lua_State *L, int index);</pre> <p> @@ -3295,7 +3356,8 @@ Lua to operate with another type for numbers (e.g., float or long). -<hr><h3><a name="lua_objlen"><code>lua_objlen</code></a></h3> +<hr><h3><a name="lua_objlen"><code>lua_objlen</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>size_t lua_objlen (lua_State *L, int index);</pre> <p> @@ -3310,7 +3372,8 @@ for other values, it is 0. -<hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3> +<hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p> +<span class="apii">[-(nargs + 1), +(nresults|1), <em>-</em>]</span> <pre>int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre> <p> @@ -3375,7 +3438,8 @@ error while running the error handler function. -<hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3> +<hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p> +<span class="apii">[-n, +0, <em>-</em>]</span> <pre>void lua_pop (lua_State *L, int n);</pre> <p> @@ -3385,7 +3449,8 @@ Pops <code>n</code> elements from the stack. -<hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3> +<hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_pushboolean (lua_State *L, int b);</pre> <p> @@ -3395,7 +3460,8 @@ Pushes a boolean value with value <code>b</code> onto the stack. -<hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3> +<hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3><p> +<span class="apii">[-n, +1, <em>m</em>]</span> <pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre> <p> @@ -3420,7 +3486,8 @@ associated with the function. -<hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3> +<hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre> <p> @@ -3446,7 +3513,8 @@ and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code>< -<hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3> +<hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre> <p> @@ -3480,7 +3548,8 @@ The conversion specifiers can only be -<hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3> +<hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre> <p> @@ -3490,7 +3559,8 @@ Pushes a number with value <code>n</code> onto the stack. -<hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3> +<hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre> <p> @@ -3510,7 +3580,8 @@ light userdata with the same C address. -<hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3> +<hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void lua_pushlstring (lua_State *L, const char *s, size_t len);</pre> <p> @@ -3525,7 +3596,8 @@ The string can contain embedded zeros. -<hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3> +<hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_pushnil (lua_State *L);</pre> <p> @@ -3535,7 +3607,8 @@ Pushes a nil value onto the stack. -<hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3> +<hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre> <p> @@ -3545,7 +3618,8 @@ Pushes a number with value <code>n</code> onto the stack. -<hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3> +<hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void lua_pushstring (lua_State *L, const char *s);</pre> <p> @@ -3561,7 +3635,8 @@ it is assumed to end at the first zero. -<hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3> +<hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>int lua_pushthread (lua_State *L);</pre> <p> @@ -3572,7 +3647,8 @@ Returns 1 if this thread is the main thread of its state. -<hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3> +<hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_pushvalue (lua_State *L, int index);</pre> <p> @@ -3583,7 +3659,8 @@ onto the stack. -<hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3> +<hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);</pre> @@ -3596,7 +3673,8 @@ instead of a variable number of arguments. -<hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3> +<hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre> <p> @@ -3610,7 +3688,8 @@ Also returns 0 if any of the indices are non valid. -<hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3> +<hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p> +<span class="apii">[-1, +1, <em>-</em>]</span> <pre>void lua_rawget (lua_State *L, int index);</pre> <p> @@ -3621,12 +3700,13 @@ Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw -<hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3> +<hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void lua_rawgeti (lua_State *L, int index, int n);</pre> <p> Pushes onto the stack the value <code>t[n]</code>, -where <code>t</code> is the value at the given valid index <code>index</code>. +where <code>t</code> is the value at the given valid index. The access is raw; that is, it does not invoke metamethods. @@ -3634,7 +3714,8 @@ that is, it does not invoke metamethods. -<hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3> +<hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3><p> +<span class="apii">[-2, +0, <em>m</em>]</span> <pre>void lua_rawset (lua_State *L, int index);</pre> <p> @@ -3645,13 +3726,14 @@ Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw -<hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3> +<hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3><p> +<span class="apii">[-1, +0, <em>m</em>]</span> <pre>void lua_rawseti (lua_State *L, int index, int n);</pre> <p> Does the equivalent of <code>t[n] = v</code>, -where <code>t</code> is the value at the given valid index <code>index</code> -and <code>v</code> is the value at the top of the stack, +where <code>t</code> is the value at the given valid index +and <code>v</code> is the value at the top of the stack. <p> @@ -3684,7 +3766,8 @@ The reader function may return pieces of any size greater than zero. -<hr><h3><a name="lua_register"><code>lua_register</code></a></h3> +<hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre> @@ -3701,7 +3784,8 @@ It is defined as a macro: -<hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3> +<hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p> +<span class="apii">[-1, +0, <em>-</em>]</span> <pre>void lua_remove (lua_State *L, int index);</pre> <p> @@ -3714,7 +3798,8 @@ because a pseudo-index is not an actual stack position. -<hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3> +<hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p> +<span class="apii">[-1, +0, <em>-</em>]</span> <pre>void lua_replace (lua_State *L, int index);</pre> <p> @@ -3726,7 +3811,8 @@ without shifting any element -<hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3> +<hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p> +<span class="apii">[-?, +?, <em>-</em>]</span> <pre>int lua_resume (lua_State *L, int narg);</pre> <p> @@ -3759,7 +3845,8 @@ and then call <a href="#lua_resume"><code>lua_resume</code></a>. -<hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3> +<hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre> <p> @@ -3770,7 +3857,8 @@ with user data <code>ud</code>. -<hr><h3><a name="lua_setfenv"><code>lua_setfenv</code></a></h3> +<hr><h3><a name="lua_setfenv"><code>lua_setfenv</code></a></h3><p> +<span class="apii">[-1, +0, <em>-</em>]</span> <pre>int lua_setfenv (lua_State *L, int index);</pre> <p> @@ -3785,13 +3873,14 @@ Otherwise it returns 1. -<hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3> +<hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p> +<span class="apii">[-1, +0, <em>e</em>]</span> <pre>void lua_setfield (lua_State *L, int index, const char *k);</pre> <p> Does the equivalent to <code>t[k] = v</code>, -where <code>t</code> is the value at the given valid index <code>index</code> -and <code>v</code> is the value at the top of the stack, +where <code>t</code> is the value at the given valid index +and <code>v</code> is the value at the top of the stack. <p> @@ -3803,7 +3892,8 @@ for the "newindex" event (see <a href="#2.8">§2.8</a>). -<hr><h3><a name="lua_setglobal"><code>lua_setglobal</code></a></h3> +<hr><h3><a name="lua_setglobal"><code>lua_setglobal</code></a></h3><p> +<span class="apii">[-1, +0, <em>e</em>]</span> <pre>void lua_setglobal (lua_State *L, const char *name);</pre> <p> @@ -3818,7 +3908,8 @@ It is defined as a macro: -<hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3> +<hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p> +<span class="apii">[-1, +0, <em>-</em>]</span> <pre>int lua_setmetatable (lua_State *L, int index);</pre> <p> @@ -3830,12 +3921,13 @@ acceptable index. -<hr><h3><a name="lua_settable"><code>lua_settable</code></a></h3> +<hr><h3><a name="lua_settable"><code>lua_settable</code></a></h3><p> +<span class="apii">[-2, +0, <em>e</em>]</span> <pre>void lua_settable (lua_State *L, int index);</pre> <p> Does the equivalent to <code>t[k] = v</code>, -where <code>t</code> is the value at the given valid index <code>index</code>, +where <code>t</code> is the value at the given valid index, <code>v</code> is the value at the top of the stack, and <code>k</code> is the value just below the top. @@ -3849,7 +3941,8 @@ for the "newindex" event (see <a href="#2.8">§2.8</a>). -<hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3> +<hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p> +<span class="apii">[-?, +?, <em>-</em>]</span> <pre>void lua_settop (lua_State *L, int index);</pre> <p> @@ -3882,7 +3975,8 @@ which creates a Lua state from scratch. -<hr><h3><a name="lua_status"><code>lua_status</code></a></h3> +<hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_status (lua_State *L);</pre> <p> @@ -3898,7 +3992,8 @@ or <a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended -<hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3> +<hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_toboolean (lua_State *L, int index);</pre> <p> @@ -3916,7 +4011,8 @@ use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's -<hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3> +<hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre> <p> @@ -3928,8 +4024,9 @@ otherwise, returns <code>NULL</code>. -<hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3> -<pre>lua_Integer lua_tointeger (lua_State *L, int idx);</pre> +<hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> +<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre> <p> Converts the Lua value at the given acceptable index @@ -3947,7 +4044,8 @@ it is truncated in some non-specified way. -<hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3> +<hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre> <p> @@ -3977,7 +4075,8 @@ will be valid after the corresponding value is removed from the stack. -<hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3> +<hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_Number lua_tonumber (lua_State *L, int index);</pre> <p> @@ -3991,7 +4090,8 @@ otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0. -<hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3> +<hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>const void *lua_topointer (lua_State *L, int index);</pre> <p> @@ -4010,7 +4110,8 @@ Typically this function is used only for debug information. -<hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3> +<hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>const char *lua_tostring (lua_State *L, int index);</pre> <p> @@ -4020,7 +4121,8 @@ Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code -<hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3> +<hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_State *lua_tothread (lua_State *L, int index);</pre> <p> @@ -4033,7 +4135,8 @@ otherwise, the function returns <code>NULL</code>. -<hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3> +<hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>void *lua_touserdata (lua_State *L, int index);</pre> <p> @@ -4047,7 +4150,8 @@ Otherwise, returns <code>NULL</code>. -<hr><h3><a name="lua_type"><code>lua_type</code></a></h3> +<hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_type (lua_State *L, int index);</pre> <p> @@ -4071,7 +4175,8 @@ and -<hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3> +<hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>const char *lua_typename (lua_State *L, int tp);</pre> <p> @@ -4089,7 +4194,7 @@ which must be one the values returned by <a href="#lua_type"><code>lua_type</cod void* ud);</pre> <p> -The writer function used by <a href="#lua_dump"><code>lua_dump</code></a>. +The type of the writer function used by <a href="#lua_dump"><code>lua_dump</code></a>. Every time it produces another piece of chunk, <a href="#lua_dump"><code>lua_dump</code></a> calls the writer, passing along the buffer to be written (<code>p</code>), @@ -4107,7 +4212,8 @@ calling the writer again. -<hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3> +<hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p> +<span class="apii">[-?, +?, <em>-</em>]</span> <pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre> <p> @@ -4122,7 +4228,8 @@ and pushes them onto the stack <code>to</code>. -<hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3> +<hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p> +<span class="apii">[-?, +?, <em>-</em>]</span> <pre>int lua_yield (lua_State *L, int nresults);</pre> <p> @@ -4254,7 +4361,8 @@ the number of upvalues of the function. -<hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3> +<hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_Hook lua_gethook (lua_State *L);</pre> <p> @@ -4264,7 +4372,8 @@ Returns the current hook function. -<hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3> +<hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_gethookcount (lua_State *L);</pre> <p> @@ -4274,7 +4383,8 @@ Returns the current hook count. -<hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3> +<hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_gethookmask (lua_State *L);</pre> <p> @@ -4284,7 +4394,8 @@ Returns the current hook mask. -<hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3> +<hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p> +<span class="apii">[-(0|1), +(0|1|2), <em>-</em>]</span> <pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre> <p> @@ -4357,7 +4468,8 @@ This function returns 0 on error -<hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3> +<hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p> +<span class="apii">[-0, +(0|1), <em>-</em>]</span> <pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre> <p> @@ -4387,7 +4499,8 @@ the number of active local variables. -<hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3> +<hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre> <p> @@ -4408,7 +4521,8 @@ it returns 0. -<hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3> +<hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p> +<span class="apii">[-0, +(0|1), <em>-</em>]</span> <pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre> <p> @@ -4468,7 +4582,8 @@ this execution occurs without any calls to hooks. -<hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3> +<hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre> <p> @@ -4519,7 +4634,8 @@ A hook is disabled by setting <code>mask</code> to zero. -<hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3> +<hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p> +<span class="apii">[-(0|1), +0, <em>-</em>]</span> <pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre> <p> @@ -4540,7 +4656,8 @@ the number of active local variables. -<hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3> +<hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p> +<span class="apii">[-(0|1), +0, <em>-</em>]</span> <pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre> <p> @@ -4590,7 +4707,7 @@ and so they provide nothing that cannot be done with this API. Several functions in the auxiliary library are used to check C function arguments. Their names are always <code>luaL_check*</code> or <code>luaL_opt*</code>. -All of these functions raise an error if the check is not satisfied. +All of these functions throw an error if the check is not satisfied. Because the error message is formatted for arguments (e.g., "<code>bad argument #1</code>"), you should not use these functions for other stack values. @@ -4605,7 +4722,8 @@ in alphabetical order. -<hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3> +<hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>void luaL_addchar (luaL_Buffer *B, char c);</pre> <p> @@ -4616,7 +4734,8 @@ Adds the character <code>c</code> to the buffer <code>B</code> -<hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3> +<hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre> <p> @@ -4629,7 +4748,8 @@ The string may contain embedded zeros. -<hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3> +<hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre> <p> @@ -4641,7 +4761,8 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>). -<hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3> +<hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre> <p> @@ -4654,7 +4775,8 @@ The string may not contain embedded zeros. -<hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3> +<hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p> +<span class="apii">[-1, +0, <em>m</em>]</span> <pre>void luaL_addvalue (luaL_Buffer *B);</pre> <p> @@ -4673,7 +4795,8 @@ which is the value to be added to the buffer. -<hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3> +<hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>void luaL_argcheck (lua_State *L, int cond, int narg, @@ -4691,7 +4814,8 @@ where <code>func</code> is retrieved from the call stack: -<hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3> +<hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre> <p> @@ -4760,7 +4884,8 @@ plus the final string on its top. -<hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3> +<hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre> <p> @@ -4773,7 +4898,8 @@ the buffer must be declared as a variable -<hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3> +<hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3><p> +<span class="apii">[-0, +(0|1), <em>e</em>]</span> <pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre> <p> @@ -4793,7 +4919,8 @@ this function returns 0 (without pushing any value on the stack). -<hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3> +<hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>void luaL_checkany (lua_State *L, int narg);</pre> <p> @@ -4804,7 +4931,8 @@ of any type (including <b>nil</b>) at position <code>narg</code>. -<hr><h3><a name="luaL_checkint"><code>luaL_checkint</code></a></h3> +<hr><h3><a name="luaL_checkint"><code>luaL_checkint</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>int luaL_checkint (lua_State *L, int narg);</pre> <p> @@ -4815,7 +4943,8 @@ and returns this number cast to an <code>int</code>. -<hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3> +<hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>lua_Integer luaL_checkinteger (lua_State *L, int narg);</pre> <p> @@ -4826,7 +4955,8 @@ and returns this number cast to a <a href="#lua_Integer"><code>lua_Integer</code -<hr><h3><a name="luaL_checklong"><code>luaL_checklong</code></a></h3> +<hr><h3><a name="luaL_checklong"><code>luaL_checklong</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>long luaL_checklong (lua_State *L, int narg);</pre> <p> @@ -4837,7 +4967,8 @@ and returns this number cast to a <code>long</code>. -<hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3> +<hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>const char *luaL_checklstring (lua_State *L, int narg, size_t *l);</pre> <p> @@ -4847,10 +4978,16 @@ if <code>l</code> is not <code>NULL</code> fills <code>*l</code> with the string's length. +<p> +This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result, +so all conversions and caveats of that function apply here. -<hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3> + + +<hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>lua_Number luaL_checknumber (lua_State *L, int narg);</pre> <p> @@ -4861,7 +4998,8 @@ and returns this number. -<hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3> +<hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>int luaL_checkoption (lua_State *L, int narg, const char *def, @@ -4891,7 +5029,8 @@ to use strings instead of numbers to select options.) -<hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3> +<hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre> <p> @@ -4903,7 +5042,8 @@ raising an error if the stack cannot grow to that size. -<hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3> +<hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>const char *luaL_checkstring (lua_State *L, int narg);</pre> <p> @@ -4911,20 +5051,28 @@ Checks whether the function argument <code>narg</code> is a string and returns this string. +<p> +This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result, +so all conversions and caveats of that function apply here. + + -<hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3> +<hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>void luaL_checktype (lua_State *L, int narg, int t);</pre> <p> Checks whether the function argument <code>narg</code> has type <code>t</code>. +See <a href="#lua_type"><code>lua_type</code></a> for the encoding of types for <code>t</code>. -<hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3> +<hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>void *luaL_checkudata (lua_State *L, int narg, const char *tname);</pre> <p> @@ -4935,7 +5083,8 @@ of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newm -<hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3> +<hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p> +<span class="apii">[-0, +?, <em>m</em>]</span> <pre>int luaL_dofile (lua_State *L, const char *filename);</pre> <p> @@ -4952,7 +5101,8 @@ or 1 in case of errors. -<hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3> +<hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p> +<span class="apii">[-0, +?, <em>m</em>]</span> <pre>int luaL_dostring (lua_State *L, const char *str);</pre> <p> @@ -4969,7 +5119,8 @@ or 1 in case of errors. -<hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3> +<hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre> <p> @@ -4991,7 +5142,8 @@ as <code>return luaL_error(<em>args</em>)</code>. -<hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3> +<hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p> +<span class="apii">[-0, +(0|1), <em>m</em>]</span> <pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre> <p> @@ -5005,7 +5157,8 @@ returns 0 and pushes nothing. -<hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3> +<hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> <pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre> <p> @@ -5016,7 +5169,8 @@ in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code> -<hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3> +<hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>const char *luaL_gsub (lua_State *L, const char *s, const char *p, @@ -5032,7 +5186,8 @@ Pushes the resulting string on the stack and returns it. -<hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3> +<hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>int luaL_loadbuffer (lua_State *L, const char *buff, size_t sz, @@ -5053,7 +5208,8 @@ used for debug information and error messages. -<hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3> +<hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>int luaL_loadfile (lua_State *L, const char *filename);</pre> <p> @@ -5079,7 +5235,8 @@ it does not run it. -<hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3> +<hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>int luaL_loadstring (lua_State *L, const char *s);</pre> <p> @@ -5100,7 +5257,8 @@ it does not run it. -<hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3> +<hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre> <p> @@ -5120,7 +5278,8 @@ with <code>tname</code> in the registry. -<hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3> +<hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>lua_State *luaL_newstate (void);</pre> <p> @@ -5140,7 +5299,8 @@ or <code>NULL</code> if there is a memory allocation error. -<hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3> +<hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p> +<span class="apii">[-0, +0, <em>m</em>]</span> <pre>void luaL_openlibs (lua_State *L);</pre> <p> @@ -5150,7 +5310,8 @@ Opens all standard Lua libraries into the given state. -<hr><h3><a name="luaL_optint"><code>luaL_optint</code></a></h3> +<hr><h3><a name="luaL_optint"><code>luaL_optint</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>int luaL_optint (lua_State *L, int narg, int d);</pre> <p> @@ -5164,7 +5325,8 @@ Otherwise, raises an error. -<hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3> +<hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer d);</pre> @@ -5180,7 +5342,8 @@ Otherwise, raises an error. -<hr><h3><a name="luaL_optlong"><code>luaL_optlong</code></a></h3> +<hr><h3><a name="luaL_optlong"><code>luaL_optlong</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>long luaL_optlong (lua_State *L, int narg, long d);</pre> <p> @@ -5194,7 +5357,8 @@ Otherwise, raises an error. -<hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3> +<hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>const char *luaL_optlstring (lua_State *L, int narg, const char *d, @@ -5216,7 +5380,8 @@ fills the position <code>*l</code> with the results's length. -<hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3> +<hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number d);</pre> <p> @@ -5230,7 +5395,8 @@ Otherwise, raises an error. -<hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3> +<hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>const char *luaL_optstring (lua_State *L, int narg, const char *d);</pre> @@ -5246,7 +5412,8 @@ Otherwise, raises an error. -<hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3> +<hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre> <p> @@ -5261,7 +5428,8 @@ it to the buffer. -<hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3> +<hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p> +<span class="apii">[-?, +1, <em>m</em>]</span> <pre>void luaL_pushresult (luaL_Buffer *B);</pre> <p> @@ -5272,7 +5440,8 @@ the top of the stack. -<hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3> +<hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p> +<span class="apii">[-1, +0, <em>m</em>]</span> <pre>int luaL_ref (lua_State *L, int t);</pre> <p> @@ -5318,7 +5487,8 @@ in which both <code>name</code> and <code>func</code> are <code>NULL</code>. -<hr><h3><a name="luaL_register"><code>luaL_register</code></a></h3> +<hr><h3><a name="luaL_register"><code>luaL_register</code></a></h3><p> +<span class="apii">[-(0|1), +1, <em>m</em>]</span> <pre>void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l);</pre> @@ -5352,17 +5522,19 @@ on the top of the stack. -<hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3> -<pre>const char *luaL_typename (lua_State *L, int idx);</pre> +<hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> +<pre>const char *luaL_typename (lua_State *L, int index);</pre> <p> -Returns the name of the type of the value at index <code>idx</code>. +Returns the name of the type of the value at the given index. -<hr><h3><a name="luaL_typerror"><code>luaL_typerror</code></a></h3> +<hr><h3><a name="luaL_typerror"><code>luaL_typerror</code></a></h3><p> +<span class="apii">[-0, +0, <em>v</em>]</span> <pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre> <p> @@ -5379,7 +5551,8 @@ and <code><em>rt</em></code> is the type name of the actual argument. -<hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3> +<hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p> +<span class="apii">[-0, +0, <em>-</em>]</span> <pre>void luaL_unref (lua_State *L, int t, int ref);</pre> <p> @@ -5398,7 +5571,8 @@ If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a -<hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3> +<hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p> +<span class="apii">[-0, +1, <em>m</em>]</span> <pre>void luaL_where (lua_State *L, int lvl);</pre> <p> @@ -5433,7 +5607,7 @@ Some of these functions provide essential services to the language others provide access to "outside" services (e.g., I/O); and others could be implemented in Lua itself, but are quite useful or have critical performance requirements that -deserve an implementation in C (e.g., <code>sort</code>). +deserve an implementation in C (e.g., <a href="#pdf-table.sort"><code>table.sort</code></a>). <p> @@ -5476,7 +5650,8 @@ it can open them individually by calling <a name="pdf-luaopen_string"><code>luaopen_string</code></a> (for the string library), <a name="pdf-luaopen_table"><code>luaopen_table</code></a> (for the table library), <a name="pdf-luaopen_math"><code>luaopen_math</code></a> (for the mathematical library), -<a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O and the Operating System libraries), +<a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O library), +<a name="pdf-luaopen_os"><code>luaopen_os</code></a> (for the Operating System library), and <a name="pdf-luaopen_debug"><code>luaopen_debug</code></a> (for the debug library). These functions are declared in <a name="pdf-lualib.h"><code>lualib.h</code></a> and should not be called directly: @@ -5665,6 +5840,8 @@ The environment of the returned function is the global environment. <p> <code>chunkname</code> is used as the chunk name for error messages and debug information. +When absent, +it defaults to "<code>=(load)</code>". @@ -5698,6 +5875,11 @@ To load and run a given string, use the idiom assert(loadstring(s))() </pre> +<p> +When absent, +<code>chunkname</code> defaults to the given string. + + <p> @@ -6160,7 +6342,15 @@ Otherwise, it tries to find a <em>loader</em> for the module. <p> To find a loader, -first <code>require</code> queries <code>package.preload[modname]</code>. +<code>require</code> is guided by the <a href="#pdf-package.loaders"><code>package.loaders</code></a> array. +By changing this array, +we can change how <code>require</code> looks for a module. +The following explanation is based on the default configuration +for <a href="#pdf-package.loaders"><code>package.loaders</code></a>. + + +<p> +First <code>require</code> queries <code>package.preload[modname]</code>. If it has a value, this value (which should be a function) is the loader. Otherwise <code>require</code> searches for a Lua loader using the @@ -6168,38 +6358,7 @@ path stored in <a href="#pdf-package.path"><code>package.path</code></a>. If that also fails, it searches for a C loader using the path stored in <a href="#pdf-package.cpath"><code>package.cpath</code></a>. If that also fails, -it tries an <em>all-in-one</em> loader (see below). - - -<p> -When loading a C library, -<code>require</code> first uses a dynamic link facility to link the -application with the library. -Then it tries to find a C function inside this library to -be used as the loader. -The name of this C function is the string "<code>luaopen_</code>" -concatenated with a copy of the module name where each dot -is replaced by an underscore. -Moreover, if the module name has a hyphen, -its prefix up to (and including) the first hyphen is removed. -For instance, if the module name is <code>a.v1-b.c</code>, -the function name will be <code>luaopen_b_c</code>. - - -<p> -If <code>require</code> finds neither a Lua library nor a -C library for a module, -it calls the <em>all-in-one loader</em>. -This loader searches the C path for a library for -the root name of the given module. -For instance, when requiring <code>a.b.c</code>, -it will search for a C library for <code>a</code>. -If found, it looks into it for an open function for -the submodule; -in our example, that would be <code>luaopen_a_b_c</code>. -With this facility, a package can pack several C submodules -into one single library, -with each submodule keeping its original open function. +it tries an <em>all-in-one</em> loader (see <a href="#pdf-package.loaders"><code>package.loaders</code></a>). <p> @@ -6234,7 +6393,7 @@ The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua initializes the C path <a href="#pdf-package.cpath"><code>package.cpath</code></a> in the same way it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>, using the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a> -(plus another default path defined in <code>luaconf.h</code>). +or a default path defined in <code>luaconf.h</code>. @@ -6255,6 +6414,94 @@ When you require a module <code>modname</code> and <p> +<hr><h3><a name="pdf-package.loaders"><code>package.loaders</code></a></h3> + + +<p> +A table used by <a href="#pdf-require"><code>require</code></a> to control how to load modules. + + +<p> +Each entry in this table is a <em>searcher function</em>. +When looking for a module, +<a href="#pdf-require"><code>require</code></a> calls each of these searchers in ascending order, +with the module name (the argument given to <a href="#pdf-require"><code>require</code></a>) as its +sole parameter. +The function may return another function (the module <em>loader</em>) +or a string explaining why it did not find that module +(or <b>nil</b> if it has nothing to say). +Lua initializes this table with four functions. + + +<p> +The first searcher simply looks for a loader in the +<a href="#pdf-package.preload"><code>package.preload</code></a> table. + + +<p> +The second searcher looks for a loader as a Lua library, +using the path stored at <a href="#pdf-package.path"><code>package.path</code></a>. +A path is a sequence of <em>templates</em> separated by semicolons. +For each template, +the searcher will change each interrogation +mark in the template by <code>filename</code>, +which is the module name with each dot replaced by a +"directory separator" (such as "<code>/</code>" in Unix); +then it will try to open the resulting file name. +So, for instance, if the Lua path is the string + +<pre> + "./?.lua;./?.lc;/usr/local/?/init.lua" +</pre><p> +the search for a Lua file for module <code>foo</code> +will try to open the files +<code>./foo.lua</code>, <code>./foo.lc</code>, and +<code>/usr/local/foo/init.lua</code>, in that order. + + +<p> +The third searcher looks for a loader as a C library, +using the path given by the variable <a href="#pdf-package.cpath"><code>package.cpath</code></a>. +For instance, +if the C path is the string + +<pre> + "./?.so;./?.dll;/usr/local/?/init.so" +</pre><p> +the searcher for module <code>foo</code> +will try to open the files <code>./foo.so</code>, <code>./foo.dll</code>, +and <code>/usr/local/foo/init.so</code>, in that order. +Once it finds a C library, +this searcher first uses a dynamic link facility to link the +application with the library. +Then it tries to find a C function inside the library to +be used as the loader. +The name of this C function is the string "<code>luaopen_</code>" +concatenated with a copy of the module name where each dot +is replaced by an underscore. +Moreover, if the module name has a hyphen, +its prefix up to (and including) the first hyphen is removed. +For instance, if the module name is <code>a.v1-b.c</code>, +the function name will be <code>luaopen_b_c</code>. + + +<p> +The fourth searcher tries an <em>all-in-one loader</em>. +It searches the C path for a library for +the root name of the given module. +For instance, when requiring <code>a.b.c</code>, +it will search for a C library for <code>a</code>. +If found, it looks into it for an open function for +the submodule; +in our example, that would be <code>luaopen_a_b_c</code>. +With this facility, a package can pack several C submodules +into one single library, +with each submodule keeping its original open function. + + + + +<p> <hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3> @@ -6303,24 +6550,6 @@ Any "<code>;;</code>" in the value of the environment variable is replaced by the default path. -<p> -A path is a sequence of <em>templates</em> separated by semicolons. -For each template, <a href="#pdf-require"><code>require</code></a> will change each interrogation -mark in the template by <code>filename</code>, -which is <code>modname</code> with each dot replaced by a -"directory separator" (such as "<code>/</code>" in Unix); -then it will try to load the resulting file name. -So, for instance, if the Lua path is - -<pre> - "./?.lua;./?.lc;/usr/local/?/init.lua" -</pre><p> -the search for a Lua loader for module <code>foo</code> -will try to load the files -<code>./foo.lua</code>, <code>./foo.lc</code>, and -<code>/usr/local/foo/init.lua</code>, in that order. - - <p> @@ -6524,11 +6753,12 @@ work as an anchor, as this would prevent the iteration. <p> <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3> Returns a copy of <code>s</code> -in which all occurrences of the <code>pattern</code> have been +in which all (or the first <code>n</code>, if given) +occurrences of the <code>pattern</code> have been replaced by a replacement string specified by <code>repl</code>, which may be a string, a table, or a function. <code>gsub</code> also returns, as its second value, -the total number of substitutions made. +the total number of matches that occurred. <p> @@ -6566,13 +6796,6 @@ then there is no replacement <p> -The optional last parameter <code>n</code> limits -the maximum number of substitutions to occur. -For instance, when <code>n</code> is 1 only the first occurrence of -<code>pattern</code> is replaced. - - -<p> Here are some examples: <pre> @@ -7005,14 +7228,14 @@ Returns the arc tangent of <code>x</code> (in radians). <p> -<hr><h3><a name="pdf-math.atan2"><code>math.atan2 (x, y)</code></a></h3> +<hr><h3><a name="pdf-math.atan2"><code>math.atan2 (y, x)</code></a></h3> <p> -Returns the arc tangent of <code>x/y</code> (in radians), +Returns the arc tangent of <code>y/x</code> (in radians), but uses the signs of both parameters to find the quadrant of the result. -(It also handles correctly the case of <code>y</code> being zero.) +(It also handles correctly the case of <code>x</code> being zero.) @@ -7062,7 +7285,7 @@ Returns the angle <code>x</code> (given in radians) in degrees. <p> -Returns the the value <em>e<sup>x</sup></em>. +Returns the value <em>e<sup>x</sup></em>. @@ -7215,13 +7438,13 @@ pseudo-random generator function <code>rand</code> provided by ANSI C. <p> When called without arguments, -returns a pseudo-random real number +returns a uniform pseudo-random real number in the range <em>[0,1)</em>. -When called with a number <code>m</code>, +When called with an integer number <code>m</code>, <code>math.random</code> returns -a pseudo-random integer in the range <em>[1, m]</em>. -When called with two numbers <code>m</code> and <code>n</code>, -<code>math.random</code> returns a pseudo-random +a uniform pseudo-random integer in the range <em>[1, m]</em>. +When called with two integer numbers <code>m</code> and <code>n</code>, +<code>math.random</code> returns a uniform pseudo-random integer in the range <em>[m, n]</em>. @@ -7316,6 +7539,7 @@ and then all operations are supplied as methods of the file descriptor. The table <code>io</code> also provides three predefined file descriptors with their usual meanings from C: <a name="pdf-io.stdin"><code>io.stdin</code></a>, <a name="pdf-io.stdout"><code>io.stdout</code></a>, and <a name="pdf-io.stderr"><code>io.stderr</code></a>. +The I/O library never closes these files. <p> @@ -7829,9 +8053,9 @@ 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. +the current locale is set to an implementation-defined native locale. +If <code>locale</code> is the string "<code>C</code>", +the current locale is set to the standard C locale. <p> @@ -7892,7 +8116,7 @@ and similar tasks, such as profiling. Please resist the temptation to use them as a usual programming tool: they can be very slow. -Moreover, several of its functions +Moreover, several of these functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or @@ -7983,7 +8207,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, +a table with a name for the current function, +if a reasonable name can be found, 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. @@ -8070,9 +8295,9 @@ The string mask may have the following characters, with the given meaning: <ul> -<li><b><code>"c"</code>:</b> The hook is called every time Lua calls a function;</li> -<li><b><code>"r"</code>:</b> The hook is called every time Lua returns from a function;</li> -<li><b><code>"l"</code>:</b> The hook is called every time Lua enters a new line of code.</li> +<li><b><code>"c"</code>:</b> the hook is called every time Lua calls a function;</li> +<li><b><code>"r"</code>:</b> the hook is called every time Lua returns from a function;</li> +<li><b><code>"l"</code>:</b> the hook is called every time Lua enters a new line of code.</li> </ul><p> With a <code>count</code> different from zero, the hook is called after every <code>count</code> instructions. @@ -8257,17 +8482,19 @@ then its value is used as the prompt. Similarly, if the global variable <a name="pdf-_PROMPT2"><code>_PROMPT2</code></a> contains a string, its value is used as the secondary prompt (issued during incomplete statements). -Therefore, both prompts can be changed directly on the command line. -For instance, +Therefore, both prompts can be changed directly on the command line +or in any Lua programs by assigning to <code>_PROMPT</code>. +See the next example: <pre> $ lua -e"_PROMPT='myprompt> '" -i </pre><p> -(the outer pair of quotes is for the shell, -the inner pair is for Lua), -or in any Lua programs by assigning to <code>_PROMPT</code>. -Note the use of <code>-i</code> to enter interactive mode; otherwise, -the program would just end silently right after the assignment to <code>_PROMPT</code>. +(The outer pair of quotes is for the shell, +the inner pair is for Lua.) +Note the use of <code>-i</code> to enter interactive mode; +otherwise, +the program would just end silently +right after the assignment to <code>_PROMPT</code>. <p> @@ -8297,7 +8524,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 you may found when moving a program +Here we list the incompatibilities that you may find when moving a program from Lua 5.0 to Lua 5.1. You can avoid most of the incompatibilities compiling Lua with appropriate options (see file <code>luaconf.h</code>). @@ -8446,29 +8673,29 @@ Here is the complete syntax of Lua in extended BNF. block ::= chunk - stat ::= varlist1 `<b>=</b>´ explist1 | + stat ::= varlist `<b>=</b>´ explist | functioncall | <b>do</b> block <b>end</b> | <b>while</b> exp <b>do</b> block <b>end</b> | <b>repeat</b> block <b>until</b> exp | <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | <b>for</b> Name `<b>=</b>´ exp `<b>,</b>´ exp [`<b>,</b>´ exp] <b>do</b> block <b>end</b> | - <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | + <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | <b>function</b> funcname funcbody | <b>local</b> <b>function</b> Name funcbody | - <b>local</b> namelist [`<b>=</b>´ explist1] + <b>local</b> namelist [`<b>=</b>´ explist] - laststat ::= <b>return</b> [explist1] | <b>break</b> + laststat ::= <b>return</b> [explist] | <b>break</b> funcname ::= Name {`<b>.</b>´ Name} [`<b>:</b>´ Name] - varlist1 ::= var {`<b>,</b>´ var} + varlist ::= var {`<b>,</b>´ var} var ::= Name | prefixexp `<b>[</b>´ exp `<b>]</b>´ | prefixexp `<b>.</b>´ Name namelist ::= Name {`<b>,</b>´ Name} - explist1 ::= {exp `<b>,</b>´} exp + explist ::= {exp `<b>,</b>´} exp exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | `<b>...</b>´ | function | prefixexp | tableconstructor | exp binop exp | unop exp @@ -8477,13 +8704,13 @@ Here is the complete syntax of Lua in extended BNF. functioncall ::= prefixexp args | prefixexp `<b>:</b>´ Name args - args ::= `<b>(</b>´ [explist1] `<b>)</b>´ | tableconstructor | String + args ::= `<b>(</b>´ [explist] `<b>)</b>´ | tableconstructor | String function ::= <b>function</b> funcbody - funcbody ::= `<b>(</b>´ [parlist1] `<b>)</b>´ block <b>end</b> + funcbody ::= `<b>(</b>´ [parlist] `<b>)</b>´ block <b>end</b> - parlist1 ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ + parlist ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ tableconstructor ::= `<b>{</b>´ [fieldlist] `<b>}</b>´ @@ -8508,13 +8735,14 @@ Here is the complete syntax of Lua in extended BNF. + <HR> <SMALL> Last update: -Mon Mar 26 12:59:26 BRT 2007 +Thu Jan 17 15:06:18 BRST 2008 </SMALL> <!-- -Last change: ready for Lua 5.1.2 +Last change: revised for Lua 5.1.3 --> </body></html> diff --git a/doc/readme.html b/doc/readme.html index 28b1d147..972faddd 100644 --- a/doc/readme.html +++ b/doc/readme.html @@ -12,7 +12,7 @@ Documentation </H1> -This is the documentation included in the source distribution of Lua 5.1.2. +This is the documentation included in the source distribution of Lua 5.1.3. <UL> <LI><A HREF="contents.html">Reference manual</A> @@ -33,7 +33,7 @@ especially the <HR> <SMALL> Last update: -Fri Mar 23 14:19:36 BRT 2007 +Wed Dec 19 13:59:14 BRST 2007 </SMALL> </BODY> @@ -5,7 +5,7 @@ # grep '^V=' ../Makefile V= 5.1 # grep '^R=' ../Makefile -R= 5.1.2 +R= 5.1.3 # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' prefix= /usr/local diff --git a/src/Makefile b/src/Makefile index cd7f6ba2..748d0f8d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -148,8 +148,7 @@ llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.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 -loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \ - lualib.h +loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.55 2006/06/07 12:37:17 roberto Exp $ +** $Id: lapi.c,v 2.55.1.3 2008/01/03 15:20:39 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -123,6 +123,11 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { } +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { lua_CFunction old; lua_lock(L); @@ -749,7 +754,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { res = 0; break; } - luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); L->top--; lua_unlock(L); return res; @@ -1,5 +1,5 @@ /* -** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $ +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ diff --git a/src/lauxlib.c b/src/lauxlib.c index 96a6b852..348730f6 100644 --- a/src/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp $ +** $Id: lauxlib.c,v 1.159.1.2 2008/01/17 14:04:41 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -244,7 +244,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, if (libname) { int size = libsize(l); /* check whether lib already exists */ - luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size); + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); lua_getfield(L, -1, libname); /* get _LOADED[libname] */ if (!lua_istable(L, -1)) { /* not found? */ lua_pop(L, 1); /* remove previous result */ diff --git a/src/lauxlib.h b/src/lauxlib.h index 1f343086..34258235 100644 --- a/src/lauxlib.h +++ b/src/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp $ +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ diff --git a/src/lbaselib.c b/src/lbaselib.c index 147a727e..cdeb15ca 100644 --- a/src/lbaselib.c +++ b/src/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $ +** $Id: lbaselib.c,v 1.191.1.3 2008/01/03 15:20:39 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -477,15 +477,52 @@ static const luaL_Reg base_funcs[] = { ** ======================================================= */ +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + static int auxresume (lua_State *L, lua_State *co, int narg) { - int status; + int status = costatus(L, co); if (!lua_checkstack(co, narg)) luaL_error(L, "too many arguments to resume"); - if (lua_status(co) == 0 && lua_gettop(co) == 0) { - lua_pushliteral(L, "cannot resume dead coroutine"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); return -1; /* error flag */ } lua_xmove(L, co, narg); + lua_setlevel(L, co); status = lua_resume(co, narg); if (status == 0 || status == LUA_YIELD) { int nres = lua_gettop(co); @@ -556,34 +593,6 @@ static int luaB_yield (lua_State *L) { } -static int luaB_costatus (lua_State *L) { - lua_State *co = lua_tothread(L, 1); - luaL_argcheck(L, co, 1, "coroutine expected"); - if (L == co) lua_pushliteral(L, "running"); - else { - switch (lua_status(co)) { - case LUA_YIELD: - lua_pushliteral(L, "suspended"); - break; - case 0: { - lua_Debug ar; - if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ - lua_pushliteral(L, "normal"); /* it is running */ - else if (lua_gettop(co) == 0) - lua_pushliteral(L, "dead"); - else - lua_pushliteral(L, "suspended"); /* initial state */ - break; - } - default: /* some error occured */ - lua_pushliteral(L, "dead"); - break; - } - } - return 1; -} - - static int luaB_corunning (lua_State *L) { if (lua_pushthread(L)) return 0; /* main thread is not a coroutine */ diff --git a/src/lcode.c b/src/lcode.c index 9ce515ab..cff626b7 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $ +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -699,7 +699,7 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; switch (op) { case OPR_MINUS: { - if (e->k == VK) + if (!isnumeral(e)) luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ codearith(fs, OP_UNM, e, &e2); break; diff --git a/src/lcode.h b/src/lcode.h index c02cb2b7..b941c607 100644 --- a/src/lcode.h +++ b/src/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp $ +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ diff --git a/src/ldblib.c b/src/ldblib.c index 26a19b6a..bb47cc72 100644 --- a/src/ldblib.c +++ b/src/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $ +** $Id: ldblib.c,v 1.104.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ diff --git a/src/ldebug.c b/src/ldebug.c index 9c8bdf2f..9eac4a9b 100644 --- a/src/ldebug.c +++ b/src/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $ +** $Id: ldebug.c,v 2.29.1.3 2007/12/28 15:32:23 roberto Exp $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -563,8 +563,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { - if (ttisstring(p1)) p1 = p2; - lua_assert(!ttisstring(p1)); + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); luaG_typeerror(L, p1, "concatenate"); } diff --git a/src/ldebug.h b/src/ldebug.h index 9c76aa10..ba28a972 100644 --- a/src/ldebug.h +++ b/src/ldebug.h @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $ +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.38 2006/06/05 19:36:14 roberto Exp $ +** $Id: ldo.c,v 2.38.1.2 2008/01/03 15:20:39 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -83,7 +83,7 @@ static void resetstack (lua_State *L, int status) { L->base = L->ci->base; luaF_close(L, L->base); /* close eventual pending closures */ luaD_seterrorobj(L, status, L->base); - L->nCcalls = 0; + L->nCcalls = L->baseCcalls; L->allowhook = 1; restore_stack_limit(L); L->errfunc = 0; @@ -417,22 +417,24 @@ static int resume_error (lua_State *L, const char *msg) { LUA_API int lua_resume (lua_State *L, int nargs) { int status; lua_lock(L); - if (L->status != LUA_YIELD) { - if (L->status != 0) - return resume_error(L, "cannot resume dead coroutine"); - else if (L->ci != L->base_ci) + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) return resume_error(L, "cannot resume non-suspended coroutine"); - } + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); luai_userstateresume(L, nargs); - lua_assert(L->errfunc == 0 && L->nCcalls == 0); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; status = luaD_rawrunprotected(L, resume, L->top - nargs); if (status != 0) { /* error? */ L->status = cast_byte(status); /* mark thread as `dead' */ luaD_seterrorobj(L, status, L->top); L->ci->top = L->top; } - else + else { + lua_assert(L->nCcalls == L->baseCcalls); status = L->status; + } + --L->nCcalls; lua_unlock(L); return status; } @@ -441,7 +443,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); lua_lock(L); - if (L->nCcalls > 0) + if (L->nCcalls > L->baseCcalls) luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); L->base = L->top - nresults; /* protect stack slots below */ L->status = LUA_YIELD; @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 2.7 2005/08/24 16:15:49 roberto Exp $ +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ diff --git a/src/ldump.c b/src/ldump.c index f08277d3..c9d3d487 100644 --- a/src/ldump.c +++ b/src/ldump.c @@ -1,5 +1,5 @@ /* -** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $ +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** save precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/src/lfunc.c b/src/lfunc.c index 05bd5ff5..813e88f5 100644 --- a/src/lfunc.c +++ b/src/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $ +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ diff --git a/src/lfunc.h b/src/lfunc.h index 2e02419b..a68cf515 100644 --- a/src/lfunc.h +++ b/src/lfunc.h @@ -1,5 +1,5 @@ /* -** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.38 2006/05/24 14:34:06 roberto Exp $ +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lgc.h,v 2.15 2005/08/24 16:15:49 roberto Exp $ +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ diff --git a/src/linit.c b/src/linit.c index 483d9c8c..c1f90dfa 100644 --- a/src/linit.c +++ b/src/linit.c @@ -1,5 +1,5 @@ /* -** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $ +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ ** Initialization of libraries for lua.c ** See Copyright Notice in lua.h */ diff --git a/src/liolib.c b/src/liolib.c index be60972c..e92984f1 100644 --- a/src/liolib.c +++ b/src/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp $ +** $Id: liolib.c,v 2.73.1.2 2008/01/02 13:56:00 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -106,8 +106,11 @@ static int io_pclose (lua_State *L) { static int io_fclose (lua_State *L) { FILE **p = topfile(L); - int ok = (fclose(*p) == 0); - *p = NULL; + int ok = 0; + if (*p != stdin && *p != stdout && *p != stderr) { + ok = (fclose(*p) == 0); + *p = NULL; + } return pushresult(L, ok, NULL); } @@ -129,8 +132,7 @@ static int io_close (lua_State *L) { static int io_gc (lua_State *L) { FILE *f = *topfile(L); - /* ignore closed files and standard files */ - if (f != NULL && f != stdin && f != stdout && f != stderr) + if (f != NULL) /* ignore closed files */ aux_close(L); return 0; } @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.20 2006/03/09 18:14:31 roberto Exp $ +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp $ +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ diff --git a/src/llimits.h b/src/llimits.h index b03221ae..ca8dcb72 100644 --- a/src/llimits.h +++ b/src/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $ +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ diff --git a/src/lmathlib.c b/src/lmathlib.c index d181a731..441fbf73 100644 --- a/src/lmathlib.c +++ b/src/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $ +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ ** Standard mathematical library ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $ +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $ +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ diff --git a/src/loadlib.c b/src/loadlib.c index 808368ba..d955f3ef 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $ +** $Id: loadlib.c,v 1.52.1.2 2007/12/28 14:58:43 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** diff --git a/src/lobject.c b/src/lobject.c index acde82cc..4ff50732 100644 --- a/src/lobject.c +++ b/src/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.22 2006/02/10 17:43:52 roberto Exp $ +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ diff --git a/src/lobject.h b/src/lobject.h index 8ce4405b..e7199dfc 100644 --- a/src/lobject.h +++ b/src/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp $ +** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ diff --git a/src/lopcodes.c b/src/lopcodes.c index bf9cd522..4cc74523 100644 --- a/src/lopcodes.c +++ b/src/lopcodes.c @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $ +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ ** See Copyright Notice in lua.h */ diff --git a/src/lopcodes.h b/src/lopcodes.h index 48105f1e..41224d6e 100644 --- a/src/lopcodes.h +++ b/src/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp $ +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ diff --git a/src/loslib.c b/src/loslib.c index fdda4741..be6e4e80 100644 --- a/src/loslib.c +++ b/src/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $ +** $Id: loslib.c,v 1.19.1.2 2007/12/28 14:58:43 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ diff --git a/src/lparser.c b/src/lparser.c index 6c473c41..1e2a9a88 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $ +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -938,6 +938,8 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { primaryexp(ls, &nv.v); if (nv.v.k == VLOCAL) check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); assignment(ls, &nv, nvars+1); } else { /* assignment -> `=' explist1 */ diff --git a/src/lparser.h b/src/lparser.h index e5b5b57e..18836afd 100644 --- a/src/lparser.h +++ b/src/lparser.h @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $ +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ diff --git a/src/lstate.c b/src/lstate.c index 4bcb7594..4313b83a 100644 --- a/src/lstate.c +++ b/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $ +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -93,7 +93,7 @@ static void preinit_state (lua_State *L, global_State *g) { resethookcount(L); L->openupval = NULL; L->size_ci = 0; - L->nCcalls = 0; + L->nCcalls = L->baseCcalls = 0; L->status = 0; L->base_ci = L->ci = NULL; L->savedpc = NULL; @@ -205,7 +205,7 @@ LUA_API void lua_close (lua_State *L) { do { /* repeat until no more errors */ L->ci = L->base_ci; L->base = L->top = L->ci->base; - L->nCcalls = 0; + L->nCcalls = L->baseCcalls = 0; } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); lua_assert(G(L)->tmudata == NULL); luai_userstateclose(L); diff --git a/src/lstate.h b/src/lstate.h index d296a4ca..3bc575b6 100644 --- a/src/lstate.h +++ b/src/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $ +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -112,6 +112,7 @@ struct lua_State { int stacksize; int size_ci; /* size of array `base_ci' */ unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ lu_byte hookmask; lu_byte allowhook; int basehookcount; diff --git a/src/lstring.c b/src/lstring.c index 4319930c..49113151 100644 --- a/src/lstring.c +++ b/src/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $ +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ diff --git a/src/lstring.h b/src/lstring.h index 1d2e91ea..73a2ff8b 100644 --- a/src/lstring.h +++ b/src/lstring.h @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ diff --git a/src/lstrlib.c b/src/lstrlib.c index fc7ae489..ca333ba1 100644 --- a/src/lstrlib.c +++ b/src/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $ +** $Id: lstrlib.c,v 1.132.1.3 2007/12/28 15:32:23 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -629,10 +629,6 @@ static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, lua_gettable(L, 3); break; } - default: { - luaL_argerror(L, 3, "string/function/table expected"); - return; - } } if (!lua_toboolean(L, -1)) { /* nil or false? */ lua_pop(L, 1); @@ -648,11 +644,15 @@ static int str_gsub (lua_State *L) { size_t srcl; const char *src = luaL_checklstring(L, 1, &srcl); const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); int max_s = luaL_optint(L, 4, srcl+1); int anchor = (*p == '^') ? (p++, 1) : 0; int n = 0; MatchState ms; luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); luaL_buffinit(L, &b); ms.L = L; ms.src_init = src; diff --git a/src/ltable.c b/src/ltable.c index bc91cacd..ec84f4fa 100644 --- a/src/ltable.c +++ b/src/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp $ +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -84,8 +84,8 @@ static const Node dummynode_ = { static Node *hashnum (const Table *t, lua_Number n) { unsigned int a[numints]; int i; - n += 1; /* normalize number (avoid -0) */ - lua_assert(sizeof(a) <= sizeof(n)); + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); memcpy(a, &n, sizeof(a)); for (i = 1; i < numints; i++) a[0] += a[i]; return hashmod(t, a[0]); diff --git a/src/ltable.h b/src/ltable.h index 09193cdb..f5b9d5ea 100644 --- a/src/ltable.h +++ b/src/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $ +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ diff --git a/src/ltablib.c b/src/ltablib.c index 453b23b3..06f1c37b 100644 --- a/src/ltablib.c +++ b/src/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $ +** $Id: ltablib.c,v 1.38.1.2 2007/12/28 15:32:23 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -118,7 +118,8 @@ static int tinsert (lua_State *L) { static int tremove (lua_State *L) { int e = aux_getn(L, 1); int pos = luaL_optint(L, 2, e); - if (e == 0) return 0; /* table is `empty' */ + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ luaL_setn(L, 1, e - 1); /* t.n = n-1 */ lua_rawgeti(L, 1, pos); /* result = t[pos] */ for ( ;pos<e; pos++) { @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 2.8 2006/01/10 12:50:00 roberto Exp $ +** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: ltm.h,v 2.6 2005/06/06 13:30:25 roberto Exp $ +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.160 2006/06/02 15:34:00 roberto Exp $ +** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -74,6 +74,8 @@ static int report (lua_State *L, int status) { static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ lua_getfield(L, LUA_GLOBALSINDEX, "debug"); if (!lua_istable(L, -1)) { lua_pop(L, 1); @@ -144,7 +146,7 @@ static int dostring (lua_State *L, const char *s, const char *name) { static int dolibrary (lua_State *L, const char *name) { lua_getglobal(L, "require"); lua_pushstring(L, name); - return report(L, lua_pcall(L, 1, 0, 0)); + return report(L, docall(L, 1, 1)); } @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $ +** $Id: lua.h,v 1.218.1.4 2008/01/03 15:41:15 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.2" +#define LUA_RELEASE "Lua 5.1.3" #define LUA_VERSION_NUM 501 -#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio" +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" @@ -294,6 +294,9 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); #define lua_Chunkwriter lua_Writer +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + /* ** {====================================================================== @@ -359,7 +362,7 @@ struct lua_Debug { /****************************************************************************** -* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved. +* Copyright (C) 1994-2008 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/luaconf.h b/src/luaconf.h index 8be8338f..c9698b0d 100644 --- a/src/luaconf.h +++ b/src/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.82a 2006/04/10 18:27:23 roberto Exp $ +** $Id: luaconf.h,v 1.82.1.5 2008/01/17 14:04:20 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -442,7 +442,8 @@ ** functions. This limit is arbitrary; its only purpose is to stop C ** functions to consume unlimited stack space. */ -#define LUAI_MAXCSTACK 2048 +#define LUAI_MCS_AUX ((int)(INT_MAX / (4*sizeof(LUA_NUMBER)))) +#define LUAI_MAXCSTACK (LUAI_MCS_AUX > SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX) diff --git a/src/lualib.h b/src/lualib.h index 0c76232c..469417f6 100644 --- a/src/lualib.h +++ b/src/lualib.h @@ -1,5 +1,5 @@ /* -** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $ +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua standard libraries ** See Copyright Notice in lua.h */ diff --git a/src/lundump.c b/src/lundump.c index 7fc635ee..1f992f24 100644 --- a/src/lundump.c +++ b/src/lundump.c @@ -1,5 +1,5 @@ /* -** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $ +** $Id: lundump.c,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/src/lundump.h b/src/lundump.h index 58cca5d1..c80189db 100644 --- a/src/lundump.h +++ b/src/lundump.h @@ -1,5 +1,5 @@ /* -** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $ +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.63a 2006/06/05 15:58:59 roberto Exp $ +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -61,11 +61,9 @@ static void traceexec (lua_State *L, const Instruction *pc) { lu_byte mask = L->hookmask; const Instruction *oldpc = L->savedpc; L->savedpc = pc; - if (mask > LUA_MASKLINE) { /* instruction-hook set? */ - if (L->hookcount == 0) { - resethookcount(L); - luaD_callhook(L, LUA_HOOKCOUNT, -1); - } + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); } if (mask & LUA_MASKLINE) { Proto *p = ci_func(L->ci)->l.p; @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $ +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $ +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ ** a generic input stream interface ** See Copyright Notice in lua.h */ @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $ +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ ** Buffered streams ** See Copyright Notice in lua.h */ |