summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2010-07-31 12:00:00 +0000
committerrepogen <>2010-07-31 12:00:00 +0000
commit90ac6291217c36341e777586e49968d4a914a32a (patch)
treeca7b024dd1f05e7bf3fdc45cdcb5b7cc3c62c769
parentf970e1e83ed07bbcf8a20fc1a95f91a0a2aae620 (diff)
downloadlua-github-90ac6291217c36341e777586e49968d4a914a32a.tar.gz
Lua 5.2.0-work45.2.0-work4
-rw-r--r--Makefile79
-rw-r--r--README4
-rw-r--r--doc/contents.html189
-rw-r--r--doc/external.pngbin165 -> 0 bytes
-rw-r--r--doc/lua.css18
-rw-r--r--doc/manual.css7
-rw-r--r--doc/manual.html501
-rw-r--r--doc/readme.html184
-rw-r--r--etc/Makefile62
-rw-r--r--etc/README30
-rw-r--r--etc/dummy.c11
-rw-r--r--etc/luavs.bat28
-rw-r--r--etc/min.c33
-rw-r--r--etc/noparser.c70
-rw-r--r--etc/one.c73
-rw-r--r--etc/strict.lua42
-rw-r--r--src/Makefile84
-rw-r--r--src/lapi.c33
-rw-r--r--src/lauxlib.c222
-rw-r--r--src/lauxlib.h23
-rw-r--r--src/lbaselib.c163
-rw-r--r--src/lbitlib.c9
-rw-r--r--src/lcode.c101
-rw-r--r--src/lcode.h4
-rw-r--r--src/lcorolib.c154
-rw-r--r--src/ldblib.c46
-rw-r--r--src/ldebug.c23
-rw-r--r--src/ldo.c5
-rw-r--r--src/lfunc.c10
-rw-r--r--src/lfunc.h4
-rw-r--r--src/lgc.c49
-rw-r--r--src/lgc.h24
-rw-r--r--src/linit.c24
-rw-r--r--src/liolib.c15
-rw-r--r--src/llimits.h10
-rw-r--r--src/lmathlib.c4
-rw-r--r--src/loadlib.c166
-rw-r--r--src/lobject.h71
-rw-r--r--src/loslib.c11
-rw-r--r--src/lparser.c60
-rw-r--r--src/lparser.h19
-rw-r--r--src/lstrlib.c5
-rw-r--r--src/ltable.c16
-rw-r--r--src/ltable.h4
-rw-r--r--src/ltablib.c4
-rw-r--r--src/lua.c43
-rw-r--r--src/lua.h21
-rw-r--r--src/luaconf.h72
-rw-r--r--src/lualib.h6
-rw-r--r--src/lvm.c72
-rw-r--r--src/print.c10
51 files changed, 1425 insertions, 1493 deletions
diff --git a/Makefile b/Makefile
index db263e66..cbc945d7 100644
--- a/Makefile
+++ b/Makefile
@@ -7,21 +7,19 @@
PLAT= none
# Where to install. The installation starts in the src and doc directories,
-# so take care if INSTALL_TOP is not an absolute path.
+# so take care if INSTALL_TOP is not an absolute path. See the local target.
+# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
+# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
-#
-# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
-# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V
-# How to install.
-# If your install program does not support "-p", then you may have to run
-# ranlib on the installed liblua.a.
+# How to install. If your install program does not support "-p", then
+# you may have to run ranlib on the installed liblua.a.
INSTALL= install -p
INSTALL_EXEC= $(INSTALL) -m 0755
INSTALL_DATA= $(INSTALL) -m 0644
@@ -31,7 +29,7 @@ INSTALL_DATA= $(INSTALL) -m 0644
# INSTALL_EXEC= $(INSTALL)
# INSTALL_DATA= $(INSTALL)
-# Utilities.
+# Other utilities.
MKDIR= mkdir -p
RM= rm -f
@@ -50,6 +48,7 @@ TO_MAN= lua.1 luac.1
V= 5.2
R= $V.0
+# Targets start here.
all: $(PLAT)
$(PLATS) clean:
@@ -75,9 +74,7 @@ local:
$(MAKE) install INSTALL_TOP=../install
none:
- @echo "Please do"
- @echo " make PLATFORM"
- @echo "where PLATFORM is one of these:"
+ @echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
@echo " $(PLATS)"
@echo "See doc/readme.html for complete instructions."
@@ -86,44 +83,30 @@ dummy:
# echo config parameters
echo:
- @echo ""
- @echo "These are the parameters currently set in src/Makefile to build Lua $R:"
- @echo ""
@cd src && $(MAKE) -s echo
- @echo ""
- @echo "These are the parameters currently set in Makefile to install Lua $R:"
- @echo ""
- @echo "PLAT = $(PLAT)"
- @echo "INSTALL_TOP = $(INSTALL_TOP)"
- @echo "INSTALL_BIN = $(INSTALL_BIN)"
- @echo "INSTALL_INC = $(INSTALL_INC)"
- @echo "INSTALL_LIB = $(INSTALL_LIB)"
- @echo "INSTALL_MAN = $(INSTALL_MAN)"
- @echo "INSTALL_LMOD = $(INSTALL_LMOD)"
- @echo "INSTALL_CMOD = $(INSTALL_CMOD)"
- @echo "INSTALL_EXEC = $(INSTALL_EXEC)"
- @echo "INSTALL_DATA = $(INSTALL_DATA)"
- @echo ""
- @echo "See also src/luaconf.h ."
- @echo ""
-
-# echo private config parameters
-pecho:
- @echo "V = $V"
- @echo "R = $R"
- @echo "TO_BIN = $(TO_BIN)"
- @echo "TO_INC = $(TO_INC)"
- @echo "TO_LIB = $(TO_LIB)"
- @echo "TO_MAN = $(TO_MAN)"
-
-# echo config parameters as Lua code
-# uncomment the last sed expression if you want nil instead of empty strings
-lecho:
- @echo "-- installation parameters for Lua $R"
- @echo "VERSION = '$V'"
- @echo "RELEASE = '$R'"
- @$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/'
- @echo "-- EOF"
+ @echo "PLAT= $(PLAT)"
+ @echo "V= $V"
+ @echo "R= $R"
+ @echo "TO_BIN= $(TO_BIN)"
+ @echo "TO_INC= $(TO_INC)"
+ @echo "TO_LIB= $(TO_LIB)"
+ @echo "TO_MAN= $(TO_MAN)"
+ @echo "INSTALL_TOP= $(INSTALL_TOP)"
+ @echo "INSTALL_BIN= $(INSTALL_BIN)"
+ @echo "INSTALL_INC= $(INSTALL_INC)"
+ @echo "INSTALL_LIB= $(INSTALL_LIB)"
+ @echo "INSTALL_MAN= $(INSTALL_MAN)"
+ @echo "INSTALL_LMOD= $(INSTALL_LMOD)"
+ @echo "INSTALL_CMOD= $(INSTALL_CMOD)"
+ @echo "INSTALL_EXEC= $(INSTALL_EXEC)"
+ @echo "INSTALL_DATA= $(INSTALL_DATA)"
+
+# echo pkg-config data
+pc:
+ @echo "version=$R"
+ @echo "prefix=$(INSTALL_TOP)"
+ @echo "libdir=$(INSTALL_LIB)"
+ @echo "includedir=$(INSTALL_INC)"
# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho
diff --git a/README b/README
index 91530230..78c83965 100644
--- a/README
+++ b/README
@@ -1,4 +1,6 @@
-This is Lua 5.2 (work3), released on 18 May 2010.
+
+This is Lua 5.2 (work4), released on 30 July 2010.
For information about Lua, including installation instructions and
license details, see doc/readme.html.
+
diff --git a/doc/contents.html b/doc/contents.html
index b9ae2340..397c6566 100644
--- a/doc/contents.html
+++ b/doc/contents.html
@@ -20,16 +20,17 @@ ul {
Lua 5.2 Reference Manual
</H1>
-<IMG SRC="alert.png" ALIGN="absbottom">
+<P>
+<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
<EM>This is a work version of Lua 5.2.
Everything may change in the final version.</EM>
-<P>
+<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>
+<P>
<A HREF="manual.html">start</A>
&middot;
<A HREF="#contents">contents</A>
@@ -41,101 +42,100 @@ Copyright &copy; 2010 Lua.org, PUC-Rio.
Freely available under the terms of the
<a href="http://www.lua.org/license.html#5">Lua license</a>.
</SMALL>
-<P>
<H2><A NAME="contents">Contents</A></H2>
<UL style="padding: 0">
-<LI><A HREF="manual.html">1 - Introduction</A>
+<LI><A HREF="manual.html">1 &ndash; Introduction</A>
<P>
-<LI><A HREF="manual.html#2">2 - Basic Concepts</A>
+<LI><A HREF="manual.html#2">2 &ndash; Basic Concepts</A>
<UL>
-<LI><A HREF="manual.html#2.1">2.1 - Values and Types</A>
-<LI><A HREF="manual.html#2.2">2.2 - Environments and the Global Environment</A>
-<LI><A HREF="manual.html#2.3">2.3 - Error Handling</A>
-<LI><A HREF="manual.html#2.4">2.4 - Metatables</A>
-<LI><A HREF="manual.html#2.5">2.5 - Garbage Collection</A>
+<LI><A HREF="manual.html#2.1">2.1 &ndash; Values and Types</A>
+<LI><A HREF="manual.html#2.2">2.2 &ndash; Environments and the Global Environment</A>
+<LI><A HREF="manual.html#2.3">2.3 &ndash; Error Handling</A>
+<LI><A HREF="manual.html#2.4">2.4 &ndash; Metatables</A>
+<LI><A HREF="manual.html#2.5">2.5 &ndash; Garbage Collection</A>
<UL>
-<LI><A HREF="manual.html#2.5.1">2.5.1 - Garbage-Collection Metamethods</A>
-<LI><A HREF="manual.html#2.5.2">2.5.2 - Weak Tables</A>
+<LI><A HREF="manual.html#2.5.1">2.5.1 &ndash; Garbage-Collection Metamethods</A>
+<LI><A HREF="manual.html#2.5.2">2.5.2 &ndash; Weak Tables</A>
</UL>
-<LI><A HREF="manual.html#2.6">2.6 - Coroutines</A>
+<LI><A HREF="manual.html#2.6">2.6 &ndash; Coroutines</A>
</UL>
<P>
-<LI><A HREF="manual.html#3">3 - The Language</A>
+<LI><A HREF="manual.html#3">3 &ndash; The Language</A>
<UL>
-<LI><A HREF="manual.html#3.1">3.1 - Lexical Conventions</A>
-<LI><A HREF="manual.html#3.2">3.2 - Variables</A>
-<LI><A HREF="manual.html#3.3">3.3 - Statements</A>
+<LI><A HREF="manual.html#3.1">3.1 &ndash; Lexical Conventions</A>
+<LI><A HREF="manual.html#3.2">3.2 &ndash; Variables</A>
+<LI><A HREF="manual.html#3.3">3.3 &ndash; Statements</A>
<UL>
-<LI><A HREF="manual.html#3.3.1">3.3.1 - Chunks</A>
-<LI><A HREF="manual.html#3.3.2">3.3.2 - Blocks</A>
-<LI><A HREF="manual.html#3.3.3">3.3.3 - Assignment</A>
-<LI><A HREF="manual.html#3.3.4">3.3.4 - Control Structures</A>
-<LI><A HREF="manual.html#3.3.5">3.3.5 - For Statement</A>
-<LI><A HREF="manual.html#3.3.6">3.3.6 - Function Calls as Statements</A>
-<LI><A HREF="manual.html#3.3.7">3.3.7 - Local Declarations</A>
+<LI><A HREF="manual.html#3.3.1">3.3.1 &ndash; Blocks</A>
+<LI><A HREF="manual.html#3.3.2">3.3.2 &ndash; Chunks</A>
+<LI><A HREF="manual.html#3.3.3">3.3.3 &ndash; Assignment</A>
+<LI><A HREF="manual.html#3.3.4">3.3.4 &ndash; Control Structures</A>
+<LI><A HREF="manual.html#3.3.5">3.3.5 &ndash; For Statement</A>
+<LI><A HREF="manual.html#3.3.6">3.3.6 &ndash; Function Calls as Statements</A>
+<LI><A HREF="manual.html#3.3.7">3.3.7 &ndash; Local Declarations</A>
</UL>
-<LI><A HREF="manual.html#3.4">3.4 - Expressions</A>
+<LI><A HREF="manual.html#3.4">3.4 &ndash; Expressions</A>
<UL>
-<LI><A HREF="manual.html#3.4.1">3.4.1 - Arithmetic Operators</A>
-<LI><A HREF="manual.html#3.4.2">3.4.2 - Coercion</A>
-<LI><A HREF="manual.html#3.4.3">3.4.3 - Relational Operators</A>
-<LI><A HREF="manual.html#3.4.4">3.4.4 - Logical Operators</A>
-<LI><A HREF="manual.html#3.4.5">3.4.5 - Concatenation</A>
-<LI><A HREF="manual.html#3.4.6">3.4.6 - The Length Operator</A>
-<LI><A HREF="manual.html#3.4.7">3.4.7 - Precedence</A>
-<LI><A HREF="manual.html#3.4.8">3.4.8 - Table Constructors</A>
-<LI><A HREF="manual.html#3.4.9">3.4.9 - Function Calls</A>
-<LI><A HREF="manual.html#3.4.10">3.4.10 - Function Definitions</A>
+<LI><A HREF="manual.html#3.4.1">3.4.1 &ndash; Arithmetic Operators</A>
+<LI><A HREF="manual.html#3.4.2">3.4.2 &ndash; Coercion</A>
+<LI><A HREF="manual.html#3.4.3">3.4.3 &ndash; Relational Operators</A>
+<LI><A HREF="manual.html#3.4.4">3.4.4 &ndash; Logical Operators</A>
+<LI><A HREF="manual.html#3.4.5">3.4.5 &ndash; Concatenation</A>
+<LI><A HREF="manual.html#3.4.6">3.4.6 &ndash; The Length Operator</A>
+<LI><A HREF="manual.html#3.4.7">3.4.7 &ndash; Precedence</A>
+<LI><A HREF="manual.html#3.4.8">3.4.8 &ndash; Table Constructors</A>
+<LI><A HREF="manual.html#3.4.9">3.4.9 &ndash; Function Calls</A>
+<LI><A HREF="manual.html#3.4.10">3.4.10 &ndash; Function Definitions</A>
</UL>
-<LI><A HREF="manual.html#3.5">3.5 - Visibility Rules</A>
+<LI><A HREF="manual.html#3.5">3.5 &ndash; Visibility Rules</A>
</UL>
<P>
-<LI><A HREF="manual.html#4">4 - The Application Program Interface</A>
+<LI><A HREF="manual.html#4">4 &ndash; The Application Program Interface</A>
<UL>
-<LI><A HREF="manual.html#4.1">4.1 - The Stack</A>
-<LI><A HREF="manual.html#4.2">4.2 - Stack Size</A>
-<LI><A HREF="manual.html#4.3">4.3 - Pseudo-Indices</A>
-<LI><A HREF="manual.html#4.4">4.4 - C Closures</A>
-<LI><A HREF="manual.html#4.5">4.5 - Registry</A>
-<LI><A HREF="manual.html#4.6">4.6 - Error Handling in C</A>
-<LI><A HREF="manual.html#4.7">4.7 - Handling Yields in C</A>
-<LI><A HREF="manual.html#4.8">4.8 - Functions and Types</A>
-<LI><A HREF="manual.html#4.9">4.9 - The Debug Interface</A>
+<LI><A HREF="manual.html#4.1">4.1 &ndash; The Stack</A>
+<LI><A HREF="manual.html#4.2">4.2 &ndash; Stack Size</A>
+<LI><A HREF="manual.html#4.3">4.3 &ndash; Pseudo-Indices</A>
+<LI><A HREF="manual.html#4.4">4.4 &ndash; C Closures</A>
+<LI><A HREF="manual.html#4.5">4.5 &ndash; Registry</A>
+<LI><A HREF="manual.html#4.6">4.6 &ndash; Error Handling in C</A>
+<LI><A HREF="manual.html#4.7">4.7 &ndash; Handling Yields in C</A>
+<LI><A HREF="manual.html#4.8">4.8 &ndash; Functions and Types</A>
+<LI><A HREF="manual.html#4.9">4.9 &ndash; The Debug Interface</A>
</UL>
<P>
-<LI><A HREF="manual.html#5">5 - The Auxiliary Library</A>
+<LI><A HREF="manual.html#5">5 &ndash; The Auxiliary Library</A>
<UL>
-<LI><A HREF="manual.html#5.1">5.1 - Functions and Types</A>
+<LI><A HREF="manual.html#5.1">5.1 &ndash; Functions and Types</A>
</UL>
<P>
-<LI><A HREF="manual.html#6">6 - Standard Libraries</A>
+<LI><A HREF="manual.html#6">6 &ndash; Standard Libraries</A>
<UL>
-<LI><A HREF="manual.html#6.1">6.1 - Basic Functions</A>
-<LI><A HREF="manual.html#6.2">6.2 - Coroutine Manipulation</A>
-<LI><A HREF="manual.html#6.3">6.3 - Modules</A>
-<LI><A HREF="manual.html#6.4">6.4 - String Manipulation</A>
+<LI><A HREF="manual.html#6.1">6.1 &ndash; Basic Functions</A>
+<LI><A HREF="manual.html#6.2">6.2 &ndash; Coroutine Manipulation</A>
+<LI><A HREF="manual.html#6.3">6.3 &ndash; Modules</A>
+<LI><A HREF="manual.html#6.4">6.4 &ndash; String Manipulation</A>
<UL>
-<LI><A HREF="manual.html#6.4.1">6.4.1 - Patterns</A>
+<LI><A HREF="manual.html#6.4.1">6.4.1 &ndash; Patterns</A>
</UL>
-<LI><A HREF="manual.html#6.5">6.5 - Table Manipulation</A>
-<LI><A HREF="manual.html#6.6">6.6 - Mathematical Functions</A>
-<LI><A HREF="manual.html#6.7">6.7 - Bitwise operations</A>
-<LI><A HREF="manual.html#6.8">6.8 - Input and Output Facilities</A>
-<LI><A HREF="manual.html#6.9">6.9 - Operating System Facilities</A>
-<LI><A HREF="manual.html#6.10">6.10 - The Debug Library</A>
+<LI><A HREF="manual.html#6.5">6.5 &ndash; Table Manipulation</A>
+<LI><A HREF="manual.html#6.6">6.6 &ndash; Mathematical Functions</A>
+<LI><A HREF="manual.html#6.7">6.7 &ndash; Bitwise operations</A>
+<LI><A HREF="manual.html#6.8">6.8 &ndash; Input and Output Facilities</A>
+<LI><A HREF="manual.html#6.9">6.9 &ndash; Operating System Facilities</A>
+<LI><A HREF="manual.html#6.10">6.10 &ndash; The Debug Library</A>
</UL>
<P>
-<LI><A HREF="manual.html#7">7 - Lua Stand-alone</A>
+<LI><A HREF="manual.html#7">7 &ndash; Lua Stand-alone</A>
<P>
-<LI><A HREF="manual.html#8">8 - Incompatibilities with the Previous Version</A>
+<LI><A HREF="manual.html#8">8 &ndash; Incompatibilities with the Previous Version</A>
<UL>
-<LI><A HREF="manual.html#8.1">8.1 - Changes in the Language</A>
-<LI><A HREF="manual.html#8.2">8.2 - Changes in the Libraries</A>
-<LI><A HREF="manual.html#8.3">8.3 - Changes in the API</A>
+<LI><A HREF="manual.html#8.1">8.1 &ndash; Changes in the Language</A>
+<LI><A HREF="manual.html#8.2">8.2 &ndash; Changes in the Libraries</A>
+<LI><A HREF="manual.html#8.3">8.3 &ndash; Changes in the API</A>
</UL>
<P>
-<LI><A HREF="manual.html#9">9 - The Complete Syntax of Lua</A>
+<LI><A HREF="manual.html#9">9 &ndash; The Complete Syntax of Lua</A>
</UL>
<H2><A NAME="index">Index</A></H2>
@@ -143,6 +143,7 @@ Freely available under the terms of the
<TR VALIGN="top">
<TD>
<H3><A NAME="functions">Lua functions</A></H3>
+<P>
<A HREF="manual.html#pdf-_G">_G</A><BR>
<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
<A HREF="manual.html#pdf-assert">assert</A><BR>
@@ -150,11 +151,11 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-dofile">dofile</A><BR>
<A HREF="manual.html#pdf-error">error</A><BR>
<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
+<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
<A HREF="manual.html#pdf-load">load</A><BR>
-<A HREF="manual.html#pdf-loadin">loadin</A><BR>
<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
+<A HREF="manual.html#pdf-loadin">loadin</A><BR>
<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
-<A HREF="manual.html#pdf-module">module</A><BR>
<A HREF="manual.html#pdf-next">next</A><BR>
<A HREF="manual.html#pdf-pairs">pairs</A><BR>
<A HREF="manual.html#pdf-pcall">pcall</A><BR>
@@ -169,8 +170,8 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-tostring">tostring</A><BR>
<A HREF="manual.html#pdf-type">type</A><BR>
<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
-<P>
+<P>
<A HREF="manual.html#pdf-bit.band">bit.band</A><BR>
<A HREF="manual.html#pdf-bit.bnot">bit.bnot</A><BR>
<A HREF="manual.html#pdf-bit.bor">bit.bor</A><BR>
@@ -180,25 +181,25 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-bit.rol">bit.rol</A><BR>
<A HREF="manual.html#pdf-bit.ror">bit.ror</A><BR>
<A HREF="manual.html#pdf-bit.rshift">bit.rshift</A><BR>
-<P>
+<P>
<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>
+<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.getuservalue">debug.getuservalue</A><BR>
<A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR>
<A HREF="manual.html#pdf-debug.getinfo">debug.getinfo</A><BR>
<A HREF="manual.html#pdf-debug.getlocal">debug.getlocal</A><BR>
<A HREF="manual.html#pdf-debug.getmetatable">debug.getmetatable</A><BR>
<A HREF="manual.html#pdf-debug.getregistry">debug.getregistry</A><BR>
<A HREF="manual.html#pdf-debug.getupvalue">debug.getupvalue</A><BR>
-<A HREF="manual.html#pdf-debug.setfenv">debug.setfenv</A><BR>
+<A HREF="manual.html#pdf-debug.setuservalue">debug.setuservalue</A><BR>
<A HREF="manual.html#pdf-debug.sethook">debug.sethook</A><BR>
<A HREF="manual.html#pdf-debug.setlocal">debug.setlocal</A><BR>
<A HREF="manual.html#pdf-debug.setmetatable">debug.setmetatable</A><BR>
@@ -206,8 +207,8 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-debug.traceback">debug.traceback</A><BR>
<A HREF="manual.html#pdf-debug.upvalueid">debug.upvalueid</A><BR>
<A HREF="manual.html#pdf-debug.upvaluejoin">debug.upvaluejoin</A><BR>
-<P>
+<P>
<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>
@@ -215,8 +216,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>
+<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>
@@ -231,11 +232,11 @@ Freely available under the terms of the
<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>
</TD>
<TD>
<H3>&nbsp;</H3>
+<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>
@@ -265,8 +266,8 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-math.sqrt">math.sqrt</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>
+<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>
@@ -278,8 +279,8 @@ 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>
+<P>
<A HREF="manual.html#pdf-package.config">package.config</A><BR>
<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
@@ -288,9 +289,8 @@ Freely available under the terms of the
<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.searchpath">package.searchpath</A><BR>
-<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>
-<P>
+<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>
@@ -305,8 +305,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>
+<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.pack">table.pack</A><BR>
@@ -317,6 +317,7 @@ Freely available under the terms of the
</TD>
<TD>
<H3>C API</H3>
+<P>
<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
@@ -326,9 +327,10 @@ 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>
+<P>
<A HREF="manual.html#lua_absindex">lua_absindex</A><BR>
+<A HREF="manual.html#lua_arith">lua_arith</A><BR>
<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_callk">lua_callk</A><BR>
@@ -343,7 +345,6 @@ Freely available under the terms of the
<A HREF="manual.html#lua_gc">lua_gc</A><BR>
<A HREF="manual.html#lua_getallocf">lua_getallocf</A><BR>
<A HREF="manual.html#lua_getctx">lua_getctx</A><BR>
-<A HREF="manual.html#lua_getfenv">lua_getfenv</A><BR>
<A HREF="manual.html#lua_getfield">lua_getfield</A><BR>
<A HREF="manual.html#lua_getglobal">lua_getglobal</A><BR>
<A HREF="manual.html#lua_gethook">lua_gethook</A><BR>
@@ -356,6 +357,7 @@ Freely available under the terms of the
<A HREF="manual.html#lua_gettable">lua_gettable</A><BR>
<A HREF="manual.html#lua_gettop">lua_gettop</A><BR>
<A HREF="manual.html#lua_getupvalue">lua_getupvalue</A><BR>
+<A HREF="manual.html#lua_getuservalue">lua_getuservalue</A><BR>
<A HREF="manual.html#lua_insert">lua_insert</A><BR>
<A HREF="manual.html#lua_isboolean">lua_isboolean</A><BR>
<A HREF="manual.html#lua_iscfunction">lua_iscfunction</A><BR>
@@ -404,7 +406,6 @@ Freely available under the terms of the
<A HREF="manual.html#lua_replace">lua_replace</A><BR>
<A HREF="manual.html#lua_resume">lua_resume</A><BR>
<A HREF="manual.html#lua_setallocf">lua_setallocf</A><BR>
-<A HREF="manual.html#lua_setfenv">lua_setfenv</A><BR>
<A HREF="manual.html#lua_setfield">lua_setfield</A><BR>
<A HREF="manual.html#lua_setglobal">lua_setglobal</A><BR>
<A HREF="manual.html#lua_sethook">lua_sethook</A><BR>
@@ -413,12 +414,15 @@ Freely available under the terms of the
<A HREF="manual.html#lua_settable">lua_settable</A><BR>
<A HREF="manual.html#lua_settop">lua_settop</A><BR>
<A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>
+<A HREF="manual.html#lua_setuservalue">lua_setuservalue</A><BR>
<A HREF="manual.html#lua_status">lua_status</A><BR>
<A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>
<A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>
<A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>
+<A HREF="manual.html#lua_tointegerx">lua_tointegerx</A><BR>
<A HREF="manual.html#lua_tolstring">lua_tolstring</A><BR>
<A HREF="manual.html#lua_tonumber">lua_tonumber</A><BR>
+<A HREF="manual.html#lua_tonumberx">lua_tonumberx</A><BR>
<A HREF="manual.html#lua_topointer">lua_topointer</A><BR>
<A HREF="manual.html#lua_tostring">lua_tostring</A><BR>
<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
@@ -436,10 +440,11 @@ Freely available under the terms of the
</TD>
<TD>
<H3>auxiliary library</H3>
+<P>
<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
-<P>
+<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>
@@ -471,9 +476,10 @@ Freely available under the terms of the
<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
+<A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR>
<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
-<A HREF="manual.html#luaL_openlib">luaL_openlib</A><BR>
+<A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR>
<A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR>
<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
@@ -484,27 +490,26 @@ Freely available under the terms of the
<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
-<A HREF="manual.html#luaL_register">luaL_register</A><BR>
+<A HREF="manual.html#luaL_requiref">luaL_requiref</A><BR>
<A HREF="manual.html#luaL_testudata">luaL_testudata</A><BR>
<A HREF="manual.html#luaL_tolstring">luaL_tolstring</A><BR>
<A HREF="manual.html#luaL_traceback">luaL_traceback</A><BR>
-<A HREF="manual.html#luaL_typeerror">luaL_typeerror</A><BR>
<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
+<A HREF="manual.html#luaL_typeerror">luaL_typeerror</A><BR>
<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
<A HREF="manual.html#luaL_where">luaL_where</A><BR>
</TD>
</TR>
</TABLE>
-<P>
<HR>
<SMALL>
Last update:
-Mon May 17 16:58:54 BRT 2010
+Fri Jul 30 15:13:14 BRT 2010
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (work3)
+Last change: revised for Lua 5.2.0 (work4)
-->
</BODY>
diff --git a/doc/external.png b/doc/external.png
deleted file mode 100644
index 419c06fb..00000000
--- a/doc/external.png
+++ /dev/null
Binary files differ
diff --git a/doc/lua.css b/doc/lua.css
index 40041a47..b9d3cca9 100644
--- a/doc/lua.css
+++ b/doc/lua.css
@@ -12,6 +12,24 @@ h1, h2, h3, h4 {
font-style: italic ;
}
+h2 {
+ padding-top: 0.4em ;
+ padding-bottom: 0.4em ;
+ padding-left: 20px ;
+ margin-left: -20px ;
+ background-color: #E0E0FF ;
+}
+
+h3 {
+ padding-left: 8px ;
+ border-left: solid #E0E0FF 1em ;
+}
+
+table h3 {
+ padding-left: 0px ;
+ border-left: none ;
+}
+
a:link {
color: #000080 ;
background-color: inherit ;
diff --git a/doc/manual.css b/doc/manual.css
index eed5afd9..6d5a3f09 100644
--- a/doc/manual.css
+++ b/doc/manual.css
@@ -11,3 +11,10 @@ span.apii {
font-family: inherit ;
}
+p+h1, ul+h1 {
+ padding-top: 0.4em ;
+ padding-bottom: 0.4em ;
+ padding-left: 20px ;
+ margin-left: -20px ;
+ background-color: #E0E0FF ;
+}
diff --git a/doc/manual.html b/doc/manual.html
index aed41ceb..d5220c11 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -16,7 +16,7 @@
Lua 5.2 Reference Manual
</h1>
-<IMG SRC="alert.png" ALIGN="absbottom">
+<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
<EM>This is a work version of Lua 5.2.
Everything may change in the final version.</EM>
<P>
@@ -38,7 +38,7 @@ Freely available under the terms of the
<!-- ====================================================================== -->
<p>
-<!-- $Id: manual.of,v 1.56 2010/05/17 18:28:03 roberto Exp $ -->
+<!-- $Id: manual.of,v 1.58 2010/07/30 19:05:32 roberto Exp $ -->
@@ -212,7 +212,7 @@ As discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a
any reference to a global name <code>var</code> is syntactically translated
to <code>_ENV.var</code>.
Moreover, any chunk is compiled in the scope of an external
-variable called <code>_ENV</code> (see <a href="#3.3.1">&sect;3.3.1</a>).
+variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>).
Any table used as the value of <code>_ENV</code> is usually called
an <em>environment</em>.
@@ -971,6 +971,12 @@ When you run it, it produces the following output:
main false cannot resume dead coroutine
</pre>
+<p>
+You can also create and manipulate coroutines through the C API:
+see functions <a href="#lua_newthread"><code>lua_newthread</code></a>, <a href="#lua_resume"><code>lua_resume</code></a>,
+and <a href="#lua_yield"><code>lua_yield</code></a>.
+
+
@@ -1231,19 +1237,18 @@ and variable declarations.
-<h3>3.3.1 - <a name="3.3.1">Chunks</a></h3>
+<h3>3.3.1 - <a name="3.3.1">Blocks</a></h3>
<p>
-The unit of execution of Lua is called a <em>chunk</em>.
-A chunk is simply a sequence of statements,
-which are executed sequentially.
+A block is a list of statements,
+which are executed sequentially:
<pre>
- chunk ::= {stat }
+ block ::= {stat}
</pre><p>
Lua has <em>empty statements</em>
that allow you to separate statements with semicolons,
-start a chunk with a semicolon
+start a block with a semicolon
or write two semicolons in sequence:
<pre>
@@ -1251,6 +1256,33 @@ or write two semicolons in sequence:
</pre>
<p>
+A block can be explicitly delimited to produce a single statement:
+
+<pre>
+ stat ::= <b>do</b> block <b>end</b>
+</pre><p>
+Explicit blocks are useful
+to control the scope of variable declarations.
+Explicit blocks are also sometimes used to
+add a <b>return</b> or <b>break</b> statement in the middle
+of another block (see <a href="#3.3.4">&sect;3.3.4</a>).
+
+
+
+
+
+<h3>3.3.2 - <a name="3.3.2">Chunks</a></h3>
+
+<p>
+The unit of execution of Lua is called a <em>chunk</em>.
+Syntactically,
+a chunk is simply a block:
+
+<pre>
+ chunk ::= block
+</pre>
+
+<p>
Lua handles a chunk as the body of an anonymous function
with a variable number of arguments
(see <a href="#3.4.10">&sect;3.4.10</a>).
@@ -1279,30 +1311,6 @@ Lua automatically detects the file type and acts accordingly.
-<h3>3.3.2 - <a name="3.3.2">Blocks</a></h3><p>
-A block is a list of statements;
-syntactically, a block is the same as a chunk:
-
-<pre>
- block ::= chunk
-</pre>
-
-<p>
-A block can be explicitly delimited to produce a single statement:
-
-<pre>
- stat ::= <b>do</b> block <b>end</b>
-</pre><p>
-Explicit blocks are useful
-to control the scope of variable declarations.
-Explicit blocks are also sometimes used to
-add a <b>return</b> or <b>break</b> statement in the middle
-of another block (see <a href="#3.3.4">&sect;3.3.4</a>).
-
-
-
-
-
<h3>3.3.3 - <a name="3.3.3">Assignment</a></h3>
<p>
@@ -1608,7 +1616,7 @@ Otherwise, all variables are initialized with <b>nil</b>.
<p>
-A chunk is also a block (see <a href="#3.3.1">&sect;3.3.1</a>),
+A chunk is also a block (see <a href="#3.3.2">&sect;3.3.2</a>),
and so local variables can be declared in a chunk outside any explicit block.
The scope of such local variables extends until the end of the chunk.
@@ -1713,7 +1721,7 @@ Lua supports the usual arithmetic operators:
the binary <code>+</code> (addition),
<code>-</code> (subtraction), <code>*</code> (multiplication),
<code>/</code> (division), <code>%</code> (modulo), and <code>^</code> (exponentiation);
-and unary <code>-</code> (negation).
+and unary <code>-</code> (mathematical negation).
If the operands are numbers, or strings that can be converted to
numbers (see <a href="#3.4.2">&sect;3.4.2</a>),
then all operations have the usual meaning.
@@ -1762,12 +1770,15 @@ Equality (<code>==</code>) first compares the type of its operands.
If the types are different, then the result is <b>false</b>.
Otherwise, the values of the operands are compared.
Numbers and strings are compared in the usual way.
-Objects (tables, userdata, threads, and functions)
+Tables, userdata, and threads
are compared by <em>reference</em>:
two objects are considered equal only if they are the <em>same</em> object.
Every time you create a new object
-(a table, userdata, thread, or function),
+(a table, userdata, or thread),
this new object is different from any previously existing object.
+Closures with the same reference are always equal.
+Closures with any detectable difference
+(different behavior, different definition) are always different.
<p>
@@ -1860,10 +1871,10 @@ character is one byte).
<p>
-The length of a table <code>t</code> is defined to be any
-integer index <code>n</code>
+The length of a table <code>t</code> can be any integer index <code>n</code>
such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;
moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> can be zero.
+(All accesses are assumed to be raw for this description.)
For a regular array, where all non-nil values
have keys from 1 to a given <code>n</code>,
its length is exactly that <code>n</code>,
@@ -2112,8 +2123,7 @@ the function is <em>instantiated</em> (or <em>closed</em>).
This function instance (or <em>closure</em>)
is the final value of the expression.
Different instances of the same function
-can refer to different external local variables
-and can have different environment tables.
+can refer to different external local variables.
<p>
@@ -2601,7 +2611,7 @@ only due to not enough memory;
<hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p>
<span class="apii">[-0, +0, <em>-</em>]</span>
-<pre>void lua_absindex (lua_State *L, int idx);</pre>
+<pre>int lua_absindex (lua_State *L, int idx);</pre>
<p>
Converts the acceptable index <code>idx</code> into an absolute index
@@ -2699,6 +2709,41 @@ but it seems a safe assumption.)
+<hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p>
+<span class="apii">[-2, +1, <em>e</em>]</span>
+<pre>int lua_arith (lua_State *L, int op);</pre>
+
+<p>
+Performs an arithmetic operation over the two values at the top
+of the stack (with the value at the top being the second operand),
+pops these values, and pushes the result of the operation.
+The function follows the semantics of the corresponding Lua operator
+(that is, it may call metamethods).
+
+
+<p>
+The value of <code>op</code> must be one of the following constants:
+
+<ul>
+
+<li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>:</b>performs addition (<code>+</code>)</li>
+<li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>:</b>performs subtraction (<code>-</code>)</li>
+<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>:</b>performs multiplication (<code>*</code>)</li>
+<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>:</b>performs division (<code>/</code>)</li>
+<li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>:</b>performs modulo (<code>%</code>)</li>
+<li><b><a name="pdf-LUA_OPPOw"><code>LUA_OPPOw</code></a>:</b>performs exponentiation (<code>^</code>)</li>
+<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>:</b>performs mathematical negation (unary <code>-</code>)</li>
+
+</ul>
+
+<p>
+When the operation is <code>LUA_OPUNM</code>,
+the caller must push a <b>nil</b> value for the second operand.
+
+
+
+
+
<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>
@@ -2886,7 +2931,7 @@ to avoid growing too large.
Returns 1 if the value at acceptable index <code>index1</code> satisfies <code>op</code>
when compared with the value at acceptable index <code>index2</code>,
following the semantics of the corresponding Lua operator
-(that is, may call metamethods).
+(that is, it may call metamethods).
Otherwise returns&nbsp;0.
Also returns&nbsp;0 if any of the indices is non valid.
@@ -2896,9 +2941,9 @@ The value of <code>op</code> must be one of the following constants:
<ul>
-<li><b>@<a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>:</b>compares for equality (<code>==</code>)</li>
-<li><b>@<a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>:</b>compares for less than (<code>&lt;</code>)</li>
-<li><b>@<a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>:</b>compares for less or equal (<code>&lt;=</code>)</li>
+<li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>:</b>compares for equality (<code>==</code>)</li>
+<li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>:</b>compares for less than (<code>&lt;</code>)</li>
+<li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>:</b>compares for less or equal (<code>&lt;=</code>)</li>
</ul>
@@ -3113,13 +3158,14 @@ as in the case of an yield.
-<hr><h3><a name="lua_getfenv"><code>lua_getfenv</code></a></h3><p>
+<hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p>
<span class="apii">[-0, +1, <em>-</em>]</span>
-<pre>void lua_getfenv (lua_State *L, int index);</pre>
+<pre>void lua_getuservalue (lua_State *L, int index);</pre>
<p>
-Pushes onto the stack the environment table of
-the value at the given index.
+Pushes onto the stack the Lua value associated with the userdata
+at the given index.
+This Lua value must be a table or <b>nil</b>.
@@ -4155,16 +4201,15 @@ with user data <code>ud</code>.
-<hr><h3><a name="lua_setfenv"><code>lua_setfenv</code></a></h3><p>
+<hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p>
<span class="apii">[-1, +0, <em>-</em>]</span>
-<pre>int lua_setfenv (lua_State *L, int index);</pre>
+<pre>int lua_setuservalue (lua_State *L, int index);</pre>
<p>
-Pops a table from the stack and sets it as
-the new environment for the value at the given index.
-If the value at the given index is
-neither a function nor a userdata,
-<a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0.
+Pops a table or <b>nil</b> from the stack and sets it as
+the new value associated to the userdata at the given index.
+If the value at the given index is not a userdata,
+<code>lua_setuservalue</code> returns 0.
Otherwise it returns 1.
@@ -4255,7 +4300,7 @@ If <code>index</code> is&nbsp;0, then all stack elements are removed.
<pre>typedef struct lua_State lua_State;</pre>
<p>
-Opaque structure that keeps the whole state of a Lua interpreter.
+An opaque structure that keeps the whole state of a Lua interpreter.
The Lua library is fully reentrant:
it has no global variables.
All information about a state is kept in this structure.
@@ -4285,6 +4330,13 @@ of a <a href="#lua_resume"><code>lua_resume</code></a> with an error,
or <a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended.
+<p>
+You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
+You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
+(to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a>
+(to resume a corotine).
+
+
@@ -4325,11 +4377,22 @@ otherwise, returns <code>NULL</code>.
<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>
<p>
+A macro equivalent to <code>lua_tointegerx(L, index, NULL)</code>.
+
+
+
+
+
+<hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p>
+<span class="apii">[-0, +0, <em>-</em>]</span>
+<pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>
+
+<p>
Converts the Lua value at the given acceptable index
to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>.
The Lua value must be a number or a string convertible to a number
(see <a href="#3.4.2">&sect;3.4.2</a>);
-otherwise, <a href="#lua_tointeger"><code>lua_tointeger</code></a> returns&nbsp;0.
+otherwise, <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> returns&nbsp;0.
<p>
@@ -4337,6 +4400,12 @@ If the number is not an integer,
it is truncated in some non-specified way.
+<p>
+If <code>isnum</code> is different from <code>NULL</code>,
+its referent is assigned a boolean value that
+indicates whether the operation succeeded.
+
+
@@ -4376,11 +4445,28 @@ will be valid after the corresponding value is removed from the stack.
<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>
<p>
+A macro equivalent to <code>lua_tonumberx(L, index, NULL)</code>.
+
+
+
+
+
+<hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p>
+<span class="apii">[-0, +0, <em>-</em>]</span>
+<pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>
+
+<p>
Converts the Lua value at the given acceptable index
to the C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>).
The Lua value must be a number or a string convertible to a number
(see <a href="#3.4.2">&sect;3.4.2</a>);
-otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns&nbsp;0.
+otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns&nbsp;0.
+
+
+<p>
+If <code>isnum</code> is different from <code>NULL</code>,
+its referent is assigned a boolean value that
+indicates whether the operation succeeded.
@@ -4628,7 +4714,7 @@ that need "inside information" from the interpreter.
<p>
A structure used to carry different pieces of
-information about an active function.
+information about a function or an activation record.
<a href="#lua_getstack"><code>lua_getstack</code></a> fills only the private part
of this structure, for later use.
To fill the other fields of <a href="#lua_Debug"><code>lua_Debug</code></a> with useful information,
@@ -4836,8 +4922,13 @@ This function returns 0 on error
<pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>
<p>
-Gets information about a local variable of a given activation record.
-The parameter <code>ar</code> must be a valid activation record that was
+Gets information about a local variable of
+a given activation record or a given function.
+
+
+<p>
+In the first case,
+the parameter <code>ar</code> must be a valid activation record that was
filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
The index <code>n</code> selects which local variable to inspect
@@ -4854,6 +4945,14 @@ represent internal variables
<p>
+In the second case, <code>ar</code> should be <code>NULL</code> and the function
+to be inspected must be at the top of the stack.
+In this case, only parameters of Lua functions are visible
+(as there is no information about what variables are active)
+and no values are pushed onto the stack.
+
+
+<p>
Returns <code>NULL</code> (and pushes nothing)
when the index is greater than
the number of active local variables.
@@ -5697,6 +5796,29 @@ it does not run it.
+<hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p>
+<span class="apii">[-0, +1, <em>m</em>]</span>
+<pre>int luaL_newlib (lua_State *L, const luaL_Reg *l);</pre>
+
+<p>
+Equivalent to <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> with no upvalues,
+but first creates a new table wherein to register the functions
+in list <code>l</code>.
+
+
+<p>
+Leaves the new table on the stack.
+
+
+<p>
+It is implemented as a macro.
+The array <code>l</code> must be the actual array,
+not a pointer to it.
+
+
+
+
+
<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>
@@ -5739,46 +5861,23 @@ or <code>NULL</code> if there is a memory allocation error.
-<hr><h3><a name="luaL_openlib"><code>luaL_openlib</code></a></h3><p>
-<span class="apii">[-(nup + (0|1)), +1, <em>e</em>]</span>
-<pre>void luaL_openlib (lua_State *L,
- const char *libname,
- const luaL_Reg *l,
- int nup);</pre>
-
-<p>
-Opens a library.
-
+<hr><h3><a name="luaL_setfuncs"><code>luaL_setfuncs</code></a></h3><p>
+<span class="apii">[-nup, +0, <em>e</em>]</span>
+<pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre>
<p>
-When called with <code>libname</code> equal to <code>NULL</code>,
-it simply registers all functions in the array <code>l</code>
-(see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack.
+Registers all functions in the array <code>l</code>
+(see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack
+(below optional upvalues, see next).
The pointer <code>l</code> may be <code>NULL</code>,
representing an empty list.
<p>
-When called with a non-null <code>libname</code>,
-<code>luaL_openlib</code> creates a new table <code>t</code>,
-sets it as the value of the global variable <code>libname</code>,
-sets it as the value of <code>package.loaded[libname]</code>,
-and registers on it all functions in the list <code>l</code>.
-If there is a table in <code>package.loaded[libname]</code> or
-in global variable <code>libname</code>,
-reuses this table instead of creating a new one.
-
-
-<p>
-In any case the function leaves the table
-on the top of the stack.
-
-
-<p>
When <code>nup</code> is not zero,
all functions are created sharing <code>nup</code> upvalues,
which must be previously pushed on the stack
-(on top of the library table, if present).
+on top of the library table.
These values are popped from the stack after the registration.
@@ -5963,7 +6062,7 @@ from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
<p>
Type for arrays of functions to be registered by
-<a href="#luaL_openlib"><code>luaL_openlib</code></a>.
+<a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>.
<code>name</code> is the function name and <code>func</code> is a pointer to
the function.
Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sentinel entry
@@ -5973,15 +6072,24 @@ 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><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>
+<hr><h3><a name="luaL_requiref"><code>luaL_requiref</code></a></h3><p>
+<span class="apii">[-0, +1, <em>e</em>]</span>
+<pre>void luaL_requiref (lua_State *L, const char *modname,
+ lua_CFunction openf, int glb);</pre>
+
+<p>
+Calls function <code>openf</code> with string <code>modname</code> as an argument
+and sets the call result in <code>package.loaded[modname]</code>,
+as if that function has been called through <a href="#pdf-require"><code>require</code></a>.
+
+
+<p>
+If <code>glb</code> is true,
+also stores the result into global <code>modname</code>.
+
<p>
-This macro is equivalent to calling <a href="#luaL_openlib"><code>luaL_openlib</code></a>
-with no upvalues.
+Leaves a copy of that result on the stack.
@@ -6134,10 +6242,12 @@ Currently, Lua has the following standard libraries:
<ul>
-<li>basic library, which includes the coroutine sub-library;</li>
+<li>basic library;</li>
<li>package library;</li>
+<li>coroutine library;</li>
+
<li>string manipulation;</li>
<li>table manipulation;</li>
@@ -6166,6 +6276,7 @@ Alternatively,
it can open them individually by calling
<a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
<a name="pdf-luaopen_package"><code>luaopen_package</code></a> (for the package library),
+<a name="pdf-luaopen_coroutine"><code>luaopen_coroutine</code></a> (for the coroutine library),
<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),
@@ -6324,6 +6435,30 @@ Otherwise, returns the metatable of the given object.
<p>
+<hr><h3><a name="pdf-ipairs"><code>ipairs (t)</code></a></h3>
+
+
+<p>
+If <code>t</code> has a metamethod <code>__ipairs</code>,
+calls it with <code>t</code> as argument and returns the first three
+results from the call.
+
+
+<p>
+Otherwise,
+returns three values: an iterator function, the table <code>t</code>, and 0,
+so that the construction
+
+<pre>
+ for i,v in ipairs(t) do <em>body</em> end
+</pre><p>
+will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middot;&middot;&middot;,
+up to the first integer key absent from the table.
+
+
+
+
+<p>
<hr><h3><a name="pdf-load"><code>load (ld [, source [, mode]])</code></a></h3>
@@ -6776,62 +6911,13 @@ Any arguments to <code>yield</code> are passed as extra results to <code>resume<
<p>
The package library provides basic
-facilities for loading and building modules in Lua.
-It exports two of its functions directly in the global environment:
-<a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.
+facilities for loading modules in Lua.
+It exports one function directly in the global environment:
+<a href="#pdf-require"><code>require</code></a>.
Everything else is exported in a table <a name="pdf-package"><code>package</code></a>.
<p>
-<hr><h3><a name="pdf-module"><code>module (name [, &middot;&middot;&middot;])</code></a></h3>
-
-
-<p>
-Creates and returns a module.
-If there is a table in <code>package.loaded[name]</code>,
-this table is the module.
-Otherwise, if there is a global table <code>t</code> with the given name,
-this table is the module.
-Otherwise creates a new table <code>t</code> and
-sets it as the value of the global <code>name</code> and
-the value of <code>package.loaded[name]</code>.
-This function also initializes <code>t._NAME</code> with the given name,
-<code>t._M</code> with the module (<code>t</code> itself),
-and <code>t._PACKAGE</code> with the package name
-(the full module name minus last component; see below).
-Finally, <code>module</code> sets <code>t</code> as the new value of <code>package.loaded[name]</code>,
-so that <a href="#pdf-require"><code>require</code></a> returns <code>t</code>.
-
-
-<p>
-The <code>module</code> function returns the module table <code>t</code>.
-
-
-<p>
-If <code>name</code> is a compound name
-(that is, one with components separated by dots),
-<code>module</code> creates (or reuses, if they already exist)
-tables for each component.
-For instance, if <code>name</code> is <code>a.b.c</code>,
-then <code>module</code> stores the module table in field <code>c</code> of
-field <code>b</code> of global <code>a</code>.
-
-
-<p>
-This function can receive optional <em>options</em> after
-the module name,
-where each option is a function to be applied over the module.
-
-
-<p>
-To keep compatibility with old versions of Lua,
-<code>module</code> also sets <code>t</code> as the new environment
-of the current function.
-
-
-
-
-<p>
<hr><h3><a name="pdf-require"><code>require (modname)</code></a></h3>
@@ -6928,7 +7014,8 @@ The path used by <a href="#pdf-require"><code>require</code></a> to search for a
<p>
Lua initializes the C&nbsp;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>
+using the environment variable <a name="pdf-LUA_CPATH_5_2"><code>LUA_CPATH_5_2</code></a>
+or the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a>
or a default path defined in <code>luaconf.h</code>.
@@ -7080,7 +7167,8 @@ The path used by <a href="#pdf-require"><code>require</code></a> to search for a
<p>
At start-up, Lua initializes this variable with
-the value of the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or
+the value of the environment variable <a name="pdf-LUA_PATH_5_2"><code>LUA_PATH_5_2</code></a> or
+the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or
with a default path defined in <code>luaconf.h</code>,
if the environment variable is not defined.
Any "<code>;;</code>" in the value of the environment variable
@@ -7136,20 +7224,6 @@ or <b>nil</b> plus an error message if none succeeds.
-<p>
-<hr><h3><a name="pdf-package.seeall"><code>package.seeall (module)</code></a></h3>
-
-
-<p>
-Sets a metatable for <code>module</code> with
-its <code>__index</code> field referring to the global environment,
-so that this module inherits values
-from the global environment.
-To be used as an option to function <a href="#pdf-module"><code>module</code></a>.
-
-
-
-
@@ -7222,6 +7296,9 @@ a copy of the function.
<p>
<hr><h3><a name="pdf-string.find"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>
+
+
+<p>
Looks for the first match of
<code>pattern</code> in the string <code>s</code>.
If it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>
@@ -7248,10 +7325,12 @@ after the two indices.
<p>
<hr><h3><a name="pdf-string.format"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>
+
+
+<p>
Returns a formatted version of its variable number of arguments
following the description given in its first argument (which must be a string).
-The format string follows the same rules as the <code>printf</code> family of
-standard C&nbsp;functions.
+The format string follows the same rules as the C&nbsp;function <code>sprintf</code>.
The only differences are that the options/modifiers
<code>*</code>, <code>l</code>, <code>L</code>, <code>n</code>, <code>p</code>,
and <code>h</code> are not supported
@@ -7500,6 +7579,8 @@ represents the character <em>x</em> itself.
<li><b><code>%d</code>:</b> represents all digits.</li>
+<li><b><code>%g</code>:</b> represents all printable characters except space.</li>
+
<li><b><code>%l</code>:</b> represents all lowercase letters.</li>
<li><b><code>%p</code>:</b> represents all punctuation characters.</li>
@@ -8329,7 +8410,7 @@ Without a <code>file</code>, closes the default output file.
<p>
-Equivalent to <code>file:flush</code> over the default output file.
+Equivalent to <code>io.output():flush()</code>.
@@ -8450,7 +8531,7 @@ on all platforms.
<p>
-Equivalent to <code>io.input():read</code>.
+Equivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.
@@ -8485,7 +8566,7 @@ or <b>nil</b> if <code>obj</code> is not a file handle.
<p>
-Equivalent to <code>io.output():write</code>.
+Equivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.
@@ -8960,8 +9041,11 @@ within any function, and so have no direct access to local variables.
<p>
-<hr><h3><a name="pdf-debug.getfenv"><code>debug.getfenv (o)</code></a></h3>
-Returns the environment of object <code>o</code>.
+<hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3>
+
+
+<p>
+Returns the Lua value associated to userdata <code>u</code>.
@@ -9023,17 +9107,17 @@ about the <a href="#pdf-print"><code>print</code></a> function.
<p>
-<hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] level, local)</code></a></h3>
+<hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] f, local)</code></a></h3>
<p>
This function returns the name and the value of the local variable
-with index <code>local</code> of the function at level <code>level</code> of the stack.
+with index <code>local</code> of the function at level <code>f</code> of the stack.
(The first parameter or local variable has index&nbsp;1, and so on,
until the last active local variable.)
The function returns <b>nil</b> if there is no local
variable with the given index,
-and raises an error when called with a <code>level</code> out of range.
+and raises an error when called with a level out of range.
(You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.)
@@ -9043,6 +9127,11 @@ represent internal variables
(loop control variables, temporaries, and C&nbsp;function locals).
+<p>
+The parameter <code>f</code> may also be a function.
+In that case, <code>getlocal</code> returns only the name of function parameters.
+
+
<p>
@@ -9079,12 +9168,17 @@ The function returns <b>nil</b> if there is no upvalue with the given index.
<p>
-<hr><h3><a name="pdf-debug.setfenv"><code>debug.setfenv (object, table)</code></a></h3>
+<hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3>
<p>
-Sets the environment of the given <code>object</code> to the given <code>table</code>.
-Returns <code>object</code>.
+Sets the given <code>value</code> as
+the Lua value associated to the given <code>udata</code>.
+<code>value</code> must be a table or <b>nil</b>.
+
+
+<p>
+Returns <code>udata</code>.
@@ -9259,7 +9353,8 @@ and as <code>lua -</code> otherwise.
<p>
Before running any argument,
-the interpreter checks for an environment variable <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a>.
+the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_2"><code>LUA_INIT_5_2</code></a>
+(or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined).
If its format is <code>@<em>filename</em></code>,
then <code>lua</code> executes the file.
Otherwise, <code>lua</code> executes the string itself.
@@ -9418,6 +9513,12 @@ not be a corresponding return event.
<ul>
<li>
+Function <code>module</code> is deprecated.
+Modules are not expected to set global variables anymore,
+and it is easy to set up a module with regular Lua code.
+</li>
+
+<li>
The debug library is not loaded by default.
You must explicitly require it.
</li>
@@ -9429,12 +9530,6 @@ use the variable <code>_ENV</code> or the new function <a href="#pdf-loadin"><co
</li>
<li>
-Function <code>ipairs</code> is deprecated.
-Use a numerical for loop instead,
-or write it in Lua.
-</li>
-
-<li>
Function <code>math.log10</code> is deprecated.
Use <a href="#pdf-math.log"><code>math.log</code></a> with 10 as its second argument, instead.
</li>
@@ -9481,19 +9576,21 @@ You must get the global environment from the registry
</li>
<li>
-Pseudoindex <code>LUA_ENVIRONINDEX</code> was removed.
+Pseudoindex <code>LUA_ENVIRONINDEX</code>
+and functions <code>lua_getfenv</code>/<code>lua_setfenv</code>
+were removed.
C functions do not have environments any more.
Use an upvalue with a shared table if you need to keep
shared state among several C functions.
-(You may use <a href="#luaL_openlib"><code>luaL_openlib</code></a> to open a C library
+(You may use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> to open a C library
with all functions sharing a common upvalue.)
-</li>
-<li>
-Macros <a href="#lua_getglobal"><code>lua_getglobal</code></a>, <a href="#lua_setglobal"><code>lua_setglobal</code></a>, and <a href="#lua_register"><code>lua_register</code></a>
-now operate over the function environment instead of the global
-environment.
-(This is more consistent with how Lua manipulates global variables.)
+
+<p>
+To manipulate the "environment" of a userdata
+(which is not called "environment" anymore),
+use the new functions
+<a href="#lua_getuservalue"><code>lua_getuservalue</code></a> and <a href="#lua_setuservalue"><code>lua_setuservalue</code></a>.
</li>
<li>
@@ -9532,9 +9629,9 @@ Here is the complete syntax of Lua in extended BNF.
<pre>
- chunk ::= {stat} [laststat [&lsquo<b>;</b>&rsquo;]]
+ chunk ::= block
- block ::= chunk
+ block ::= {stat} [laststat [&lsquo<b>;</b>&rsquo;]]
stat ::= &lsquo<b>;</b>&rsquo; |
varlist &lsquo<b>=</b>&rsquo; explist |
@@ -9604,10 +9701,10 @@ Here is the complete syntax of Lua in extended BNF.
<HR>
<SMALL>
Last update:
-Mon May 17 16:24:08 BRT 2010
+Fri Jul 30 16:41:34 BRT 2010
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (work3)
+Last change: revised for Lua 5.2.0 (work4)
-->
</body></html>
diff --git a/doc/readme.html b/doc/readme.html
index 076dd81f..9284427d 100644
--- a/doc/readme.html
+++ b/doc/readme.html
@@ -13,27 +13,12 @@ blockquote, .display {
margin-left: 0px ;
}
-.external {
- padding-right: 15px;
- background: transparent url(external.png) no-repeat center right;
-}
-
tt, kbd, code {
font-size: 120% ;
xcolor: black ;
xpadding: 4px ;
xbackground-color: #E0E0E0 ;
}
-
-kbd {
- color: black ;
- background-color: #E8E8E8 ;
-}
-
-.review {
- color: red ;
-}
-
</STYLE>
</HEAD>
@@ -42,14 +27,15 @@ kbd {
<HR>
<H1>
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
-Welcome to Lua 5.2
+Welcome to Lua 5.2 (work4)
</H1>
-<IMG SRC="alert.png" ALIGN="absbottom">
+<P>
+<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
<EM>This is a work version of Lua 5.2.
Everything may change in the final version.</EM>
-<P>
+<P>
<A HREF="#about">about</A>
&middot;
<A HREF="#install">installation</A>
@@ -60,10 +46,10 @@ Everything may change in the final version.</EM>
&middot;
<A HREF="contents.html">reference manual</A>
<HR>
-<P>
<H2><A NAME="about">About Lua</A></H2>
+<P>
Lua is a powerful, fast, lightweight, embeddable scripting language
developed by a
<A HREF="http://www.lua.org/authors.html">team</A>
@@ -73,8 +59,8 @@ the Pontifical Catholic University of Rio de Janeiro in Brazil.
Lua is
<A HREF="#license">free software</A>
used in many products and projects around the world.
-<P>
+<P>
Lua's
<A HREF="http://www.lua.org/">official web site</A>
provides complete information
@@ -90,36 +76,53 @@ especially the
which may differ slightly from the
<A HREF="contents.html">local copy</A>
distributed in this package.
-<P>
<H2><A NAME="install">Installing Lua</A></H2>
-Lua is distributed in source form.
+<P>
+Lua is distributed in
+<A HREF="ftp/">source</A>
+form.
You need to build it before using it.
-This should be straightforward
+Building Lua should be straightforward
because
Lua is implemented in pure ANSI C, and compiles unmodified in all known
platforms that have an ANSI C compiler.
Lua also compiles unmodified as C++.
-<P>
+<P>
The instructions below are for Unix-like platforms.
There are also
<A HREF="#other">instructions for other systems</A>.
See below for
<A HREF="#customization">customization options</A>.
+
<P>
+If you don't have the time or the inclination to compile Lua yourself,
+get a binary from
+<A HREF="http://lua-users.org/wiki/LuaBinaries">LuaBinaries</A>.
+Try also
+<A HREF="http://luaforwindows.luaforge.net/">Lua for Windows</A>,
+an easy-to-use distribution of Lua that includes many useful libraries.
+
+<!--
+<P>
+If you only want to try Lua,
+try the
+<A HREF="demo.html">live demo</A>.
+<P>
+-->
<H3>Building Lua</H3>
+<P>
In most Unix-like platforms, simply do "<KBD>make</KBD>" with a suitable target.
Here are the details.
-<P>
<OL>
<LI>
Open a terminal window and move to
-the top-level directory, which is named lua-5.2.
+the top-level directory, which is named lua-5.2.0.
The Makefile there controls both the build process and the installation process.
<P>
<LI>
@@ -143,29 +146,31 @@ luac (the compiler),
and liblua.a (the library).
<P>
<LI>
- If you want to check that Lua has been built correctly, do "<KBD>make test</KBD>"
- after building Lua. This will run the interpreter on a "hello world"
+ To check that Lua has been built correctly, do "<KBD>make test</KBD>"
+ after building Lua. This will run the interpreter on a simple "Hello world"
Lua program from the test directory.
You may want to try other example programs in that directory.
</OL>
-<P>
<H3>Installing Lua</H3>
+<P>
Once you have built Lua, you may want to install it in an official
place in your system. In this case, do "<KBD>make install</KBD>". The official
place and the way to install files are defined in Makefile. You'll
probably need the right permissions to install files.
-<P>
- If you want to build and install Lua in one step, do "<KBD>make xxx install</KBD>",
- where xxx is your platform name.
<P>
+ To build and install Lua in one step, do "<KBD>make xxx install</KBD>",
+ where xxx is your platform name.
- If you want to install Lua locally, then do "<KBD>make local</KBD>".
+<P>
+ To install Lua locally, then do "<KBD>make local</KBD>".
This will create a directory <TT>install</TT> with subdirectories
<TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>,
- and install Lua there as follows:
-<P>
+ and install Lua as listed below.
+
+ To install Lua locally, but in some other directory, do
+ "<KBD>make install INSTALL_TOP=xxx</KBD>", where xxx is your chosen directory.
<DL CLASS="display">
<DT>
@@ -186,52 +191,48 @@ and liblua.a (the library).
lua.1 luac.1
</DL>
- These are the only directories you need for development.
-<P>
-
- There are man pages for
- <A HREF="lua.html">lua</A> and
- <A HREF="luac.html">luac</A>, in both nroff and html, and a
- <A HREF="contents.html">reference manual</A> in html in doc, some sample code in test, and some
- useful stuff in etc. You don't need these directories for development.
-<P>
-
- If you want to install Lua locally, but in some other directory, do
- "<KBD>make install INSTALL_TOP=xxx</KBD>", where xxx is your chosen directory.
<P>
+ These are the only directories you need for development.
+ If you only want to run Lua programs,
+ you only need the files in bin and man.
+ The files in include and lib are needed for
+ embedding Lua in C or C++ programs.
<H3><A NAME="customization">Customization</A></H3>
+<P>
Three kinds of things can be customized by editing a file:
<UL>
<LI> Where and how to install Lua &mdash; edit Makefile.
<LI> How to build Lua &mdash; edit src/Makefile.
<LI> Lua features &mdash; edit src/luaconf.h.
</UL>
-<P>
+<P>
You don't actually need to edit the Makefiles because you may set the
relevant variables in the command line when invoking make.
-<P>
+ Nevertheless, it's probably best to edit and save the Makefiles to
+ record the changes you need.
+<P>
On the other hand, if you need to customize some Lua features, you'll need
to edit src/luaconf.h before building and installing Lua.
The edited file will be the one installed, and
it will be used by any Lua clients that you build, to ensure consistency.
- (Further customization is possible by editing the Lua sources.)
-<P>
+ Further customization is available to experts by editing the Lua sources.
- We strongly recommend that you enable dynamic loading. This is done
- automatically for all platforms listed above that have this feature
- and also for Windows.
<P>
+ We strongly recommend that you enable dynamic loading in src/luaconf.h.
+ This is done automatically for all platforms listed above that have
+ this feature and also for Windows.
<H3><A NAME="other">Building Lua on other systems</A></H3>
+<P>
If you're not using the usual Unix tools, then the instructions for
building Lua depend on the compiler you use. You'll need to create
projects (or whatever your compiler uses) for building the library,
the interpreter, and the compiler, as follows:
-<P>
+
<DL CLASS="display">
<DT>
library:
@@ -239,8 +240,9 @@ library:
lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c
ltm.c lundump.c lvm.c lzio.c
-lauxlib.c lbaselib.c lbitlib.c ldblib.c liolib.c lmathlib.c loslib.c
-ltablib.c lstrlib.c loadlib.c linit.c
+lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c
+lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c
+
<DT>
interpreter:
<DD>
@@ -251,14 +253,7 @@ compiler:
library, luac.c print.c
</DL>
- If you use Visual Studio .NET, you can use <TT>etc/luavs.bat</TT> in its
- "Command Prompt".
-<P>
-
- If all you want is to build the Lua interpreter, you may put all .c files
- in a single project, except for luac.c and print.c. Or just use <TT>etc/one.c</TT>.
<P>
-
To use Lua as a library in your own programs you'll need to know how to
create and use libraries with your compiler. Moreover, to dynamically load
C libraries for Lua you'll need to know how to create dynamic libraries
@@ -268,38 +263,31 @@ compiler:
be linked statically into the host program and its symbols exported for
dynamic linking; src/Makefile does this for the Lua interpreter.
For Windows, we recommend that the Lua library be a DLL.
-<P>
+<P>
As mentioned above, you may edit src/luaconf.h to customize
some features before building Lua.
-<P>
-<H2><A NAME="changes">Changes since Lua 5.1</A></H2>
+<H2><A NAME="changes">Changes since Lua 5.2.0 (work3)</A></H2>
-<IMG SRC="alert.png" ALIGN="absbottom">
-<EM>Everything may change in the final version.</EM>
-<P>
-
-Here are the main changes since the previous work version:
<UL>
-<LI> new <CODE>_ENV</CODE> proposal
-<LI> generational collector (very experimental)
-<LI> light C functions
-
-<LI> order tag methods follow the same rules of other binary operators
-<LI> <CODE>lua_absindex</CODE>
-<LI> \0 in patterns
-<LI> empty statement
-<LI> options in <CODE>io.lines</CODE>
+<LI> <CODE>module</CODE> and <CODE>luaL_register</CODE> deprecated, replaced by <CODE>luaL_newlib</CODE> and <CODE>luaL_setfuncs</CODE>.
+<LI> new function <CODE>luaL_requiref</CODE>.
+<LI> caching of Lua closures for resue.
+<LI> version-specific environment variables (<CODE>LUA_PATH_5_2</CODE>, etc.).
+<LI> new class '%g' in patterns.
+<LI> <CODE>debug.getlocal</CODE> gets parameter names of inactive functions.
+<LI> new functions <CODE>lua_tonumberx</CODE> and <CODE>lua_tointegerx</CODE>.
</UL>
-<P>
-Here are the main changes in Lua since its last release.
+<H2><A NAME="changes">Changes since Lua 5.1</A></H2>
+
+<P>
+Here are the main changes introduced in Lua 5.2.
The
<A HREF="contents.html">reference manual</A>
lists the
-<A HREF="manual.html#7">incompatibilities</A> that had to be introduced.
-<P>
+<A HREF="manual.html#8">incompatibilities</A> that had to be introduced.
<H3>Language</H3>
<UL>
@@ -358,42 +346,40 @@ lists the
<LI> handling of non-string error messages in the standalone interpreter.
</UL>
-
<H2><A NAME="license">License</A></H2>
<A HREF="http://www.opensource.org/docs/definition.php">
-<IMG SRC="osi-certified-72x60.png" ALIGN="right" BORDER="0" ALT="[osi certified]" xSTYLE="padding: 40px ;" hspace="10">
+<IMG SRC="osi-certified-72x60.png" ALIGN="right" BORDER="0" ALT="[osi certified]" STYLE="padding-left: 30px ;">
</A>
+<P>
Lua is free software licensed under the terms of the
<A HREF="http://www.opensource.org/licenses/mit-license.html">MIT license</A>
-reproduced below,
-and
-can be used for any purpose, including commercial purposes,
+reproduced below;
+it can be used for any purpose, including commercial purposes,
at absolutely no cost without having to ask us.
The only requirement is that if you do use Lua,
then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.
-For details and rationale, see
-<A HREF="http://www.lua.org/license.html" class="external">this</A>.
-<P>
+For details, see
+<A HREF="http://www.lua.org/license.html">this</A>.
<BLOCKQUOTE>
Copyright &copy; 1994&ndash;2010 Lua.org, PUC-Rio.
-<P>
+<P>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
-<P>
+<P>
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
-<P>
+<P>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -401,17 +387,15 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-<P>
</BLOCKQUOTE>
-<P>
<HR>
<SMALL>
Last update:
-Tue May 18 13:59:06 BRT 2010
+Fri Jul 30 15:12:25 BRT 2010
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (work3)
+Last change: revised for Lua 5.2.0 (work4)
-->
</BODY>
diff --git a/etc/Makefile b/etc/Makefile
deleted file mode 100644
index 34d8571a..00000000
--- a/etc/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@
-# makefile for Lua etc
-
-TOP= ..
-LIB= $(TOP)/src
-INC= $(TOP)/src
-BIN= $(TOP)/src
-SRC= $(TOP)/src
-TST= $(TOP)/test
-
-T= test
-CC= gcc
-CFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS)
-MYCFLAGS=
-MYLIBS= -lm # -ldl -lreadline -lncurses -Wl,-E
-RM= rm -f
-
-
-default:
- @echo 'Please choose a target: min noparser one one-lua one-lib one-luac so strict clean'
-
-min: min.c
- $(CC) $(CFLAGS) -o $T min.c -L$(LIB) -llua $(MYLIBS)
- echo 'print"Hello there!"' | ./$T
- ./$T $(TST)/hello.lua
- echo 'print("Hello world, from",_VERSION,"!")' | ./$T
-
-noparser: noparser.o
- $(CC) -o $T noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS)
- $(BIN)/luac $(TST)/hello.lua
- -./$T luac.out
- -./$T -e'a=1'
-
-one: one-lua one-lib one-luac
-
-one-lua:
- $(CC) $(CFLAGS) -o $T one.c $(MYLIBS)
- ./$T $(TST)/hello.lua
-
-one-lib:
- $(CC) $(CFLAGS) -DMAKE_LIB -o liblua.o -c one.c
- $(CC) $(CFLAGS) -o $T min.c liblua.o $(MYLIBS)
- ./$T $(TST)/hello.lua
-
-one-luac:
- $(CC) $(CFLAGS) -o $T -DMAKE_LUAC one.c $(MYLIBS)
- ./$T -l $(TST)/hello.lua
-
-so:
- $(CC) $(CFLAGS) -shared -o dummy.so dummy.c
- @#env MACOSX_DEPLOYMENT_TARGET=10.3 $(CC) $(CFLAGS) -bundle -undefined dynamic_lookup -o dummy.so dummy.c
- $(BIN)/lua -v -ldummy
-
-strict:
- -$(BIN)/lua -e 'print(a);b=2'
- -$(BIN)/lua -lstrict -e 'print(a)'
- -$(BIN)/lua -e 'function f() b=2 end f()'
- -$(BIN)/lua -lstrict -e 'function f() b=2 end f()'
-
-clean:
- $(RM) $T a.out core core.* *.o luac.out dummy.so
-
-.PHONY: default min noparser one one-lua one-lib one-luac so strict clean
diff --git a/etc/README b/etc/README
deleted file mode 100644
index 0eda3bd3..00000000
--- a/etc/README
+++ /dev/null
@@ -1,30 +0,0 @@
-This directory contains some useful files and code.
-Unlike the code in ../src, everything here is in the public domain.
-
-If any of the makes fail, you're probably not using the same libraries used
-to build Lua. Set MYLIBS in Makefile or in the command line accordingly.
-
-dummy.c:
- A minimal Lua library for testing dynamic loading.
- Do "make so" for a demo.
-
-luavs.bat
- Script to build Lua under "Visual Studio .NET Command Prompt".
- Run it from the toplevel as etc\luavs.bat.
-
-min.c
- A minimal Lua interpreter for learning and for starting your own.
- Do "make min" for a demo.
-
-noparser.c
- Linking with noparser.o avoids loading the parsing modules in lualib.a.
- Do "make noparser" for a demo.
-
-one.c
- Full Lua interpreter in a single file. Also library and compiler.
- Do "make one" for a demo.
-
-strict.lua
- Traps uses of undeclared global variables.
- Do "make strict" for a demo.
-
diff --git a/etc/dummy.c b/etc/dummy.c
deleted file mode 100644
index 1d40e8be..00000000
--- a/etc/dummy.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
-* dummy.c -- a minimal Lua library for testing dynamic loading
-*/
-
-#include <stdio.h>
-#include "lua.h"
-
-int luaopen_dummy (lua_State *L) {
- puts("Hello from dummy");
- return 0;
-}
diff --git a/etc/luavs.bat b/etc/luavs.bat
deleted file mode 100644
index 14518713..00000000
--- a/etc/luavs.bat
+++ /dev/null
@@ -1,28 +0,0 @@
-@rem Script to build Lua 5.2 under "Visual Studio .NET Command Prompt".
-@rem Do not run from this directory; run it from the toplevel: etc\luavs.bat .
-@rem It creates lua52.dll, lua52.lib, lua.exe, and luac.exe in src.
-@rem (contributed by David Manura and Mike Pall)
-
-@setlocal
-@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
-@set MYLINK=link /nologo
-@set MYMT=mt /nologo
-
-cd src
-%MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c
-del lua.obj luac.obj
-%MYLINK% /DLL /out:lua52.dll l*.obj
-if exist lua52.dll.manifest^
- %MYMT% -manifest lua52.dll.manifest -outputresource:lua52.dll;2
-%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c
-%MYLINK% /out:lua.exe lua.obj lua52.lib
-if exist lua.exe.manifest^
- %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe
-%MYCOMPILE% l*.c print.c
-del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^
- loslib.obj ltablib.obj lstrlib.obj loadlib.obj
-%MYLINK% /out:luac.exe *.obj
-if exist luac.exe.manifest^
- %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe
-del *.obj *.manifest
-cd ..
diff --git a/etc/min.c b/etc/min.c
deleted file mode 100644
index 0b6a5c32..00000000
--- a/etc/min.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-* min.c -- a minimal Lua interpreter
-* runs one file from the command line or stdin if no file given.
-* minimal error handling, no traceback, no interaction, no standard library,
-* only a "print" function.
-*/
-
-#include <stdio.h>
-
-#include "lua.h"
-#include "lauxlib.h"
-#include "lualib.h"
-
-static int print(lua_State *L)
-{
- int n=lua_gettop(L);
- int i;
- for (i=1; i<=n; i++)
- printf("%s ",luaL_tolstring(L,i,NULL));
- printf("\n");
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- lua_State *L=luaL_newstate();
- luaL_openlibs(L);
- lua_register(L,"print",print);
- if (luaL_dofile(L,argv[1])!=0)
- fprintf(stderr,"%s: %s\n",argv[0],lua_tostring(L,-1));
- lua_close(L);
- return 0;
-}
diff --git a/etc/noparser.c b/etc/noparser.c
deleted file mode 100644
index f1fd4aea..00000000
--- a/etc/noparser.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
-* The code below can be used to make a Lua core that does not contain the
-* parsing modules (lcode, llex, lparser), which represent 35% of the total core.
-* You'll only be able to load binary files and strings, precompiled with luac.
-* (Of course, you'll have to build luac with the original parsing modules!)
-*
-* To use this module, simply compile it and list its object file before the
-* Lua libraries. The linker should then not load the parsing modules.
-*
-* If you want to avoid the dump module or the undump modules, use the
-* corresponding #define below.
-*
-#define NOPARSER
-#define NODUMP
-#define NOUNDUMP
-*/
-
-#define NOPARSER
-
-#define LUA_CORE
-#include "lua.h"
-
-/* --------------------------------------------------------------- noparser */
-#ifdef NOPARSER
-#include "llex.h"
-#include "lparser.h"
-#include "lzio.h"
-
-LUAI_FUNC void luaX_init (lua_State *L) {
- UNUSED(L);
-}
-
-LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Varlist *varl, const char *name) {
- UNUSED(z);
- UNUSED(buff);
- UNUSED(name);
- lua_pushliteral(L,"parser not available");
- lua_error(L);
- return NULL;
-}
-#endif
-
-/* --------------------------------------------------------------- nodump */
-#ifdef NODUMP
-#include "lundump.h"
-
-LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) {
- UNUSED(f);
- UNUSED(w);
- UNUSED(data);
- UNUSED(strip);
- lua_pushliteral(L,"dumper not available");
- lua_error(L);
- return 0;
-}
-#endif
-
-/* --------------------------------------------------------------- noundump */
-#ifdef NOUNDUMP
-#include "lundump.h"
-
-LUAI_FUNC Proto *luaU_undump (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
- UNUSED(z);
- UNUSED(buff);
- UNUSED(name);
- lua_pushliteral(L,"binary loader not available");
- lua_error(L);
- return NULL;
-}
-#endif
diff --git a/etc/one.c b/etc/one.c
deleted file mode 100644
index 372543a6..00000000
--- a/etc/one.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-* one.c -- Lua core, libraries, and interpreter in a single file
-*/
-
-/* default is to build the full interpreter */
-#ifndef MAKE_LIB
-#ifndef MAKE_LUAC
-#ifndef MAKE_LUA
-#define MAKE_LUA
-#endif
-#endif
-#endif
-
-/* choose suitable platform-specific features */
-/* some of these may need extra libraries such as -ldl -lreadline -lncurses */
-#if 0
-#define LUA_USE_LINUX
-#define LUA_USE_MACOSX
-#define LUA_USE_POSIX
-#define LUA_ANSI
-#endif
-
-#define luaall_c
-
-/* core -- used by all */
-#include "lapi.c"
-#include "lcode.c"
-#include "lctype.c"
-#include "ldebug.c"
-#include "ldo.c"
-#include "ldump.c"
-#include "lfunc.c"
-#include "lgc.c"
-#include "llex.c"
-#include "lmem.c"
-#include "lobject.c"
-#include "lopcodes.c"
-#include "lparser.c"
-#include "lstate.c"
-#include "lstring.c"
-#include "ltable.c"
-#include "ltm.c"
-#include "lundump.c"
-#include "lvm.c"
-#include "lzio.c"
-
-/* auxiliary library -- used by all */
-#include "lauxlib.c"
-
-/* standard library -- not used by luac */
-#ifndef MAKE_LUAC
-#include "lbaselib.c"
-#include "lbitlib.c"
-#include "ldblib.c"
-#include "liolib.c"
-#include "lmathlib.c"
-#include "loadlib.c"
-#include "loslib.c"
-#include "lstrlib.c"
-#include "ltablib.c"
-#include "linit.c"
-#endif
-
-/* lua */
-#ifdef MAKE_LUA
-#include "lua.c"
-#endif
-
-/* luac */
-#ifdef MAKE_LUAC
-#include "print.c"
-#include "luac.c"
-#endif
diff --git a/etc/strict.lua b/etc/strict.lua
deleted file mode 100644
index 5ce1aa85..00000000
--- a/etc/strict.lua
+++ /dev/null
@@ -1,42 +0,0 @@
---
--- strict.lua
--- checks uses of undeclared global variables
--- All global variables must be 'declared' through a regular assignment
--- (even assigning nil will do) in a main chunk before being used
--- anywhere or assigned to inside a function.
---
-
-require"debug"
-local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget
-
-local mt = getmetatable(_G)
-if mt == nil then
- mt = {}
- setmetatable(_G, mt)
-end
-
-mt.__declared = {}
-
-local function what ()
- local d = getinfo(3, "S")
- return d and d.what or "C"
-end
-
-mt.__newindex = function (t, n, v)
- if not mt.__declared[n] then
- local w = what()
- if w ~= "main" and w ~= "C" then
- error("assign to undeclared variable '"..n.."'", 2)
- end
- mt.__declared[n] = true
- end
- rawset(t, n, v)
-end
-
-mt.__index = function (t, n)
- if not mt.__declared[n] and what() ~= "C" then
- error("variable '"..n.."' is not declared", 2)
- end
- return rawget(t, n)
-end
-
diff --git a/src/Makefile b/src/Makefile
index 83185e34..84a21035 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -26,8 +26,8 @@ LUA_A= liblua.a
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
ltm.o lundump.o lvm.o lzio.o
-LIB_O= lauxlib.o lbaselib.o lbitlib.o ldblib.o liolib.o lmathlib.o loslib.o \
- lstrlib.o ltablib.o loadlib.o linit.o
+LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
+ lmathlib.o loslib.o lstrlib.o ltablib.o loadlib.o linit.o
LUA_T= lua
LUA_O= lua.o
@@ -39,6 +39,7 @@ ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
ALL_A= $(LUA_A)
+# Targets start here.
default: $(PLAT)
all: $(ALL_T)
@@ -64,21 +65,21 @@ depend:
@$(CC) $(CFLAGS) -MM l*.c print.c
echo:
- @echo "PLAT = $(PLAT)"
- @echo "CC = $(CC)"
- @echo "CFLAGS = $(CFLAGS)"
- @echo "AR = $(AR)"
- @echo "RANLIB = $(RANLIB)"
- @echo "RM = $(RM)"
- @echo "MYCFLAGS = $(MYCFLAGS)"
- @echo "MYLDFLAGS = $(MYLDFLAGS)"
- @echo "MYLIBS = $(MYLIBS)"
-
-# convenience targets for popular platforms
+ @echo "PLAT= $(PLAT)"
+ @echo "CC= $(CC)"
+ @echo "CFLAGS= $(CFLAGS)"
+ @echo "AR= $(AR)"
+ @echo "RANLIB= $(RANLIB)"
+ @echo "RM= $(RM)"
+ @echo "MYCFLAGS= $(MYCFLAGS)"
+ @echo "MYLDFLAGS= $(MYLDFLAGS)"
+ @echo "MYLIBS= $(MYLIBS)"
+
+# Convenience targets for popular platforms
ALL= all
none:
- @echo "Please choose a platform:"
+ @echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
@echo " $(PLATS)"
aix:
@@ -119,65 +120,66 @@ solaris:
# DO NOT DELETE
lapi.o: lapi.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \
- lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h \
- lvm.h
+ lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h \
+ lvm.h
lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
- lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
- lstring.h ltable.h
+ lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
+ lstring.h ltable.h
+lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h
lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h
ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
- ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \
- lfunc.h lstring.h lgc.h ltable.h lvm.h
+ ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \
+ lfunc.h lstring.h lgc.h ltable.h lvm.h
ldo.o: ldo.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \
- lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h \
- lstring.h ltable.h lundump.h lvm.h
+ lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h \
+ lstring.h ltable.h lundump.h lvm.h
ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
- lzio.h lmem.h lundump.h
+ lzio.h lmem.h lundump.h
lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h \
- lstate.h ltm.h lzio.h lmem.h lopcodes.h
+ lstate.h ltm.h lzio.h lmem.h
lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
+ lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \
- lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
+ lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h ldo.h lgc.h
+ ltm.h lzio.h lmem.h ldo.h lgc.h
loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \
- lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
+ lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
- lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \
- lfunc.h lstring.h lgc.h ltable.h
+ lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lfunc.h \
+ lstring.h lgc.h ltable.h
lstate.o: lstate.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
- ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h lstring.h \
- ltable.h
+ ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h lstring.h \
+ ltable.h
lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
- ltm.h lzio.h lstring.h lgc.h
+ ltm.h lzio.h lstring.h lgc.h
lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h
+ ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h
ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
- lmem.h lstring.h lgc.h ltable.h
+ lmem.h lstring.h lgc.h ltable.h
lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \
- lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
- lundump.h
+ lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
+ lundump.h
lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
- llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
+ llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
+ lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
- lzio.h
+ lzio.h
print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h lopcodes.h lundump.h
+ ltm.h lzio.h lmem.h lopcodes.h lundump.h
# (end of Makefile)
diff --git a/src/lapi.c b/src/lapi.c
index 8a0378f9..2d7c336a 100644
--- a/src/lapi.c
+++ b/src/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.129 2010/05/14 13:15:26 roberto Exp $
+** $Id: lapi.c,v 2.133 2010/07/25 15:18:19 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -55,7 +55,7 @@ static TValue *index2addr (lua_State *L, int idx) {
return &G(L)->l_registry;
else { /* upvalues */
idx = LUA_REGISTRYINDEX - idx;
- api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large");
+ api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
if (ttislcf(ci->func)) /* light C function? */
return cast(TValue *, luaO_nilobject); /* it has no upvalues */
else {
@@ -316,27 +316,34 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
}
-LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
+LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) {
TValue n;
const TValue *o = index2addr(L, idx);
- if (tonumber(o, &n))
+ if (tonumber(o, &n)) {
+ if (isnum) *isnum = 1;
return nvalue(o);
- else
+ }
+ else {
+ if (isnum) *isnum = 0;
return 0;
+ }
}
-LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
+LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
TValue n;
const TValue *o = index2addr(L, idx);
if (tonumber(o, &n)) {
lua_Integer res;
lua_Number num = nvalue(o);
lua_number2integer(res, num);
+ if (isnum) *isnum = 1;
return res;
}
- else
+ else {
+ if (isnum) *isnum = 0;
return 0;
+ }
}
@@ -507,7 +514,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
else {
Closure *cl;
api_checknelems(L, n);
- api_check(L, n <= UCHAR_MAX, "upvalue index too large");
+ api_check(L, n <= MAXUPVAL, "upvalue index too large");
luaC_checkGC(L);
cl = luaF_newCclosure(L, n);
cl->c.f = fn;
@@ -637,7 +644,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
}
-LUA_API void lua_getenv (lua_State *L, int idx) {
+LUA_API void lua_getuservalue (lua_State *L, int idx) {
StkId o;
lua_lock(L);
o = index2addr(L, idx);
@@ -689,7 +696,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
t = index2addr(L, idx);
api_check(L, ttistable(t), "table expected");
setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
- luaC_barriert(L, hvalue(t), L->top-1);
+ luaC_barrierback(L, gcvalue(t), L->top-1);
L->top -= 2;
lua_unlock(L);
}
@@ -702,7 +709,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
o = index2addr(L, idx);
api_check(L, ttistable(o), "table expected");
setobj2t(L, luaH_setint(L, hvalue(o), n), L->top-1);
- luaC_barriert(L, hvalue(o), L->top-1);
+ luaC_barrierback(L, gcvalue(o), L->top-1);
L->top--;
lua_unlock(L);
}
@@ -725,7 +732,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
case LUA_TTABLE: {
hvalue(obj)->metatable = mt;
if (mt)
- luaC_objbarriert(L, hvalue(obj), mt);
+ luaC_objbarrierback(L, gcvalue(obj), mt);
break;
}
case LUA_TUSERDATA: {
@@ -747,7 +754,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
}
-LUA_API void lua_setenv (lua_State *L, int idx) {
+LUA_API void lua_setuservalue (lua_State *L, int idx) {
StkId o;
lua_lock(L);
api_checknelems(L, 1);
diff --git a/src/lauxlib.c b/src/lauxlib.c
index 8ebc18fa..54f13da2 100644
--- a/src/lauxlib.c
+++ b/src/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.212 2010/05/18 17:21:24 roberto Exp $
+** $Id: lauxlib.c,v 1.219 2010/07/28 15:51:59 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -308,8 +308,9 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {
- lua_Number d = lua_tonumber(L, narg);
- if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
+ int isnum;
+ lua_Number d = lua_tonumberx(L, narg, &isnum);
+ if (!isnum)
tag_error(L, narg, LUA_TNUMBER);
return d;
}
@@ -321,8 +322,9 @@ LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
- lua_Integer d = lua_tointeger(L, narg);
- if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
+ int isnum;
+ lua_Integer d = lua_tointegerx(L, narg, &isnum);
+ if (!isnum)
tag_error(L, narg, LUA_TNUMBER);
return d;
}
@@ -476,26 +478,25 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
*/
typedef struct LoadF {
- int first;
- FILE *f;
- char buff[LUAL_BUFFERSIZE];
+ int n; /* number of pre-read characters */
+ FILE *f; /* file being read */
+ char buff[LUAL_BUFFERSIZE]; /* area for reading file */
} LoadF;
static const char *getF (lua_State *L, void *ud, size_t *size) {
LoadF *lf = (LoadF *)ud;
(void)L;
- if (lf->first != EOF) {
- *size = 1;
- lf->buff[0] = (char)lf->first;
- lf->first = EOF;
+ if (lf->n > 0) { /* are there pre-read characters to be read? */
+ *size = lf->n; /* return them (chars already in buffer) */
+ lf->n = 0; /* no more pre-read characters */
}
- else {
+ else { /* read a block from file */
/* 'fread' can return > 0 *and* set the EOF flag. If next call to
'getF' called 'fread', it might still wait for user input.
The next check avoids this problem. */
if (feof(lf->f)) return NULL;
- *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
+ *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
}
return lf->buff;
}
@@ -510,6 +511,23 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
}
+/*
+** reads the first character of file 'f' and skips its first line
+** if it starts with '#'. Returns true if it skipped the first line.
+** In any case, '*cp' has the first "valid" character of the file
+** (after the optional first-line comment).
+*/
+static int skipcomment (FILE *f, int *cp) {
+ int c = *cp = getc(f);
+ if (c == '#') { /* first line is a comment (Unix exec. file)? */
+ while ((c = getc(f)) != EOF && c != '\n') ; /* skip first line */
+ *cp = getc(f); /* skip end-of-line */
+ return 1; /* there was a comment */
+ }
+ else return 0; /* no comment */
+}
+
+
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
LoadF lf;
int status, readstatus;
@@ -524,16 +542,17 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
lf.f = fopen(filename, "r");
if (lf.f == NULL) return errfile(L, "open", fnameindex);
}
- c = getc(lf.f);
- if (c == '#') { /* Unix exec. file? */
- while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
- }
- else if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
+ lf.n = 0;
+ if (skipcomment(lf.f, &c)) /* read initial portion */
+ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
+ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
- c = getc(lf.f); /* re-read first character */
+ lf.n = 0;
+ skipcomment(lf.f, &c); /* re-read initial portion */
}
- lf.first = c; /* 'c' is the first character of the stream */
+ if (c != EOF)
+ lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
readstatus = ferror(lf.f);
if (filename) fclose(lf.f); /* close file (even in case of errors) */
@@ -607,9 +626,10 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
LUALIB_API int luaL_len (lua_State *L, int idx) {
int l;
+ int isnum;
lua_len(L, idx);
- l = lua_tointeger(L, -1);
- if (l == 0 && !lua_isnumber(L, -1))
+ l = lua_tointegerx(L, -1, &isnum);
+ if (!isnum)
luaL_error(L, "object length is not a number");
lua_pop(L, 1); /* remove object */
return l;
@@ -639,6 +659,43 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
}
+/*
+** {======================================================
+** Compatibility with 5.1 module functions
+** =======================================================
+*/
+#if defined(LUA_COMPAT_MODULE)
+
+static const char *luaL_findtablex (lua_State *L, int idx,
+ const char *fname, int szhint) {
+ const char *e;
+ if (idx) lua_pushvalue(L, idx);
+ do {
+ e = strchr(fname, '.');
+ if (e == NULL) e = fname + strlen(fname);
+ lua_pushlstring(L, fname, e - fname);
+ lua_rawget(L, -2);
+ if (lua_isnil(L, -1)) { /* no such field? */
+ lua_pop(L, 1); /* remove this nil */
+ lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
+ lua_pushlstring(L, fname, e - fname);
+ lua_pushvalue(L, -2);
+ lua_settable(L, -4); /* set new table into field */
+ }
+ else if (!lua_istable(L, -1)) { /* field has a non-table value? */
+ lua_pop(L, 2); /* remove table and value */
+ return fname; /* return problematic part of the name */
+ }
+ lua_remove(L, -2); /* remove previous table */
+ fname = e + 1;
+ } while (*e == '.');
+ return NULL;
+}
+
+
+/*
+** Count number of elements in a luaL_Reg list.
+*/
static int libsize (const luaL_Reg *l) {
int size = 0;
for (; l && l->name; l++) size++;
@@ -646,37 +703,101 @@ static int libsize (const luaL_Reg *l) {
}
+/*
+** Find or create a module table with a given name. The function
+** first looks at the _LOADED table and, if that fails, try a
+** global variable with that name. In any case, leaves on the stack
+** the module table.
+*/
+LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
+ int sizehint) {
+ luaL_findtablex(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
+ lua_getfield(L, -1, modname); /* get _LOADED[modname] */
+ if (!lua_istable(L, -1)) { /* not found? */
+ lua_pop(L, 1); /* remove previous result */
+ /* try global variable (and create one if it does not exist) */
+ lua_pushglobaltable(L);
+ if (luaL_findtablex(L, 0, modname, sizehint) != NULL)
+ luaL_error(L, "name conflict for module " LUA_QS, modname);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
+ }
+ lua_remove(L, -2); /* remove _LOADED table */
+}
+
+
LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
const luaL_Reg *l, int nup) {
luaL_checkversion(L);
if (libname) {
- /* check whether lib already exists */
- 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 */
- /* try global variable (and create one if it does not exist) */
- lua_pushglobaltable(L);
- if (luaL_findtable(L, 0, libname, libsize(l)) != NULL)
- luaL_error(L, "name conflict for module " LUA_QS, libname);
- lua_pushvalue(L, -1);
- lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
- }
- lua_remove(L, -2); /* remove _LOADED table */
+ luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
}
+ luaL_setfuncs(L, l, nup);
+}
+
+#endif
+/* }====================================================== */
+
+/*
+** set functions from list 'l' into table at top - 'nup'; each
+** function gets the 'nup' elements at the top as upvalues.
+** Returns with only the table at the stack.
+*/
+LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup, "too many upvalues");
for (; l && l->name; l++) { /* fill the table with given functions */
int i;
for (i = 0; i < nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -nup);
- lua_pushcclosure(L, l->func, nup);
+ lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
lua_setfield(L, -(nup + 2), l->name);
}
lua_pop(L, nup); /* remove upvalues */
}
+/*
+** ensure that stack[idx][fname] has a table and push that table
+** into the stack
+*/
+LUALIB_API void luaL_findtable (lua_State *L, int idx, const char *fname) {
+ lua_getfield(L, idx, fname);
+ if (lua_istable(L, -1)) return; /* table already there */
+ else {
+ idx = lua_absindex(L, idx);
+ lua_pop(L, 1); /* remove previous result */
+ lua_newtable(L);
+ lua_pushvalue(L, -1); /* copy to be left at top */
+ lua_setfield(L, idx, fname); /* assign new table to field */
+ }
+}
+
+
+/*
+** stripped-down 'require'. Calls 'openf' to open a module,
+** registers the result in 'package.loaded' table and, if 'glb'
+** is true, also registers the result in the global table.
+** Leaves resulting module on the top.
+*/
+LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
+ lua_CFunction openf, int glb) {
+ lua_pushcfunction(L, openf);
+ lua_pushstring(L, modname); /* argument to open function */
+ lua_call(L, 1, 1); /* open module */
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_pushvalue(L, -2); /* make copy of module (call result) */
+ lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
+ lua_pop(L, 1); /* remove _LOADED table */
+ if (glb) {
+ lua_pushglobaltable(L);
+ lua_pushvalue(L, -2); /* copy of 'mod' */
+ lua_setfield(L, -2, modname); /* _G[modname] = module */
+ lua_pop(L, 1); /* remove _G table */
+ }
+}
+
+
LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
const char *r) {
const char *wild;
@@ -694,33 +815,6 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
}
-LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
- const char *fname, int szhint) {
- const char *e;
- if (idx) lua_pushvalue(L, idx);
- do {
- e = strchr(fname, '.');
- if (e == NULL) e = fname + strlen(fname);
- lua_pushlstring(L, fname, e - fname);
- lua_rawget(L, -2);
- if (lua_isnil(L, -1)) { /* no such field? */
- lua_pop(L, 1); /* remove this nil */
- lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
- lua_pushlstring(L, fname, e - fname);
- lua_pushvalue(L, -2);
- lua_settable(L, -4); /* set new table into field */
- }
- else if (!lua_istable(L, -1)) { /* field has a non-table value? */
- lua_pop(L, 2); /* remove table and value */
- return fname; /* return problematic part of the name */
- }
- lua_remove(L, -2); /* remove previous table */
- fname = e + 1;
- } while (*e == '.');
- return NULL;
-}
-
-
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud;
(void)osize;
diff --git a/src/lauxlib.h b/src/lauxlib.h
index ae2e2c75..b2034673 100644
--- a/src/lauxlib.h
+++ b/src/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.105 2010/05/04 17:21:08 roberto Exp $
+** $Id: lauxlib.h,v 1.108 2010/07/02 11:38:13 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -29,8 +29,6 @@ typedef struct luaL_Reg {
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)
-LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
- const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
@@ -76,12 +74,15 @@ LUALIB_API int (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
-LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
- const char *fname, int szhint);
+LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
+
+LUALIB_API void (luaL_findtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
+LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
+ lua_CFunction openf, int glb);
/*
** ===============================================================
@@ -89,6 +90,12 @@ LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
** ===============================================================
*/
+
+#define luaL_newlibtable(L,l) \
+ lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
+
+#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
+
#define luaL_argcheck(L, cond,numarg,extramsg) \
((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
@@ -148,6 +155,12 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
/* }====================================================== */
+LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
+ int sizehint);
+LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
+ const luaL_Reg *l, int nup);
+
+
/* compatibility with ref system */
/* pre-defined references */
diff --git a/src/lbaselib.c b/src/lbaselib.c
index 946ecea5..1e13a183 100644
--- a/src/lbaselib.c
+++ b/src/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.243 2010/04/19 17:02:02 roberto Exp $
+** $Id: lbaselib.c,v 1.246 2010/07/02 11:38:13 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -210,15 +210,13 @@ static int luaB_pairs (lua_State *L) {
}
-#if defined(LUA_COMPAT_IPAIRS)
-
static int ipairsaux (lua_State *L) {
int i = luaL_checkint(L, 2);
luaL_checktype(L, 1, LUA_TTABLE);
i++; /* next value */
lua_pushinteger(L, i);
lua_rawgeti(L, 1, i);
- return (lua_isnil(L, -1) && i > luaL_len(L, 1)) ? 0 : 2;
+ return (lua_isnil(L, -1)) ? 1 : 2;
}
@@ -226,14 +224,6 @@ static int luaB_ipairs (lua_State *L) {
return pairsmeta(L, "__ipairs", 1, ipairsaux);
}
-#else
-
-static int luaB_ipairs (lua_State *L) {
- return luaL_error(L, "'ipairs' deprecated");
-}
-
-#endif
-
static int load_aux (lua_State *L, int status) {
if (status == LUA_OK)
@@ -500,150 +490,13 @@ static const luaL_Reg base_funcs[] = {
};
-/*
-** {======================================================
-** Coroutine library
-** =======================================================
-*/
-
-static int auxresume (lua_State *L, lua_State *co, int narg) {
- int status;
- if (!lua_checkstack(co, narg)) {
- lua_pushliteral(L, "too many arguments to resume");
- return -1; /* error flag */
- }
- if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
- lua_pushliteral(L, "cannot resume dead coroutine");
- return -1; /* error flag */
- }
- lua_xmove(L, co, narg);
- status = lua_resume(co, narg);
- if (status == LUA_OK || status == LUA_YIELD) {
- int nres = lua_gettop(co);
- if (!lua_checkstack(L, nres + 1)) {
- lua_pop(co, nres); /* remove results anyway */
- lua_pushliteral(L, "too many results to resume");
- return -1; /* error flag */
- }
- lua_xmove(co, L, nres); /* move yielded values */
- return nres;
- }
- else {
- lua_xmove(co, L, 1); /* move error message */
- return -1; /* error flag */
- }
-}
-
-
-static int luaB_coresume (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- int r;
- luaL_argcheck(L, co, 1, "coroutine expected");
- r = auxresume(L, co, lua_gettop(L) - 1);
- if (r < 0) {
- lua_pushboolean(L, 0);
- lua_insert(L, -2);
- return 2; /* return false + error message */
- }
- else {
- lua_pushboolean(L, 1);
- lua_insert(L, -(r + 1));
- return r + 1; /* return true + `resume' returns */
- }
-}
-
-
-static int luaB_auxwrap (lua_State *L) {
- lua_State *co = lua_tothread(L, lua_upvalueindex(1));
- int r = auxresume(L, co, lua_gettop(L));
- if (r < 0) {
- if (lua_isstring(L, -1)) { /* error object is a string? */
- luaL_where(L, 1); /* add extra info */
- lua_insert(L, -2);
- lua_concat(L, 2);
- }
- lua_error(L); /* propagate error */
- }
- return r;
-}
-
-
-static int luaB_cocreate (lua_State *L) {
- lua_State *NL = lua_newthread(L);
- luaL_checktype(L, 1, LUA_TFUNCTION);
- lua_pushvalue(L, 1); /* move function to top */
- lua_xmove(L, NL, 1); /* move function from L to NL */
- return 1;
-}
-
-
-static int luaB_cowrap (lua_State *L) {
- luaB_cocreate(L);
- lua_pushcclosure(L, luaB_auxwrap, 1);
- return 1;
-}
-
-
-static int luaB_yield (lua_State *L) {
- return lua_yield(L, lua_gettop(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 LUA_OK: {
- 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 occurred */
- lua_pushliteral(L, "dead");
- break;
- }
- }
- return 1;
-}
-
-
-static int luaB_corunning (lua_State *L) {
- int ismain = lua_pushthread(L);
- lua_pushboolean(L, ismain);
- return 2;
-}
-
-
-static const luaL_Reg co_funcs[] = {
- {"create", luaB_cocreate},
- {"resume", luaB_coresume},
- {"running", luaB_corunning},
- {"status", luaB_costatus},
- {"wrap", luaB_cowrap},
- {"yield", luaB_yield},
- {NULL, NULL}
-};
-
-/* }====================================================== */
-
-
-static void base_open (lua_State *L) {
+LUAMOD_API int luaopen_base (lua_State *L) {
/* set global _G */
lua_pushglobaltable(L);
lua_pushglobaltable(L);
lua_setfield(L, -2, "_G");
/* open lib into global table */
- luaL_register(L, "_G", base_funcs);
+ luaL_setfuncs(L, base_funcs, 0);
lua_pushliteral(L, LUA_VERSION);
lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
/* `newproxy' needs a weaktable as upvalue */
@@ -654,12 +507,6 @@ static void base_open (lua_State *L) {
lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
lua_pushcclosure(L, luaB_newproxy, 1);
lua_setfield(L, -2, "newproxy"); /* set global `newproxy' */
-}
-
-
-LUAMOD_API int luaopen_base (lua_State *L) {
- base_open(L);
- luaL_register(L, LUA_COLIBNAME, co_funcs);
- return 2;
+ return 1;
}
diff --git a/src/lbitlib.c b/src/lbitlib.c
index b367d0c6..1b32653d 100644
--- a/src/lbitlib.c
+++ b/src/lbitlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbitlib.c,v 1.4 2010/02/11 15:55:29 roberto Exp $
+** $Id: lbitlib.c,v 1.6 2010/07/02 12:01:53 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/
@@ -23,8 +23,9 @@ typedef unsigned LUA_INT32 b_uint;
static b_uint getuintarg (lua_State *L, int arg) {
b_uint r;
- lua_Number x = lua_tonumber(L, arg);
- if (x == 0) luaL_checktype(L, arg, LUA_TNUMBER);
+ int isnum;
+ lua_Number x = lua_tonumberx(L, arg, &isnum);
+ if (!isnum) luaL_typeerror(L, arg, "number");
lua_number2uint(r, x);
return r;
}
@@ -141,6 +142,6 @@ static const luaL_Reg bitlib[] = {
LUAMOD_API int luaopen_bit (lua_State *L) {
- luaL_register(L, LUA_BITLIBNAME, bitlib);
+ luaL_newlib(L, bitlib);
return 1;
}
diff --git a/src/lcode.c b/src/lcode.c
index d060b5f0..ea3217fa 100644
--- a/src/lcode.c
+++ b/src/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 2.46 2010/04/17 12:46:32 roberto Exp $
+** $Id: lcode.c,v 2.49 2010/07/07 16:27:29 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -266,7 +266,7 @@ static void freereg (FuncState *fs, int reg) {
static void freeexp (FuncState *fs, expdesc *e) {
if (e->k == VNONRELOC)
- freereg(fs, e->u.s.info);
+ freereg(fs, e->u.info);
}
@@ -352,7 +352,7 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
void luaK_setoneret (FuncState *fs, expdesc *e) {
if (e->k == VCALL) { /* expression is an open function call? */
e->k = VNONRELOC;
- e->u.s.info = GETARG_A(getcode(fs, e));
+ e->u.info = GETARG_A(getcode(fs, e));
}
else if (e->k == VVARARG) {
SETARG_B(getcode(fs, e), 2);
@@ -368,20 +368,18 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
break;
}
case VUPVAL: {
- e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
+ e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
e->k = VRELOCABLE;
break;
}
case VINDEXED: {
- freereg(fs, e->u.s.aux);
- freereg(fs, e->u.s.info);
- e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
- e->k = VRELOCABLE;
- break;
- }
- case VINDEXEDUP: {
- freereg(fs, e->u.s.aux);
- e->u.s.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.s.info, e->u.s.aux);
+ OpCode op = OP_GETTABUP; /* assume 't' is in an upvalue */
+ freereg(fs, e->u.ind.idx);
+ if (e->u.ind.vt == VLOCAL) { /* 't' is in a register? */
+ freereg(fs, e->u.ind.t);
+ op = OP_GETTABLE;
+ }
+ e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);
e->k = VRELOCABLE;
break;
}
@@ -413,7 +411,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
break;
}
case VK: {
- luaK_codek(fs, reg, e->u.s.info);
+ luaK_codek(fs, reg, e->u.info);
break;
}
case VKNUM: {
@@ -426,8 +424,8 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
break;
}
case VNONRELOC: {
- if (reg != e->u.s.info)
- luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);
+ if (reg != e->u.info)
+ luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
break;
}
default: {
@@ -435,7 +433,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
return; /* nothing to do... */
}
}
- e->u.s.info = reg;
+ e->u.info = reg;
e->k = VNONRELOC;
}
@@ -451,7 +449,7 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) {
static void exp2reg (FuncState *fs, expdesc *e, int reg) {
discharge2reg(fs, e, reg);
if (e->k == VJMP)
- luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */
+ luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */
if (hasjumps(e)) {
int final; /* position after whole expression */
int p_f = NO_JUMP; /* position of an eventual LOAD false */
@@ -467,7 +465,7 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) {
patchlistaux(fs, e->t, final, reg, p_t);
}
e->f = e->t = NO_JUMP;
- e->u.s.info = reg;
+ e->u.info = reg;
e->k = VNONRELOC;
}
@@ -483,14 +481,14 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
luaK_dischargevars(fs, e);
if (e->k == VNONRELOC) {
- if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */
- if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */
- exp2reg(fs, e, e->u.s.info); /* put value on it */
- return e->u.s.info;
+ if (!hasjumps(e)) return e->u.info; /* exp is already in a register */
+ if (e->u.info >= fs->nactvar) { /* reg. is not a local? */
+ exp2reg(fs, e, e->u.info); /* put value on it */
+ return e->u.info;
}
}
luaK_exp2nextreg(fs, e); /* default */
- return e->u.s.info;
+ return e->u.info;
}
@@ -514,21 +512,21 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) {
case VTRUE:
case VFALSE:
case VNIL: {
- if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
- e->u.s.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
+ if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */
+ e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
e->k = VK;
- return RKASK(e->u.s.info);
+ return RKASK(e->u.info);
}
else break;
}
case VKNUM: {
- e->u.s.info = luaK_numberK(fs, e->u.nval);
+ e->u.info = luaK_numberK(fs, e->u.nval);
e->k = VK;
/* go through */
}
case VK: {
- if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */
- return RKASK(e->u.s.info);
+ if (e->u.info <= MAXINDEXRK) /* constant fits in argC? */
+ return RKASK(e->u.info);
else break;
}
default: break;
@@ -542,22 +540,18 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
switch (var->k) {
case VLOCAL: {
freeexp(fs, ex);
- exp2reg(fs, ex, var->u.s.info);
+ exp2reg(fs, ex, var->u.info);
return;
}
case VUPVAL: {
int e = luaK_exp2anyreg(fs, ex);
- luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
+ luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
break;
}
case VINDEXED: {
+ OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
int e = luaK_exp2RK(fs, ex);
- luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
- break;
- }
- case VINDEXEDUP: {
- int e = luaK_exp2RK(fs, ex);
- luaK_codeABC(fs, OP_SETTABUP, var->u.s.info, var->u.s.aux, e);
+ luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
break;
}
default: {
@@ -574,16 +568,16 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
luaK_exp2anyreg(fs, e);
freeexp(fs, e);
func = fs->freereg;
- luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
+ luaK_codeABC(fs, OP_SELF, func, e->u.info, luaK_exp2RK(fs, key));
freeexp(fs, key);
luaK_reserveregs(fs, 2);
- e->u.s.info = func;
+ e->u.info = func;
e->k = VNONRELOC;
}
static void invertjump (FuncState *fs, expdesc *e) {
- Instruction *pc = getjumpcontrol(fs, e->u.s.info);
+ Instruction *pc = getjumpcontrol(fs, e->u.info);
lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
GET_OPCODE(*pc) != OP_TEST);
SETARG_A(*pc, !(GETARG_A(*pc)));
@@ -601,7 +595,7 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) {
}
discharge2anyreg(fs, e);
freeexp(fs, e);
- return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);
+ return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
}
@@ -615,7 +609,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
}
case VJMP: {
invertjump(fs, e);
- pc = e->u.s.info;
+ pc = e->u.info;
break;
}
case VFALSE: {
@@ -645,7 +639,7 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) {
break;
}
case VJMP: {
- pc = e->u.s.info;
+ pc = e->u.info;
break;
}
case VTRUE: {
@@ -685,7 +679,7 @@ static void codenot (FuncState *fs, expdesc *e) {
case VNONRELOC: {
discharge2anyreg(fs, e);
freeexp(fs, e);
- e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);
+ e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
e->k = VRELOCABLE;
break;
}
@@ -703,8 +697,11 @@ static void codenot (FuncState *fs, expdesc *e) {
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
lua_assert(!hasjumps(t));
- t->u.s.aux = luaK_exp2RK(fs, k);
- t->k = (t->k == VUPVAL) ? VINDEXEDUP : VINDEXED;
+ t->u.ind.t = t->u.info;
+ t->u.ind.idx = luaK_exp2RK(fs, k);
+ t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL
+ : check_exp(vkisinreg(t->k), VLOCAL);
+ t->k = VINDEXED;
}
@@ -734,7 +731,7 @@ static void codearith (FuncState *fs, OpCode op,
freeexp(fs, e2);
freeexp(fs, e1);
}
- e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
+ e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);
e1->k = VRELOCABLE;
luaK_fixline(fs, line);
}
@@ -752,7 +749,7 @@ static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
cond = 1;
}
- e1->u.s.info = condjump(fs, op, cond, o1, o2);
+ e1->u.info = condjump(fs, op, cond, o1, o2);
e1->k = VJMP;
}
@@ -828,10 +825,10 @@ void luaK_posfix (FuncState *fs, BinOpr op,
case OPR_CONCAT: {
luaK_exp2val(fs, e2);
if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
- lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
+ lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);
freeexp(fs, e1);
- SETARG_B(getcode(fs, e2), e1->u.s.info);
- e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;
+ SETARG_B(getcode(fs, e2), e1->u.info);
+ e1->k = VRELOCABLE; e1->u.info = e2->u.info;
}
else {
luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
diff --git a/src/lcode.h b/src/lcode.h
index d7f7dd62..86d21389 100644
--- a/src/lcode.h
+++ b/src/lcode.h
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.h,v 1.54 2010/04/17 12:46:32 roberto Exp $
+** $Id: lcode.h,v 1.55 2010/07/02 20:42:40 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -36,7 +36,7 @@ typedef enum BinOpr {
typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
-#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info])
+#define getcode(fs,e) ((fs)->f->code[(e)->u.info])
#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
diff --git a/src/lcorolib.c b/src/lcorolib.c
new file mode 100644
index 00000000..981ca381
--- /dev/null
+++ b/src/lcorolib.c
@@ -0,0 +1,154 @@
+/*
+** $Id: lcorolib.c,v 1.2 2010/07/02 11:38:13 roberto Exp $
+** Coroutine Library
+** See Copyright Notice in lua.h
+*/
+
+
+#include <stdlib.h>
+
+
+#define lcorolib_c
+#define LUA_LIB
+
+#include "lua.h"
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+
+static int auxresume (lua_State *L, lua_State *co, int narg) {
+ int status;
+ if (!lua_checkstack(co, narg)) {
+ lua_pushliteral(L, "too many arguments to resume");
+ return -1; /* error flag */
+ }
+ if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
+ lua_pushliteral(L, "cannot resume dead coroutine");
+ return -1; /* error flag */
+ }
+ lua_xmove(L, co, narg);
+ status = lua_resume(co, narg);
+ if (status == LUA_OK || status == LUA_YIELD) {
+ int nres = lua_gettop(co);
+ if (!lua_checkstack(L, nres + 1)) {
+ lua_pop(co, nres); /* remove results anyway */
+ lua_pushliteral(L, "too many results to resume");
+ return -1; /* error flag */
+ }
+ lua_xmove(co, L, nres); /* move yielded values */
+ return nres;
+ }
+ else {
+ lua_xmove(co, L, 1); /* move error message */
+ return -1; /* error flag */
+ }
+}
+
+
+static int luaB_coresume (lua_State *L) {
+ lua_State *co = lua_tothread(L, 1);
+ int r;
+ luaL_argcheck(L, co, 1, "coroutine expected");
+ r = auxresume(L, co, lua_gettop(L) - 1);
+ if (r < 0) {
+ lua_pushboolean(L, 0);
+ lua_insert(L, -2);
+ return 2; /* return false + error message */
+ }
+ else {
+ lua_pushboolean(L, 1);
+ lua_insert(L, -(r + 1));
+ return r + 1; /* return true + `resume' returns */
+ }
+}
+
+
+static int luaB_auxwrap (lua_State *L) {
+ lua_State *co = lua_tothread(L, lua_upvalueindex(1));
+ int r = auxresume(L, co, lua_gettop(L));
+ if (r < 0) {
+ if (lua_isstring(L, -1)) { /* error object is a string? */
+ luaL_where(L, 1); /* add extra info */
+ lua_insert(L, -2);
+ lua_concat(L, 2);
+ }
+ lua_error(L); /* propagate error */
+ }
+ return r;
+}
+
+
+static int luaB_cocreate (lua_State *L) {
+ lua_State *NL = lua_newthread(L);
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+ lua_pushvalue(L, 1); /* move function to top */
+ lua_xmove(L, NL, 1); /* move function from L to NL */
+ return 1;
+}
+
+
+static int luaB_cowrap (lua_State *L) {
+ luaB_cocreate(L);
+ lua_pushcclosure(L, luaB_auxwrap, 1);
+ return 1;
+}
+
+
+static int luaB_yield (lua_State *L) {
+ return lua_yield(L, lua_gettop(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 LUA_OK: {
+ 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 occurred */
+ lua_pushliteral(L, "dead");
+ break;
+ }
+ }
+ return 1;
+}
+
+
+static int luaB_corunning (lua_State *L) {
+ int ismain = lua_pushthread(L);
+ lua_pushboolean(L, ismain);
+ return 2;
+}
+
+
+static const luaL_Reg co_funcs[] = {
+ {"create", luaB_cocreate},
+ {"resume", luaB_coresume},
+ {"running", luaB_corunning},
+ {"status", luaB_costatus},
+ {"wrap", luaB_cowrap},
+ {"yield", luaB_yield},
+ {NULL, NULL}
+};
+
+
+
+LUAMOD_API int luaopen_coroutine (lua_State *L) {
+ luaL_newlib(L, co_funcs);
+ return 1;
+}
+
diff --git a/src/ldblib.c b/src/ldblib.c
index 28e671df..9ae6f86b 100644
--- a/src/ldblib.c
+++ b/src/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.121 2010/03/26 20:58:11 roberto Exp $
+** $Id: ldblib.c,v 1.124 2010/07/25 15:18:19 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -44,19 +44,19 @@ static int db_setmetatable (lua_State *L) {
}
-static int db_getenv (lua_State *L) {
+static int db_getuservalue (lua_State *L) {
luaL_checktype(L, 1, LUA_TUSERDATA);
- lua_getenv(L, 1);
+ lua_getuservalue(L, 1);
return 1;
}
-static int db_setenv (lua_State *L) {
+static int db_setuservalue (lua_State *L) {
luaL_checktype(L, 1, LUA_TUSERDATA);
if (!lua_isnoneornil(L, 2))
luaL_checktype(L, 2, LUA_TTABLE);
lua_settop(L, 2);
- lua_setenv(L, 1);
+ lua_setuservalue(L, 1);
return 1;
}
@@ -157,19 +157,27 @@ static int db_getlocal (lua_State *L) {
lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
const char *name;
- if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
- return luaL_argerror(L, arg+1, "level out of range");
- name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2));
- if (name) {
- lua_xmove(L1, L, 1);
- lua_pushstring(L, name);
- lua_pushvalue(L, -2);
- return 2;
- }
- else {
- lua_pushnil(L);
+ int nvar = luaL_checkint(L, arg+2); /* local-variable index */
+ if (lua_isfunction(L, arg + 1)) { /* function argument? */
+ lua_pushvalue(L, arg + 1); /* push function */
+ lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */
return 1;
}
+ else { /* stack-level argument */
+ if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
+ return luaL_argerror(L, arg+1, "level out of range");
+ name = lua_getlocal(L1, &ar, nvar);
+ if (name) {
+ lua_xmove(L1, L, 1); /* push local value */
+ lua_pushstring(L, name); /* push name */
+ lua_pushvalue(L, -2); /* re-order */
+ return 2;
+ }
+ else {
+ lua_pushnil(L); /* no name (nor value) */
+ return 1;
+ }
+ }
}
@@ -367,7 +375,7 @@ static int db_traceback (lua_State *L) {
static const luaL_Reg dblib[] = {
{"debug", db_debug},
- {"getenv", db_getenv},
+ {"getuservalue", db_getuservalue},
{"gethook", db_gethook},
{"getinfo", db_getinfo},
{"getlocal", db_getlocal},
@@ -376,7 +384,7 @@ static const luaL_Reg dblib[] = {
{"getupvalue", db_getupvalue},
{"upvaluejoin", db_upvaluejoin},
{"upvalueid", db_upvalueid},
- {"setenv", db_setenv},
+ {"setuservalue", db_setuservalue},
{"sethook", db_sethook},
{"setlocal", db_setlocal},
{"setmetatable", db_setmetatable},
@@ -387,7 +395,7 @@ static const luaL_Reg dblib[] = {
LUAMOD_API int luaopen_debug (lua_State *L) {
- luaL_register(L, LUA_DBLIBNAME, dblib);
+ luaL_newlib(L, dblib);
return 1;
}
diff --git a/src/ldebug.c b/src/ldebug.c
index dcc8ca99..5a04d5a3 100644
--- a/src/ldebug.c
+++ b/src/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.70 2010/04/13 20:48:12 roberto Exp $
+** $Id: ldebug.c,v 2.72 2010/06/21 16:30:12 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -119,12 +119,21 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
- StkId pos;
- const char *name = findlocal(L, ar->i_ci, n, &pos);
+ const char *name;
lua_lock(L);
- if (name) {
- setobj2s(L, L->top, pos);
- api_incr_top(L);
+ if (ar == NULL) { /* information about non-active function? */
+ if (!isLfunction(L->top - 1)) /* not a Lua function? */
+ name = NULL;
+ else /* consider live variables at function start (parameters) */
+ name = luaF_getlocalname(clvalue(L->top - 1)->l.p, n, 0);
+ }
+ else { /* active function; get information through 'ar' */
+ StkId pos;
+ name = findlocal(L, ar->i_ci, n, &pos);
+ if (name) {
+ setobj2s(L, L->top, pos);
+ api_incr_top(L);
+ }
}
lua_unlock(L);
return name;
@@ -264,7 +273,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
static void kname (Proto *p, int c, int reg, const char *what,
const char **name) {
- if (c == reg && *what == 'c')
+ if (c == reg && what && *what == 'c')
return; /* index is a constant; name already correct */
else if (ISK(c) && ttisstring(&p->k[INDEXK(c)]))
*name = svalue(&p->k[INDEXK(c)]);
diff --git a/src/ldo.c b/src/ldo.c
index 5b0e766e..834a0543 100644
--- a/src/ldo.c
+++ b/src/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 2.87 2010/05/05 18:49:56 roberto Exp $
+** $Id: ldo.c,v 2.88 2010/06/04 13:06:15 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -630,8 +630,7 @@ static void f_parser (lua_State *L, void *ud) {
: luaY_parser(L, p->z, &p->buff, &p->varl, p->name);
setptvalue2s(L, L->top, tf);
incr_top(L);
- cl = luaF_newLclosure(L, tf->sizeupvalues);
- cl->l.p = tf;
+ cl = luaF_newLclosure(L, tf);
setclvalue(L, L->top - 1, cl);
for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */
cl->l.upvals[i] = luaF_newupval(L);
diff --git a/src/lfunc.c b/src/lfunc.c
index e95dad01..1a1a8bb8 100644
--- a/src/lfunc.c
+++ b/src/lfunc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lfunc.c,v 2.24 2010/05/10 18:23:45 roberto Exp $
+** $Id: lfunc.c,v 2.27 2010/06/30 14:11:17 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -16,7 +16,6 @@
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
-#include "lopcodes.h"
#include "lstate.h"
@@ -29,9 +28,11 @@ Closure *luaF_newCclosure (lua_State *L, int n) {
}
-Closure *luaF_newLclosure (lua_State *L, int n) {
+Closure *luaF_newLclosure (lua_State *L, Proto *p) {
+ int n = p->sizeupvalues;
Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeLclosure(n), NULL, 0)->cl;
c->l.isC = 0;
+ c->l.p = p;
c->l.nupvalues = cast_byte(n);
while (n--) c->l.upvals[n] = NULL;
return c;
@@ -56,7 +57,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
lua_assert(p->v != &p->u.value);
if (p->v == level) { /* found a corresponding upvalue? */
if (isdead(g, o)) /* is it dead? */
- changewhite(o); /* ressurrect it */
+ changewhite(o); /* resurrect it */
return p;
}
resetoldbit(o); /* may create a newer upval after this one */
@@ -116,6 +117,7 @@ Proto *luaF_newproto (lua_State *L) {
f->p = NULL;
f->sizep = 0;
f->code = NULL;
+ f->cache = NULL;
f->sizecode = 0;
f->lineinfo = NULL;
f->sizelineinfo = 0;
diff --git a/src/lfunc.h b/src/lfunc.h
index d11182b0..da189231 100644
--- a/src/lfunc.h
+++ b/src/lfunc.h
@@ -1,5 +1,5 @@
/*
-** $Id: lfunc.h,v 2.5 2010/03/26 20:58:11 roberto Exp $
+** $Id: lfunc.h,v 2.6 2010/06/04 13:06:15 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -20,7 +20,7 @@
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems);
-LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems);
+LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, Proto *p);
LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
LUAI_FUNC void luaF_close (lua_State *L, StkId level);
diff --git a/src/lgc.c b/src/lgc.c
index 276edacd..fcaca1b4 100644
--- a/src/lgc.c
+++ b/src/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 2.96 2010/05/17 20:39:31 roberto Exp $
+** $Id: lgc.c,v 2.101 2010/06/30 14:11:17 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -27,7 +27,7 @@
/* how much to allocate before next GC step */
#define GCSTEPSIZE 1024
-/* maximum numer of elements to sweep in each single step */
+/* maximum number of elements to sweep in each single step */
#define GCSWEEPMAX 40
/* cost of sweeping one element */
@@ -127,7 +127,7 @@ static int iscleared (const TValue *o, int iskey) {
** barrier that moves collector forward, that is, mark the white object
** being pointed by a black object.
*/
-void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
+void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
global_State *g = G(L);
lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
lua_assert(isgenerational(g) || g->gcstate != GCSpause);
@@ -143,19 +143,42 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
/*
** barrier that moves collector backward, that is, mark the black object
-** pointing to a white object as gray again.
+** pointing to a white object as gray again. (Current implementation
+** only works for tables; access to 'gclist' is not uniform across
+** different types.)
*/
-void luaC_barrierback (lua_State *L, Table *t) {
+void luaC_barrierback_ (lua_State *L, GCObject *o) {
global_State *g = G(L);
- GCObject *o = obj2gco(t);
lua_assert(isblack(o) && !isdead(g, o));
- black2gray(o); /* make table gray (again) */
- t->gclist = g->grayagain;
+ black2gray(o); /* make object gray (again) */
+ gco2t(o)->gclist = g->grayagain;
g->grayagain = o;
}
/*
+** barrier for prototypes. When creating first closure (cache is
+** NULL), use a forward barrier; this may be the only closure of the
+** prototype (if it is a "regular" function, with a single instance)
+** and the prototype may be big, so it is better to avoid traversing
+** it again. Otherwise, use a backward barrier, to avoid marking all
+** possible instances.
+*/
+LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c) {
+ global_State *g = G(L);
+ lua_assert(isblack(obj2gco(p)));
+ if (p->cache == NULL) { /* first time? */
+ luaC_objbarrier(L, p, c);
+ }
+ else { /* use a backward barrier */
+ black2gray(obj2gco(p)); /* make prototype gray (again) */
+ p->gclist = g->grayagain;
+ g->grayagain = obj2gco(p);
+ }
+}
+
+
+/*
** check color (and invariants) for an upvalue that was closed,
** i.e., moved into the 'allgc' list
*/
@@ -348,7 +371,7 @@ static int traverseephemeron (global_State *g, Table *h) {
if (ttisnil(gval(n))) /* entry is empty? */
removeentry(n); /* remove it */
else if (valiswhite(gval(n))) { /* value not marked yet? */
- if (iscleared(key2tval(n), 1)) /* key is not marked (yet)? */
+ if (iscleared(gkey(n), 1)) /* key is not marked (yet)? */
hasclears = 1; /* may have to propagate mark from key to value */
else { /* key is marked, so mark value */
marked = 1; /* value was not marked */
@@ -411,6 +434,8 @@ static int traversetable (global_State *g, Table *h) {
static int traverseproto (global_State *g, Proto *f) {
int i;
+ if (f->cache && iswhite(obj2gco(f->cache)))
+ f->cache = NULL; /* allow cache to be collected */
stringmark(f->source);
for (i = 0; i < f->sizek; i++) /* mark literals */
markvalue(g, &f->k[i]);
@@ -533,6 +558,7 @@ static void convergeephemerons (global_State *g) {
** =======================================================
*/
+
/*
** clear collected entries from all weaktables in list 'l'
*/
@@ -548,7 +574,7 @@ static void cleartable (GCObject *l) {
}
for (n = gnode(h, 0); n < limit; n++) {
if (!ttisnil(gval(n)) && /* non-empty entry? */
- (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) {
+ (iscleared(gkey(n), 1) || iscleared(gval(n), 0))) {
setnilvalue(gval(n)); /* remove value ... */
removeentry(n); /* and remove entry from table */
}
@@ -932,7 +958,8 @@ static void generationalcollection (lua_State *L) {
g->lastmajormem = g->totalbytes; /* update control */
}
else {
- luaC_runtilstate(L, bitmask(GCSpause)); /* run collection */
+ luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
+ luaC_runtilstate(L, bitmask(GCSpause));
if (g->totalbytes > g->lastmajormem/100 * g->gcpause)
g->lastmajormem = 0; /* signal for a major collection */
}
diff --git a/src/lgc.h b/src/lgc.h
index 18eb70fd..9c5b05e2 100644
--- a/src/lgc.h
+++ b/src/lgc.h
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.h,v 2.41 2010/05/10 18:23:45 roberto Exp $
+** $Id: lgc.h,v 2.44 2010/06/30 14:11:17 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -44,7 +44,7 @@
/*
** macro to tell when main invariant (white objects cannot point to black
** ones) must be kept. During a non-generational collection, the sweep
-** phase may brak the invariant, as objects turned white may point to
+** phase may break the invariant, as objects turned white may point to
** still-black objects. The invariant is restored when sweep ends and
** all objects are white again. During a generational collection, the
** invariant must be kept all times.
@@ -112,17 +112,20 @@
#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
- luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
+ luaC_barrier_(L,obj2gco(p),gcvalue(v)); }
-#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
- luaC_barrierback(L,t); }
+#define luaC_barrierback(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
+ luaC_barrierback_(L,p); }
#define luaC_objbarrier(L,p,o) \
{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
- luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
+ luaC_barrier_(L,obj2gco(p),obj2gco(o)); }
-#define luaC_objbarriert(L,t,o) \
- { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
+#define luaC_objbarrierback(L,p,o) \
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) luaC_barrierback_(L,p); }
+
+#define luaC_barrierproto(L,p,c) \
+ { if (isblack(obj2gco(p))) luaC_barrierproto_(L,p,c); }
LUAI_FUNC void luaC_separateudata (lua_State *L, int all);
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
@@ -131,8 +134,9 @@ LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz,
GCObject **list, int offset);
-LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
-LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
+LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);
+LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o);
+LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c);
LUAI_FUNC void luaC_checkfinalizer (lua_State *L, Udata *u);
LUAI_FUNC void luaC_checkupvalcolor (global_State *g, UpVal *uv);
LUAI_FUNC void luaC_changemode (lua_State *L, int mode);
diff --git a/src/linit.c b/src/linit.c
index ff296cd7..b8af9f39 100644
--- a/src/linit.c
+++ b/src/linit.c
@@ -1,5 +1,5 @@
/*
-** $Id: linit.c,v 1.24 2010/03/26 20:58:11 roberto Exp $
+** $Id: linit.c,v 1.28 2010/07/02 11:38:13 roberto Exp $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/
@@ -29,12 +29,16 @@
static const luaL_Reg loadedlibs[] = {
{"_G", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
+ {LUA_COLIBNAME, luaopen_coroutine},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_BITLIBNAME, luaopen_bit},
{LUA_MATHLIBNAME, luaopen_math},
+#if defined(LUA_COMPAT_DEBUGLIB)
+ {LUA_DBLIBNAME, luaopen_debug},
+#endif
{NULL, NULL}
};
@@ -50,25 +54,17 @@ static const luaL_Reg preloadedlibs[] = {
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib;
- /* call open functions from 'loadedlibs' */
+ /* call open functions from 'loadedlibs' and set results to global table */
for (lib = loadedlibs; lib->func; lib++) {
- lua_settop(L, 0);
- lua_pushstring(L, lib->name);
- (lib->func)(L);
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1); /* remove lib */
}
/* add open functions from 'preloadedlibs' into 'package.preload' table */
- lua_pushglobaltable(L);
- luaL_findtable(L, 0, "package.preload", 0);
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
for (lib = preloadedlibs; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name);
}
- lua_pop(L, 1); /* remove package.preload table */
-#if defined(LUA_COMPAT_DEBUGLIB)
- lua_getglobal(L, "require");
- lua_pushliteral(L, LUA_DBLIBNAME);
- lua_call(L, 1, 0); /* call 'require"debug"' */
- lua_pop(L, 1); /* remove global table */
-#endif
+ lua_pop(L, 1); /* remove _PRELOAD table */
}
diff --git a/src/liolib.c b/src/liolib.c
index c453cb95..3ecccb11 100644
--- a/src/liolib.c
+++ b/src/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 2.88 2010/03/26 20:58:11 roberto Exp $
+** $Id: liolib.c,v 2.91 2010/07/28 15:51:59 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -120,7 +120,7 @@ static FILE **newprefile (lua_State *L) {
static FILE **newfile (lua_State *L) {
FILE **pf = newprefile(L);
lua_pushvalue(L, lua_upvalueindex(1)); /* set upvalue... */
- lua_setenv(L, -2); /* ... as environment for new file */
+ lua_setuservalue(L, -2); /* ... as environment for new file */
return pf;
}
@@ -163,7 +163,7 @@ static int io_fclose (lua_State *L) {
static int aux_close (lua_State *L) {
- lua_getenv(L, 1);
+ lua_getuservalue(L, 1);
lua_getfield(L, -1, "__close");
return (lua_tocfunction(L, -1))(L);
}
@@ -583,7 +583,7 @@ static void createmeta (lua_State *L) {
luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
lua_pushvalue(L, -1); /* push metatable */
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
- luaL_register(L, NULL, flib); /* add file methods to new metatable */
+ luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
lua_pop(L, 1); /* pop new metatable */
}
@@ -595,7 +595,7 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
lua_rawseti(L, 1, k); /* add it to common upvalue */
}
lua_pushvalue(L, 3); /* get environment for default files */
- lua_setenv(L, -2); /* set it as environment for file */
+ lua_setuservalue(L, -2); /* set it as environment for file */
lua_setfield(L, 2, fname); /* add file to module */
}
@@ -615,8 +615,9 @@ LUAMOD_API int luaopen_io (lua_State *L) {
createmeta(L);
/* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
newenv(L, io_fclose); /* upvalue for all io functions at index 1 */
- lua_pushvalue(L, -1); /* copy to be consumed by 'openlib' */
- luaL_openlib(L, LUA_IOLIBNAME, iolib, 1); /* new module at index 2 */
+ luaL_newlibtable(L, iolib); /* new module at index 2 */
+ lua_pushvalue(L, 1); /* copy of env to be consumed by 'setfuncs' */
+ luaL_setfuncs(L, iolib, 1);
/* create (and set) default files */
newenv(L, io_noclose); /* environment for default files at index 3 */
createstdfile(L, stdin, IO_INPUT, "stdin");
diff --git a/src/llimits.h b/src/llimits.h
index 02be816e..4b75a84e 100644
--- a/src/llimits.h
+++ b/src/llimits.h
@@ -1,5 +1,5 @@
/*
-** $Id: llimits.h,v 1.80 2010/05/07 18:44:12 roberto Exp $
+** $Id: llimits.h,v 1.82 2010/05/31 16:08:55 roberto Exp $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
*/
@@ -97,6 +97,11 @@ typedef LUAI_UACNUMBER l_uacNumber;
#define LUAI_MAXCCALLS 200
#endif
+/*
+** maximum number of upvalues in a closure (both C and Lua). (Value
+** must fit in an unsigned char.)
+*/
+#define MAXUPVAL UCHAR_MAX
/*
@@ -179,7 +184,8 @@ typedef lu_int32 Instruction;
#if !defined(HARDMEMTESTS)
#define condchangemem(L) condmovestack(L)
#else
-#define condchangemem(L) luaC_fullgc(L, 0)
+#define condchangemem(L) \
+ ((void)(gcstopped(G(L)) || (luaC_fullgc(L, 0), 1)))
#endif
#endif
diff --git a/src/lmathlib.c b/src/lmathlib.c
index 27e6847e..7ba6550c 100644
--- a/src/lmathlib.c
+++ b/src/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.74 2009/11/24 12:05:44 roberto Exp $
+** $Id: lmathlib.c,v 1.75 2010/07/02 11:38:13 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -263,7 +263,7 @@ static const luaL_Reg mathlib[] = {
** Open math library
*/
LUAMOD_API int luaopen_math (lua_State *L) {
- luaL_register(L, LUA_MATHLIBNAME, mathlib);
+ luaL_newlib(L, mathlib);
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
lua_pushnumber(L, HUGE_VAL);
diff --git a/src/loadlib.c b/src/loadlib.c
index 793c658e..82c00b0d 100644
--- a/src/loadlib.c
+++ b/src/loadlib.c
@@ -1,11 +1,11 @@
/*
-** $Id: loadlib.c,v 1.82 2010/03/19 15:02:34 roberto Exp $
+** $Id: loadlib.c,v 1.89 2010/07/28 15:51:59 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
** This module contains an implementation of loadlib for Unix systems
-** that have dlfcn, an implementation for Darwin (Mac OS X), an
-** implementation for Windows, and a stub for other systems.
+** that have dlfcn, an implementation for Windows, and a stub for other
+** systems.
*/
@@ -23,17 +23,21 @@
/*
-** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment
+** LUA_PATH and LUA_CPATH are the names of the environment
** variables that Lua check to set its paths.
*/
-#if !defined(LUA_PATH_VAR)
-#define LUA_PATH_VAR "LUA_PATH"
+#if !defined(LUA_PATH)
+#define LUA_PATH "LUA_PATH"
#endif
-#if !defined(LUA_CPATH_VAR)
-#define LUA_CPATH_VAR "LUA_CPATH"
+#if !defined(LUA_CPATH)
+#define LUA_CPATH "LUA_CPATH"
#endif
+#define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
+
+#define LUA_PATHVERSION LUA_PATH LUA_PATHSUFFIX
+#define LUA_CPATHVERSION LUA_CPATH LUA_PATHSUFFIX
/*
** LUA_PATH_SEP is the character that separates templates in a path.
@@ -145,7 +149,7 @@ static void setprogdir (lua_State *L) {
char buff[MAX_PATH + 1];
char *lb;
DWORD nsize = sizeof(buff)/sizeof(char);
- DWORD n = GetModuleFileName(NULL, buff, nsize);
+ DWORD n = GetModuleFileNameA(NULL, buff, nsize);
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
luaL_error(L, "unable to get ModuleFileName");
else {
@@ -159,7 +163,7 @@ static void setprogdir (lua_State *L) {
static void pusherror (lua_State *L) {
int error = GetLastError();
char buffer[128];
- if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
+ if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, 0, buffer, sizeof(buffer), NULL))
lua_pushstring(L, buffer);
else
@@ -172,7 +176,7 @@ static void ll_unloadlib (void *lib) {
static void *ll_load (lua_State *L, const char *path, int seeglb) {
- HMODULE lib = LoadLibraryEx(path, NULL, LUA_LLE_FLAGS);
+ HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
(void)(seeglb); /* symbols are 'global' by default? */
if (lib == NULL) pusherror(L);
return lib;
@@ -188,90 +192,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
/* }====================================================== */
-
-#elif defined(LUA_DL_DYLD)
-/*
-** {======================================================================
-** Old native Mac OS X - only for old versions of Mac OS (< 10.3)
-** =======================================================================
-*/
-
-#include <mach-o/dyld.h>
-
-
-/* Mac appends a `_' before C function names */
-#undef POF
-#define POF "_" LUA_POF
-
-
-static void pusherror (lua_State *L) {
- const char *err_str;
- const char *err_file;
- NSLinkEditErrors err;
- int err_num;
- NSLinkEditError(&err, &err_num, &err_file, &err_str);
- lua_pushstring(L, err_str);
-}
-
-
-static const char *errorfromcode (NSObjectFileImageReturnCode ret) {
- switch (ret) {
- case NSObjectFileImageInappropriateFile:
- return "file is not a bundle";
- case NSObjectFileImageArch:
- return "library is for wrong CPU type";
- case NSObjectFileImageFormat:
- return "bad format";
- case NSObjectFileImageAccess:
- return "cannot access file";
- case NSObjectFileImageFailure:
- default:
- return "unable to load library";
- }
-}
-
-
-static void ll_unloadlib (void *lib) {
- NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
-}
-
-
-static void *ll_load (lua_State *L, const char *path, int seeglb) {
- NSObjectFileImage img;
- NSObjectFileImageReturnCode ret;
- /* this would be a rare case, but prevents crashing if it happens */
- if(!_dyld_present()) {
- lua_pushliteral(L, "dyld not present");
- return NULL;
- }
- ret = NSCreateObjectFileImageFromFile(path, &img);
- if (ret == NSObjectFileImageSuccess) {
- NSModule mod = NSLinkModule(img,
- path,
- NSLINKMODULE_OPTION_RETURN_ON_ERROR |
- (seeglb ? 0 : NSLINKMODULE_OPTION_PRIVATE));
- NSDestroyObjectFileImage(img);
- if (mod == NULL) pusherror(L);
- return mod;
- }
- lua_pushstring(L, errorfromcode(ret));
- return NULL;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);
- if (nss == NULL) {
- lua_pushfstring(L, "symbol " LUA_QS " not found", sym);
- return NULL;
- }
- return (lua_CFunction)NSAddressOfSymbol(nss);
-}
-
-/* }====================================================== */
-
-
-
#else
/*
** {======================================================
@@ -507,7 +427,7 @@ static int loader_Croot (lua_State *L) {
static int loader_preload (lua_State *L) {
const char *name = luaL_checkstring(L, 1);
- lua_getfield(L, lua_upvalueindex(1), "preload");
+ lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
if (!lua_istable(L, -1))
luaL_error(L, LUA_QL("package.preload") " must be a table");
lua_getfield(L, -1, name);
@@ -575,11 +495,10 @@ static int ll_require (lua_State *L) {
** 'module' function
** =======================================================
*/
-
+#if defined(LUA_COMPAT_MODULE)
/*
-** FOR COMPATIBILITY ONLY: changes the _ENV variable of
-** calling function
+** changes the _ENV variable of calling function
*/
static void set_env (lua_State *L) {
lua_Debug ar;
@@ -620,18 +539,8 @@ static void modinit (lua_State *L, const char *modname) {
static int ll_module (lua_State *L) {
const char *modname = luaL_checkstring(L, 1);
- int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
- lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_getfield(L, loaded, modname); /* get _LOADED[modname] */
- if (!lua_istable(L, -1)) { /* not found? */
- lua_pop(L, 1); /* remove previous result */
- /* try global variable (and create one if it does not exist) */
- lua_pushglobaltable(L);
- if (luaL_findtable(L, 0, modname, 1) != NULL)
- return luaL_error(L, "name conflict for module " LUA_QS, modname);
- lua_pushvalue(L, -1);
- lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
- }
+ int lastarg = lua_gettop(L); /* last parameter */
+ luaL_pushmodule(L, modname, 1); /* get/create module table */
/* check whether table already has a _NAME field */
lua_getfield(L, -1, "_NAME");
if (!lua_isnil(L, -1)) /* is table an initialized module? */
@@ -642,7 +551,7 @@ static int ll_module (lua_State *L) {
}
lua_pushvalue(L, -1);
set_env(L);
- dooptions(L, loaded - 1);
+ dooptions(L, lastarg);
return 1;
}
@@ -660,6 +569,17 @@ static int ll_seeall (lua_State *L) {
}
+#else
+
+static int ll_seeall (lua_State *L) {
+ return luaL_error(L, "deprecated function");
+}
+
+static int ll_module (lua_State *L) {
+ return luaL_error(L, "deprecated function");
+}
+
+#endif
/* }====================================================== */
@@ -667,9 +587,11 @@ static int ll_seeall (lua_State *L) {
/* auxiliary mark (for internal use) */
#define AUXMARK "\1"
-static void setpath (lua_State *L, const char *fieldname, const char *envname,
- const char *def) {
- const char *path = getenv(envname);
+static void setpath (lua_State *L, const char *fieldname, const char *envname1,
+ const char *envname2, const char *def) {
+ const char *path = getenv(envname1);
+ if (path == NULL) /* no environment variable? */
+ path = getenv(envname2); /* try alternative name */
if (path == NULL) /* no environment variable? */
lua_pushstring(L, def); /* use default */
else {
@@ -710,7 +632,7 @@ LUAMOD_API int luaopen_package (lua_State *L) {
lua_pushcfunction(L, gctm);
lua_setfield(L, -2, "__gc");
/* create `package' table */
- luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
+ luaL_newlib(L, pk_funcs);
/* create `loaders' table */
lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
/* fill it with pre-defined loaders */
@@ -720,21 +642,23 @@ LUAMOD_API int luaopen_package (lua_State *L) {
lua_rawseti(L, -2, i+1);
}
lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */
- setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT); /* set field `path' */
- setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT); /* set field `cpath' */
+ /* set field 'path' */
+ setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT);
+ /* set field 'cpath' */
+ setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT);
/* store config information */
lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
lua_setfield(L, -2, "config");
/* set field `loaded' */
- luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
lua_setfield(L, -2, "loaded");
/* set field `preload' */
- lua_newtable(L);
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
lua_setfield(L, -2, "preload");
lua_pushglobaltable(L);
lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */
- luaL_openlib(L, NULL, ll_funcs, 1); /* open lib into global table */
+ luaL_setfuncs(L, ll_funcs, 1); /* open lib into global table */
lua_pop(L, 1); /* pop global table */
return 1; /* return 'package' table */
}
diff --git a/src/lobject.h b/src/lobject.h
index 73634220..5b856f3c 100644
--- a/src/lobject.h
+++ b/src/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 2.40 2010/05/07 18:44:46 roberto Exp $
+** $Id: lobject.h,v 2.42 2010/07/26 15:53:23 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -56,17 +56,18 @@ typedef struct GCheader {
** Union of all Lua values
*/
typedef union {
- GCObject *gc;
- void *p;
- lua_Number n;
- int b;
- lua_CFunction f;
+ GCObject *gc; /* collectable objects */
+ void *p; /* light userdata */
+ lua_Number n; /* numbers */
+ int b; /* booleans */
+ lua_CFunction f; /* light C functions */
} Value;
/*
-** Tagged Values
+** Tagged Values. This is the basic representation of values in Lua,
+** an actual value plus a tag with its type.
*/
#define TValuefields Value value_; int tt_
@@ -76,7 +77,7 @@ typedef struct lua_TValue {
} TValue;
-/* macro defining a nil value to be used in definitions */
+/* macro defining a nil value */
#define NILCONSTANT {NULL}, LUA_TNIL
@@ -125,6 +126,8 @@ typedef struct lua_TValue {
#define iscollectable(o) (ttype(o) >= LUA_TSTRING)
+
+/* Macros for internal tests */
#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
#define checkconsistency(obj) lua_assert(!iscollectable(obj) || righttt(obj))
@@ -191,7 +194,7 @@ typedef struct lua_TValue {
/*
-** different types of sets, according to destination
+** different types of assignments, according to destination
*/
/* from stack to (same) stack */
@@ -215,7 +218,7 @@ typedef TValue *StkId; /* index to stack elements */
/*
-** String headers for string table
+** Header for string value; string bytes follow the end of this structure
*/
typedef union TString {
L_Umaxalign dummy; /* ensures maximum alignment for strings */
@@ -228,11 +231,16 @@ typedef union TString {
} TString;
+/* get the actual string (array of bytes) from a TString */
#define getstr(ts) cast(const char *, (ts) + 1)
-#define svalue(o) getstr(rawtsvalue(o))
+/* get the actual string (array of bytes) from a Lua value */
+#define svalue(o) getstr(rawtsvalue(o))
+/*
+** Header for userdata; memory area follows the end of this structure
+*/
typedef union Udata {
L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
struct {
@@ -246,16 +254,27 @@ typedef union Udata {
/*
-** Upvalues from a function prototype
+** Description of an upvalue for function prototypes
*/
typedef struct Upvaldesc {
TString *name; /* upvalue name (for debug information) */
- lu_byte instack;
+ lu_byte instack; /* whether it is in stack */
lu_byte idx; /* index of upvalue (in stack or in outer function's list) */
} Upvaldesc;
/*
+** Description of a local variable for function prototypes
+** (used for debug information)
+*/
+typedef struct LocVar {
+ TString *varname;
+ int startpc; /* first point where variable is active */
+ int endpc; /* first point where variable is dead */
+} LocVar;
+
+
+/*
** Function Prototypes
*/
typedef struct Proto {
@@ -264,8 +283,9 @@ typedef struct Proto {
Instruction *code;
struct Proto **p; /* functions defined inside the function */
int *lineinfo; /* map from opcodes to source lines */
- struct LocVar *locvars; /* information about local variables */
+ LocVar *locvars; /* information about local variables */
Upvaldesc *upvalues; /* upvalue information */
+ union Closure *cache; /* last created closure with this prototype */
TString *source;
int sizeupvalues; /* size of 'upvalues' */
int sizek; /* size of `k' */
@@ -276,24 +296,16 @@ typedef struct Proto {
int linedefined;
int lastlinedefined;
GCObject *gclist;
- lu_byte numparams;
+ lu_byte numparams; /* number of fixed parameters */
lu_byte is_vararg;
- lu_byte maxstacksize;
+ lu_byte maxstacksize; /* maximum stack used by this function */
} Proto;
-typedef struct LocVar {
- TString *varname;
- int startpc; /* first point where variable is active */
- int endpc; /* first point where variable is dead */
-} LocVar;
-
-
/*
-** Upvalues
+** Lua Upvalues
*/
-
typedef struct UpVal {
CommonHeader;
TValue *v; /* points to stack or to its own value */
@@ -317,14 +329,14 @@ typedef struct UpVal {
typedef struct CClosure {
ClosureHeader;
lua_CFunction f;
- TValue upvalue[1];
+ TValue upvalue[1]; /* list of upvalues */
} CClosure;
typedef struct LClosure {
ClosureHeader;
struct Proto *p;
- UpVal *upvals[1];
+ UpVal *upvals[1]; /* list of upvalues */
} LClosure;
@@ -338,6 +350,7 @@ typedef union Closure {
#define getproto(o) (clvalue(o)->l.p)
+
/*
** Tables
*/
@@ -382,8 +395,12 @@ typedef struct Table {
#define sizenode(t) (twoto((t)->lsizenode))
+/*
+** (address of) a fixed nil value
+*/
#define luaO_nilobject (&luaO_nilobject_)
+
LUAI_DDEC const TValue luaO_nilobject_;
LUAI_FUNC int luaO_int2fb (unsigned int x);
diff --git a/src/loslib.c b/src/loslib.c
index 41592088..9b27ebce 100644
--- a/src/loslib.c
+++ b/src/loslib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loslib.c,v 1.29 2009/12/17 13:08:51 roberto Exp $
+** $Id: loslib.c,v 1.31 2010/07/02 12:01:53 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@@ -146,11 +146,10 @@ static int getboolfield (lua_State *L, const char *key) {
static int getfield (lua_State *L, const char *key, int d) {
- int res;
+ int res, isnum;
lua_getfield(L, -1, key);
- if (lua_isnumber(L, -1))
- res = (int)lua_tointeger(L, -1);
- else {
+ res = (int)lua_tointegerx(L, -1, &isnum);
+ if (!isnum) {
if (d < 0)
return luaL_error(L, "field " LUA_QS " missing in date table", key);
res = d;
@@ -304,7 +303,7 @@ static const luaL_Reg syslib[] = {
LUAMOD_API int luaopen_os (lua_State *L) {
- luaL_register(L, LUA_OSLIBNAME, syslib);
+ luaL_newlib(L, syslib);
return 1;
}
diff --git a/src/lparser.c b/src/lparser.c
index 762cb4fc..16c05d9e 100644
--- a/src/lparser.c
+++ b/src/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 2.86 2010/05/15 13:32:02 roberto Exp $
+** $Id: lparser.c,v 2.90 2010/07/07 16:27:29 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -138,7 +138,7 @@ static TString *str_checkname (LexState *ls) {
static void init_exp (expdesc *e, expkind k, int i) {
e->f = e->t = NO_JUMP;
e->k = k;
- e->u.s.info = i;
+ e->u.info = i;
}
@@ -221,12 +221,12 @@ static int searchupvalue (FuncState *fs, TString *name) {
static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
Proto *f = fs->f;
int oldsize = f->sizeupvalues;
- checklimit(fs, fs->nups + 1, UCHAR_MAX, "upvalues");
+ checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues,
- Upvaldesc, UCHAR_MAX, "upvalues");
+ Upvaldesc, MAXUPVAL, "upvalues");
while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
f->upvalues[fs->nups].instack = (v->k == VLOCAL);
- f->upvalues[fs->nups].idx = cast_byte(v->u.s.info);
+ f->upvalues[fs->nups].idx = cast_byte(v->u.info);
f->upvalues[fs->nups].name = name;
luaC_objbarrier(fs->L, f, name);
return fs->nups++;
@@ -402,8 +402,8 @@ static void close_func (LexState *ls) {
lua_State *L = ls->L;
FuncState *fs = ls->fs;
Proto *f = fs->f;
- removevars(fs, 0);
luaK_ret(fs, 0, 0); /* final return */
+ removevars(fs, 0);
luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
f->sizecode = fs->pc;
luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
@@ -518,7 +518,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
checknext(ls, '=');
rkkey = luaK_exp2RK(fs, &key);
expr(ls, &val);
- luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
+ luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));
fs->freereg = reg; /* free registers */
}
@@ -528,7 +528,7 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) {
luaK_exp2nextreg(fs, &cc->v);
cc->v.k = VVOID;
if (cc->tostore == LFIELDS_PER_FLUSH) {
- luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */
+ luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
cc->tostore = 0; /* no more items pending */
}
}
@@ -538,13 +538,13 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
if (cc->tostore == 0) return;
if (hasmultret(cc->v.k)) {
luaK_setmultret(fs, &cc->v);
- luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
+ luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
cc->na--; /* do not count last expression (unknown number of elements) */
}
else {
if (cc->v.k != VVOID)
luaK_exp2nextreg(fs, &cc->v);
- luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
+ luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
}
}
@@ -702,7 +702,7 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
}
}
lua_assert(f->k == VNONRELOC);
- base = f->u.s.info; /* base register for call */
+ base = f->u.info; /* base register for call */
if (hasmultret(args.k))
nparams = LUA_MULTRET; /* open call */
else {
@@ -969,27 +969,26 @@ struct LHS_assign {
** local value in a safe place and use this safe copy in the previous
** assignment.
*/
-static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v,
- expkind ix, OpCode op) {
+static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
FuncState *fs = ls->fs;
int extra = fs->freereg; /* eventual position to save local variable */
int conflict = 0;
for (; lh; lh = lh->prev) {
- if (lh->v.k == ix) {
- if (lh->v.u.s.info == v->u.s.info) { /* conflict? */
- conflict = 1;
- lh->v.k = VINDEXED;
- lh->v.u.s.info = extra; /* previous assignment will use safe copy */
- }
- if (v->k == VLOCAL && lh->v.u.s.aux == v->u.s.info) { /* conflict? */
- conflict = 1;
- lua_assert(lh->v.k == VINDEXED);
- lh->v.u.s.aux = extra; /* previous assignment will use safe copy */
- }
+ /* conflict in table 't'? */
+ if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
+ conflict = 1;
+ lh->v.u.ind.vt = VLOCAL;
+ lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
+ }
+ /* conflict in index 'idx'? */
+ if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
+ conflict = 1;
+ lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
}
}
if (conflict) {
- luaK_codeABC(fs, op, fs->freereg, v->u.s.info, 0); /* make copy */
+ OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
+ luaK_codeABC(fs, op, fs->freereg, v->u.info, 0); /* make copy */
luaK_reserveregs(fs, 1);
}
}
@@ -997,16 +996,13 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v,
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
expdesc e;
- check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXEDUP,
- "syntax error");
+ check_condition(ls, vkisvar(lh->v.k), "syntax error");
if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */
struct LHS_assign nv;
nv.prev = lh;
primaryexp(ls, &nv.v);
- if (nv.v.k == VLOCAL)
- check_conflict(ls, lh, &nv.v, VINDEXED, OP_MOVE);
- else if (nv.v.k == VUPVAL)
- check_conflict(ls, lh, &nv.v, VINDEXEDUP, OP_GETUPVAL);
+ if (nv.v.k != VINDEXED)
+ check_conflict(ls, lh, &nv.v);
checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls,
"variable names");
assignment(ls, &nv, nvars+1);
@@ -1108,7 +1104,7 @@ static int exp1 (LexState *ls) {
expr(ls, &e);
luaK_exp2nextreg(ls->fs, &e);
lua_assert(e.k == VNONRELOC);
- reg = e.u.s.info;
+ reg = e.u.info;
return reg;
}
diff --git a/src/lparser.h b/src/lparser.h
index 9e406a7b..6055a85b 100644
--- a/src/lparser.h
+++ b/src/lparser.h
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.h,v 1.63 2010/03/12 19:14:06 roberto Exp $
+** $Id: lparser.h,v 1.65 2010/07/07 16:27:29 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -23,23 +23,30 @@ typedef enum {
VFALSE,
VK, /* info = index of constant in `k' */
VKNUM, /* nval = numerical value */
+ VNONRELOC, /* info = result register */
VLOCAL, /* info = local register */
VUPVAL, /* info = index of upvalue in 'upvalues' */
- VINDEXED, /* info = table R/K; aux = index R/K */
- VINDEXEDUP, /* info = table upvalue; aux = R/K */
+ VINDEXED, /* t = table register/upvalue; idx = index R/K */
VJMP, /* info = instruction pc */
VRELOCABLE, /* info = instruction pc */
- VNONRELOC, /* info = result register */
VCALL, /* info = instruction pc */
VVARARG /* info = instruction pc */
} expkind;
+#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
+#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
+
typedef struct expdesc {
expkind k;
union {
- struct { int info, aux; } s;
- lua_Number nval;
+ struct { /* for indexed variables (VINDEXED) */
+ short idx; /* index (R/K) */
+ lu_byte t; /* table (register or upvalue) */
+ lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
+ } ind;
+ int info; /* for generic use */
+ lua_Number nval; /* for VKNUM */
} u;
int t; /* patch list of `exit when true' */
int f; /* patch list of `exit when false' */
diff --git a/src/lstrlib.c b/src/lstrlib.c
index a5c3a204..558a748e 100644
--- a/src/lstrlib.c
+++ b/src/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.152 2010/05/04 17:20:33 roberto Exp $
+** $Id: lstrlib.c,v 1.154 2010/07/02 11:38:13 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -241,6 +241,7 @@ static int match_class (int c, int cl) {
case 'a' : res = isalpha(c); break;
case 'c' : res = iscntrl(c); break;
case 'd' : res = isdigit(c); break;
+ case 'g' : res = isgraph(c); break;
case 'l' : res = islower(c); break;
case 'p' : res = ispunct(c); break;
case 's' : res = isspace(c); break;
@@ -912,7 +913,7 @@ static void createmetatable (lua_State *L) {
** Open string library
*/
LUAMOD_API int luaopen_string (lua_State *L) {
- luaL_register(L, LUA_STRLIBNAME, strlib);
+ luaL_newlib(L, strlib);
createmetatable(L);
return 1;
}
diff --git a/src/ltable.c b/src/ltable.c
index dc6604dd..f93b96cc 100644
--- a/src/ltable.c
+++ b/src/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 2.50 2010/04/18 13:22:48 roberto Exp $
+** $Id: ltable.c,v 2.52 2010/06/25 12:18:10 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -148,7 +148,7 @@ static int findindex (lua_State *L, Table *t, StkId key) {
Node *n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
/* key may be dead already, but it is ok to use it in `next' */
- if (luaO_rawequalObj(key2tval(n), key) ||
+ if (luaO_rawequalObj(gkey(n), key) ||
(ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
gcvalue(gkey(n)) == gcvalue(key))) {
i = cast_int(n - gnode(t, 0)); /* key index in hash table */
@@ -174,7 +174,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
}
for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
- setobj2s(L, key, key2tval(gnode(t, i)));
+ setobj2s(L, key, gkey(gnode(t, i)));
setobj2s(L, key+1, gval(gnode(t, i)));
return 1;
}
@@ -255,7 +255,7 @@ static int numusehash (const Table *t, int *nums, int *pnasize) {
while (i--) {
Node *n = &t->node[i];
if (!ttisnil(gval(n))) {
- ause += countint(key2tval(n), nums);
+ ause += countint(gkey(n), nums);
totaluse++;
}
}
@@ -321,7 +321,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
for (i = twoto(oldhsize) - 1; i >= 0; i--) {
Node *old = nold+i;
if (!ttisnil(gval(old)))
- setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
+ setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
}
if (!isdummy(nold))
luaM_freearray(L, nold, twoto(oldhsize)); /* free old array */
@@ -406,7 +406,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
return luaH_set(L, t, key); /* re-insert key into grown table */
}
lua_assert(!isdummy(n));
- othern = mainposition(t, key2tval(mp));
+ othern = mainposition(t, gkey(mp));
if (othern != mp) { /* is colliding node out of its main position? */
/* yes; move colliding node into free position */
while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
@@ -423,7 +423,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
}
}
setobj2t(L, gkey(mp), key);
- luaC_barriert(L, t, key);
+ luaC_barrierback(L, obj2gco(t), key);
lua_assert(ttisnil(gval(mp)));
return gval(mp);
}
@@ -481,7 +481,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
default: {
Node *n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
- if (luaO_rawequalObj(key2tval(n), key))
+ if (luaO_rawequalObj(gkey(n), key))
return gval(n); /* that's it */
else n = gnext(n);
} while (n);
diff --git a/src/ltable.h b/src/ltable.h
index 784377ac..c14b0283 100644
--- a/src/ltable.h
+++ b/src/ltable.h
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.h,v 2.13 2009/11/06 17:07:48 roberto Exp $
+** $Id: ltable.h,v 2.14 2010/06/25 12:18:10 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -15,8 +15,6 @@
#define gval(n) (&(n)->i_val)
#define gnext(n) ((n)->i_key.nk.next)
-#define key2tval(n) (&(n)->i_key.tvk)
-
LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
LUAI_FUNC TValue *luaH_setint (lua_State *L, Table *t, int key);
diff --git a/src/ltablib.c b/src/ltablib.c
index 2e00da29..b094d2f8 100644
--- a/src/ltablib.c
+++ b/src/ltablib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltablib.c,v 1.55 2010/03/13 03:57:46 roberto Exp $
+** $Id: ltablib.c,v 1.56 2010/07/02 11:38:13 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
@@ -324,7 +324,7 @@ static const luaL_Reg tab_funcs[] = {
LUAMOD_API int luaopen_table (lua_State *L) {
- luaL_register(L, LUA_TABLIBNAME, tab_funcs);
+ luaL_newlib(L, tab_funcs);
#if defined(LUA_COMPAT_UNPACK)
/* _G.unpack = table.unpack */
lua_getfield(L, -1, "unpack");
diff --git a/src/lua.c b/src/lua.c
index 2b1c6161..7d23636f 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.190 2010/04/14 15:14:21 roberto Exp $
+** $Id: lua.c,v 1.192 2010/07/25 15:03:37 roberto Exp $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -31,10 +31,13 @@
#define LUA_MAXINPUT 512
#endif
-#if !defined(LUA_INIT_VAR)
-#define LUA_INIT_VAR "LUA_INIT"
+#if !defined(LUA_INIT)
+#define LUA_INIT "LUA_INIT"
#endif
+#define LUA_INITVERSION \
+ LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
+
/*
** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
@@ -167,14 +170,14 @@ static int traceback (lua_State *L) {
}
-static int docall (lua_State *L, int narg, int clear) {
+static int docall (lua_State *L, int narg, int nres) {
int status;
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */
globalL = L; /* to be available to 'laction' */
signal(SIGINT, laction);
- status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
+ status = lua_pcall(L, narg, nres, base);
signal(SIGINT, SIG_DFL);
lua_remove(L, base); /* remove traceback function */
return status;
@@ -206,22 +209,31 @@ static int getargs (lua_State *L, char **argv, int n) {
static int dofile (lua_State *L, const char *name) {
int status = luaL_loadfile(L, name);
- if (status == LUA_OK) status = docall(L, 0, 1);
+ if (status == LUA_OK) status = docall(L, 0, 0);
return report(L, status);
}
static int dostring (lua_State *L, const char *s, const char *name) {
int status = luaL_loadbuffer(L, s, strlen(s), name);
- if (status == LUA_OK) status = docall(L, 0, 1);
+ if (status == LUA_OK) status = docall(L, 0, 0);
return report(L, status);
}
static int dolibrary (lua_State *L, const char *name) {
- lua_getglobal(L, "require");
+ int status;
+ lua_pushglobaltable(L);
+ lua_getfield(L, -1, "require");
lua_pushstring(L, name);
- return report(L, docall(L, 1, 1));
+ status = docall(L, 1, 1);
+ if (status == LUA_OK) {
+ lua_setfield(L, -2, name); /* global[name] = require return */
+ lua_pop(L, 1); /* remove global table */
+ }
+ else
+ lua_remove(L, -2); /* remove global table (below error msg.) */
+ return report(L, status);
}
@@ -297,7 +309,7 @@ static void dotty (lua_State *L) {
const char *oldprogname = progname;
progname = NULL;
while ((status = loadline(L)) != -1) {
- if (status == LUA_OK) status = docall(L, 0, 0);
+ if (status == LUA_OK) status = docall(L, 0, LUA_MULTRET);
report(L, status);
if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
@@ -326,7 +338,7 @@ static int handle_script (lua_State *L, char **argv, int n) {
status = luaL_loadfile(L, fname);
lua_insert(L, -(narg+1));
if (status == LUA_OK)
- status = docall(L, narg, 0);
+ status = docall(L, narg, LUA_MULTRET);
else
lua_pop(L, narg);
return report(L, status);
@@ -400,12 +412,17 @@ static int runargs (lua_State *L, char **argv, int n) {
static int handle_luainit (lua_State *L) {
- const char *init = getenv(LUA_INIT_VAR);
+ const char *name = "=" LUA_INITVERSION;
+ const char *init = getenv(name + 1);
+ if (init == NULL) {
+ name = "=" LUA_INIT;
+ init = getenv(name + 1); /* try alternative name */
+ }
if (init == NULL) return LUA_OK;
else if (init[0] == '@')
return dofile(L, init+1);
else
- return dostring(L, init, "=" LUA_INIT_VAR);
+ return dostring(L, init, name);
}
diff --git a/src/lua.h b/src/lua.h
index 09a9ab76..d1cf33ab 100644
--- a/src/lua.h
+++ b/src/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.270 2010/05/12 14:09:20 roberto Exp $
+** $Id: lua.h,v 1.273 2010/07/25 15:18:19 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@@ -16,8 +16,12 @@
#include "luaconf.h"
-#define LUA_VERSION "Lua 5.2"
-#define LUA_RELEASE "Lua 5.2.0 (work3)"
+#define LUA_VERSION_MAJOR "5"
+#define LUA_VERSION_MINOR "2"
+#define LUA_VERSION_RELEASE "0" " (work4)"
+
+#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
+#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_VERSION_NUM 502
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2010 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
@@ -153,8 +157,8 @@ LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
-LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
-LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
+LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
+LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
@@ -213,7 +217,7 @@ LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
-LUA_API void (lua_getenv) (lua_State *L, int idx);
+LUA_API void (lua_getuservalue) (lua_State *L, int idx);
/*
@@ -224,7 +228,7 @@ LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
-LUA_API void (lua_setenv) (lua_State *L, int idx);
+LUA_API void (lua_setuservalue) (lua_State *L, int idx);
/*
@@ -296,6 +300,9 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
** ===============================================================
*/
+#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
+#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
+
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
diff --git a/src/luaconf.h b/src/luaconf.h
index 0606230d..12ec5fc1 100644
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.137 2010/05/12 14:17:36 roberto Exp $
+** $Id: luaconf.h,v 1.142 2010/07/28 15:51:59 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -76,7 +76,7 @@
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
-#if defined(_WIN32)
+#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
@@ -89,16 +89,18 @@
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
-#else /* _WIN32 */
+#else /* }{ */
+
+#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
#define LUA_ROOT "/usr/local/"
-#define LUA_LDIR LUA_ROOT "share/lua/5.2/"
-#define LUA_CDIR LUA_ROOT "lib/lua/5.2/"
+#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
+#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
-#endif /* _WIN32 */
+#endif /* } */
/*
@@ -122,19 +124,19 @@
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
-#if defined(LUA_BUILD_AS_DLL)
+#if defined(LUA_BUILD_AS_DLL) /* { */
-#if defined(LUA_CORE) || defined(LUA_LIB)
+#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
-#else
+#else /* }{ */
#define LUA_API __declspec(dllimport)
-#endif
+#endif /* } */
-#else /* LUA_BUILD_AS_DLL */
+#else /* }{ */
#define LUA_API extern
-#endif /* LUA_BUILD_AS_DLL */
+#endif /* } */
/* more often than not the libs go together with the core */
@@ -156,7 +158,7 @@
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
-#if defined(luaall_c)
+#if defined(luaall_c) /* { */
#define LUAI_FUNC static
#define LUAI_DDEC static
#define LUAI_DDEF static
@@ -167,11 +169,11 @@
#define LUAI_DDEC LUAI_FUNC
#define LUAI_DDEF /* empty */
-#else /* luaall_c */
+#else /* }{ */
#define LUAI_FUNC extern
#define LUAI_DDEC extern
#define LUAI_DDEF /* empty */
-#endif /* luaall_c */
+#endif /* } */
@@ -229,10 +231,12 @@
/*
@@ LUA_COMPAT_CPCALL controls the presence of macro 'lua_cpcall'.
-** You can replace it with the preregistered function 'cpcall'.
+** You can call your C function directly (with light C functions)
*/
#define lua_cpcall(L,f,u) \
- (lua_pushlightuserdata(L,(u)), luaL_cpcall(L,(f),1,0))
+ (lua_pushcfunction(L, (f)), \
+ lua_pushlightuserdata(L,(u)), \
+ lua_pcall(L,1,0,0))
/*
@@ -269,6 +273,12 @@
/* compatibility with previous wrong spelling */
#define luaL_typerror luaL_typeerror
+/*
+@@ LUA_COMPAT_MODULE controls compatibility with previous
+** module functions 'module' (Lua) and 'luaL_register' (C).
+*/
+#define LUA_COMPAT_MODULE
+
#endif /* LUA_COMPAT_ALL */
/* }================================================================== */
@@ -281,14 +291,14 @@
** your machine. Probably you do not need to change this.
*/
/* avoid overflows in comparison */
-#if INT_MAX-20 < 32760
+#if INT_MAX-20 < 32760 /* { */
#define LUAI_BITSINT 16
-#elif INT_MAX > 2147483640L
+#elif INT_MAX > 2147483640L /* }{ */
/* int has at least 32 bits */
#define LUAI_BITSINT 32
-#else
+#else /* }{ */
#error "you must define LUA_BITSINT with number of bits in an integer"
-#endif
+#endif /* } */
/*
@@ -301,16 +311,16 @@
** good enough for your machine. Probably you do not need to change
** this.
*/
-#if LUAI_BITSINT >= 32
+#if LUAI_BITSINT >= 32 /* { */
#define LUA_INT32 int
#define LUAI_UMEM size_t
#define LUAI_MEM ptrdiff_t
-#else
+#else /* }{ */
/* 16-bit ints */
#define LUA_INT32 long
#define LUAI_UMEM unsigned long
#define LUAI_MEM long
-#endif
+#endif /* } */
/*
@@ -436,17 +446,17 @@
/* On a Pentium, resort to a trick */
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
- (defined(__i386) || defined (_M_IX86) || defined(__i386__))
+ (defined(__i386) || defined (_M_IX86) || defined(__i386__)) /* { */
/* On a Microsoft compiler, use assembler */
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) /* { */
#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
#define lua_number2integer(i,n) lua_number2int(i, n)
#define lua_number2uint(i,n) \
{__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
-#else /* _MSC_VER */
+#else /* }{ */
/* the next trick should work on any Pentium, but sometimes clashes
with a DirectX idiosyncrasy */
@@ -456,16 +466,16 @@ union luai_Cast { double l_d; long l_l; };
#define lua_number2integer(i,n) lua_number2int(i, n)
#define lua_number2uint(i,n) lua_number2int(i, n)
-#endif /* _MSC_VER */
+#endif /* } */
-#else /* LUA_NUMBER_DOUBLE ... (Pentium) */
+#else /* }{ */
/* this option always works, but may be slow */
#define lua_number2int(i,n) ((i)=(int)(n))
#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
#define lua_number2uint(i,n) ((i)=(unsigned LUA_INT32)(n))
-#endif /* LUA_NUMBER_DOUBLE ... (Pentium) */
+#endif /* } */
/* on several machines, coercion from unsigned to double is too slow,
@@ -477,7 +487,7 @@ union luai_Cast { double l_d; long l_l; };
/*
@@ luai_hashnum is a macro do hash a lua_Number value into an integer.
@* The hash must be deterministic and give reasonable values for
-@* both small and large values (outside the range of integers).
+@* both small and large values (outside the range of integers).
@* It is used only in ltable.c.
*/
diff --git a/src/lualib.h b/src/lualib.h
index d5e4ba9d..db2e200e 100644
--- a/src/lualib.h
+++ b/src/lualib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lualib.h,v 1.39 2009/11/24 12:05:44 roberto Exp $
+** $Id: lualib.h,v 1.40 2010/06/10 21:29:47 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
@@ -15,9 +15,11 @@
#define LUA_FILEHANDLE "FILE*"
-#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_base) (lua_State *L);
+#define LUA_COLIBNAME "coroutine"
+LUAMOD_API int (luaopen_coroutine) (lua_State *L);
+
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
diff --git a/src/lvm.c b/src/lvm.c
index 518a16ba..a222049b 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 2.120 2010/05/13 19:53:05 roberto Exp $
+** $Id: lvm.c,v 2.123 2010/06/30 14:11:17 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -88,7 +88,7 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1,
setobj2s(L, L->top++, p1); /* 1st argument */
setobj2s(L, L->top++, p2); /* 2nd argument */
if (!hasres) /* no result? 'p3' is third argument */
- setobj2s(L, L->top++, p3); /* 3th argument */
+ setobj2s(L, L->top++, p3); /* 3rd argument */
luaD_checkstack(L, 0);
/* metamethod may yield only when called from Lua code */
luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
@@ -136,7 +136,7 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
if (!ttisnil(oldval) || /* result is not nil? */
(tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
setobj2t(L, oldval, val);
- luaC_barriert(L, h, val);
+ luaC_barrierback(L, obj2gco(h), val);
return;
}
/* else will try the tag method */
@@ -346,6 +346,51 @@ void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
/*
+** check whether cached closure in prototype 'p' may be reused, that is,
+** whether there is a cached closure with the same upvalues needed by
+** new closure to be created.
+*/
+static Closure *getcached (Proto *p, UpVal **encup, StkId base) {
+ Closure *c = p->cache;
+ if (c != NULL) { /* is there a cached closure? */
+ int nup = p->sizeupvalues;
+ Upvaldesc *uv = p->upvalues;
+ int i;
+ for (i = 0; i < nup; i++) { /* check whether it has right upvalues */
+ TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;
+ if (c->l.upvals[i]->v != v)
+ return NULL; /* wrong upvalue; cannot reuse closure */
+ }
+ }
+ return c; /* return cached closure (or NULL if no cached closure) */
+}
+
+
+/*
+** create a new Lua closure, push it in the stack, and initialize
+** its upvalues. Note that the call to 'luaC_barrierproto' must come
+** before the assignment to 'p->cache', as the function needs the
+** original value of that field.
+*/
+static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
+ StkId ra) {
+ int nup = p->sizeupvalues;
+ Upvaldesc *uv = p->upvalues;
+ int i;
+ Closure *ncl = luaF_newLclosure(L, p);
+ setclvalue(L, ra, ncl); /* anchor new closure in stack */
+ for (i = 0; i < nup; i++) { /* fill in its upvalues */
+ if (uv[i].instack) /* upvalue refers to local variable? */
+ ncl->l.upvals[i] = luaF_findupval(L, base + uv[i].idx);
+ else /* get upvalue from enclosing function */
+ ncl->l.upvals[i] = encup[uv[i].idx];
+ }
+ luaC_barrierproto(L, p, ncl);
+ p->cache = ncl; /* save it on cache for reuse */
+}
+
+
+/*
** finish execution of an opcode interrupted by an yield
*/
void luaV_finishOp (lua_State *L) {
@@ -721,7 +766,7 @@ void luaV_execute (lua_State *L) {
for (; n > 0; n--) {
TValue *val = ra+n;
setobj2t(L, luaH_setint(L, h, last--), val);
- luaC_barriert(L, h, val);
+ luaC_barrierback(L, obj2gco(h), val);
}
L->top = ci->top; /* correct top (in case of previous open call) */
)
@@ -729,19 +774,12 @@ void luaV_execute (lua_State *L) {
luaF_close(L, ra);
)
vmcase(OP_CLOSURE,
- Proto *p = cl->p->p[GETARG_Bx(i)]; /* prototype for new closure */
- int nup = p->sizeupvalues;
- Closure *ncl = luaF_newLclosure(L, nup);
- Upvaldesc *uv = p->upvalues;
- int j;
- ncl->l.p = p;
- setclvalue(L, ra, ncl); /* anchor new closure in stack */
- for (j = 0; j < nup; j++) { /* fill in upvalues */
- if (uv[j].instack) /* upvalue refers to local variable? */
- ncl->l.upvals[j] = luaF_findupval(L, base + uv[j].idx);
- else /* get upvalue from enclosing function */
- ncl->l.upvals[j] = cl->upvals[uv[j].idx];
- }
+ Proto *p = cl->p->p[GETARG_Bx(i)];
+ Closure *ncl = getcached(p, cl->upvals, base); /* cached closure */
+ if (ncl == NULL) /* no match? */
+ pushclosure(L, p, cl->upvals, base, ra); /* create a new one */
+ else
+ setclvalue(L, ra, ncl); /* push cashed closure */
checkGC(L);
)
vmcase(OP_VARARG,
diff --git a/src/print.c b/src/print.c
index 6a5b05db..83a1cd68 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,5 +1,5 @@
/*
-** $Id: print.c,v 1.60 2010/05/17 22:27:10 lhf Exp $
+** $Id: print.c,v 1.61 2010/07/31 11:34:07 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
*/
@@ -71,6 +71,8 @@ static void PrintConstant(const Proto* f, int i)
}
}
+#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
+
static void PrintCode(const Proto* f)
{
const Instruction* code=f->code;
@@ -116,14 +118,14 @@ static void PrintCode(const Proto* f)
break;
case OP_GETUPVAL:
case OP_SETUPVAL:
- printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b].name) : "-");
+ printf("\t; %s", UPVALNAME(b));
break;
case OP_GETTABUP:
- printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b].name) : "-");
+ printf("\t; %s", UPVALNAME(b));
if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
break;
case OP_SETTABUP:
- printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[a].name) : "-");
+ printf("\t; %s", UPVALNAME(a));
if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
break;