Revision: 9512 http://pure-data.svn.sourceforge.net/pure-data/?rev=9512&view=rev Author: eighthave Date: 2008-02-24 14:39:13 -0800 (Sun, 24 Feb 2008)
Log Message: ----------- importing lua-5.1.3.tar.gz
Added Paths: ----------- vendor/lua/ vendor/lua/current/ vendor/lua/current/COPYRIGHT vendor/lua/current/HISTORY vendor/lua/current/INSTALL vendor/lua/current/Makefile vendor/lua/current/README vendor/lua/current/doc/ vendor/lua/current/doc/amazon.gif vendor/lua/current/doc/contents.html vendor/lua/current/doc/cover.png vendor/lua/current/doc/logo.gif vendor/lua/current/doc/lua.1 vendor/lua/current/doc/lua.css vendor/lua/current/doc/lua.html vendor/lua/current/doc/luac.1 vendor/lua/current/doc/luac.html vendor/lua/current/doc/manual.css vendor/lua/current/doc/manual.html vendor/lua/current/doc/readme.html vendor/lua/current/etc/ vendor/lua/current/etc/Makefile vendor/lua/current/etc/README vendor/lua/current/etc/all.c vendor/lua/current/etc/lua.hpp vendor/lua/current/etc/lua.ico vendor/lua/current/etc/lua.pc vendor/lua/current/etc/luavs.bat vendor/lua/current/etc/min.c vendor/lua/current/etc/noparser.c vendor/lua/current/etc/strict.lua vendor/lua/current/src/ vendor/lua/current/src/Makefile vendor/lua/current/src/lapi.c vendor/lua/current/src/lapi.h vendor/lua/current/src/lauxlib.c vendor/lua/current/src/lauxlib.h vendor/lua/current/src/lbaselib.c vendor/lua/current/src/lcode.c vendor/lua/current/src/lcode.h vendor/lua/current/src/ldblib.c vendor/lua/current/src/ldebug.c vendor/lua/current/src/ldebug.h vendor/lua/current/src/ldo.c vendor/lua/current/src/ldo.h vendor/lua/current/src/ldump.c vendor/lua/current/src/lfunc.c vendor/lua/current/src/lfunc.h vendor/lua/current/src/lgc.c vendor/lua/current/src/lgc.h vendor/lua/current/src/linit.c vendor/lua/current/src/liolib.c vendor/lua/current/src/llex.c vendor/lua/current/src/llex.h vendor/lua/current/src/llimits.h vendor/lua/current/src/lmathlib.c vendor/lua/current/src/lmem.c vendor/lua/current/src/lmem.h vendor/lua/current/src/loadlib.c vendor/lua/current/src/lobject.c vendor/lua/current/src/lobject.h vendor/lua/current/src/lopcodes.c vendor/lua/current/src/lopcodes.h vendor/lua/current/src/loslib.c vendor/lua/current/src/lparser.c vendor/lua/current/src/lparser.h vendor/lua/current/src/lstate.c vendor/lua/current/src/lstate.h vendor/lua/current/src/lstring.c vendor/lua/current/src/lstring.h vendor/lua/current/src/lstrlib.c vendor/lua/current/src/ltable.c vendor/lua/current/src/ltable.h vendor/lua/current/src/ltablib.c vendor/lua/current/src/ltm.c vendor/lua/current/src/ltm.h vendor/lua/current/src/lua.c vendor/lua/current/src/lua.h vendor/lua/current/src/luac.c vendor/lua/current/src/luaconf.h vendor/lua/current/src/lualib.h vendor/lua/current/src/lundump.c vendor/lua/current/src/lundump.h vendor/lua/current/src/lvm.c vendor/lua/current/src/lvm.h vendor/lua/current/src/lzio.c vendor/lua/current/src/lzio.h vendor/lua/current/src/print.c vendor/lua/current/test/ vendor/lua/current/test/README vendor/lua/current/test/bisect.lua vendor/lua/current/test/cf.lua vendor/lua/current/test/echo.lua vendor/lua/current/test/env.lua vendor/lua/current/test/factorial.lua vendor/lua/current/test/fib.lua vendor/lua/current/test/fibfor.lua vendor/lua/current/test/globals.lua vendor/lua/current/test/hello.lua vendor/lua/current/test/life.lua vendor/lua/current/test/luac.lua vendor/lua/current/test/printf.lua vendor/lua/current/test/readonly.lua vendor/lua/current/test/sieve.lua vendor/lua/current/test/sort.lua vendor/lua/current/test/table.lua vendor/lua/current/test/trace-calls.lua vendor/lua/current/test/trace-globals.lua vendor/lua/current/test/xd.lua
Added: vendor/lua/current/COPYRIGHT =================================================================== --- vendor/lua/current/COPYRIGHT (rev 0) +++ vendor/lua/current/COPYRIGHT 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,34 @@ +Lua License +----------- + +Lua is licensed under the terms of the MIT license reproduced below. +This means that Lua is free software and can be used for both academic +and commercial purposes at absolutely no cost. + +For details and rationale, see http://www.lua.org/license.html . + +=============================================================================== + +Copyright (C) 1994-2008 Lua.org, PUC-Rio. + +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: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +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 +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. + +=============================================================================== + +(end of COPYRIGHT)
Added: vendor/lua/current/HISTORY =================================================================== --- vendor/lua/current/HISTORY (rev 0) +++ vendor/lua/current/HISTORY 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,183 @@ +HISTORY for Lua 5.1 + +* Changes from version 5.0 to 5.1 + ------------------------------- + Language: + + new module system. + + new semantics for control variables of fors. + + new semantics for setn/getn. + + new syntax/semantics for varargs. + + new long strings and comments. + + new `mod' operator (`%') + + new length operator #t + + metatables for all types + API: + + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer. + + user supplies memory allocator (lua_open becomes lua_newstate). + + luaopen_* functions must be called through Lua. + Implementation: + + new configuration scheme via luaconf.h. + + incremental garbage collection. + + better handling of end-of-line in the lexer. + + fully reentrant parser (new Lua function `load') + + better support for 64-bit machines. + + native loadlib support for Mac OS X. + + standard distribution in only one library (lualib.a merged into lua.a) + +* Changes from version 4.0 to 5.0 + ------------------------------- + Language: + + lexical scoping. + + Lua coroutines. + + standard libraries now packaged in tables. + + tags replaced by metatables and tag methods replaced by metamethods, + stored in metatables. + + proper tail calls. + + each function can have its own global table, which can be shared. + + new __newindex metamethod, called when we insert a new key into a table. + + new block comments: --[[ ... ]]. + + new generic for. + + new weak tables. + + new boolean type. + + new syntax "local function". + + (f()) returns the first value returned by f. + + {f()} fills a table with all values returned by f. + + \n ignored in [[\n . + + fixed and-or priorities. + + more general syntax for function definition (e.g. function a.x.y:f()...end). + + more general syntax for function calls (e.g. (print or write)(9)). + + new functions (time/date, tmpfile, unpack, require, load*, etc.). + API: + + chunks are loaded by using lua_load; new luaL_loadfile and luaL_loadbuffer. + + introduced lightweight userdata, a simple "void*" without a metatable. + + new error handling protocol: the core no longer prints error messages; + all errors are reported to the caller on the stack. + + new lua_atpanic for host cleanup. + + new, signal-safe, hook scheme. + Implementation: + + new license: MIT. + + new, faster, register-based virtual machine. + + support for external multithreading and coroutines. + + new and consistent error message format. + + the core no longer needs "stdio.h" for anything (except for a single + use of sprintf to convert numbers to strings). + + lua.c now runs the environment variable LUA_INIT, if present. It can + be "@filename", to run a file, or the chunk itself. + + support for user extensions in lua.c. + sample implementation given for command line editing. + + new dynamic loading library, active by default on several platforms. + + safe garbage-collector metamethods. + + precompiled bytecodes checked for integrity (secure binary dostring). + + strings are fully aligned. + + position capture in string.find. + + read('*l') can read lines with embedded zeros. + +* Changes from version 3.2 to 4.0 + ------------------------------- + Language: + + new "break" and "for" statements (both numerical and for tables). + + uniform treatment of globals: globals are now stored in a Lua table. + + improved error messages. + + no more '$debug': full speed *and* full debug information. + + new read form: read(N) for next N bytes. + + general read patterns now deprecated. + (still available with -DCOMPAT_READPATTERNS.) + + all return values are passed as arguments for the last function + (old semantics still available with -DLUA_COMPAT_ARGRET) + + garbage collection tag methods for tables now deprecated. + + there is now only one tag method for order. + API: + + New API: fully re-entrant, simpler, and more efficient. + + New debug API. + Implementation: + + faster than ever: cleaner virtual machine and new hashing algorithm. + + non-recursive garbage-collector algorithm. + + reduced memory usage for programs with many strings. + + improved treatment for memory allocation errors. + + improved support for 16-bit machines (we hope). + + code now compiles unmodified as both ANSI C and C++. + + numbers in bases other than 10 are converted using strtoul. + + new -f option in Lua to support #! scripts. + + luac can now combine text and binaries. + +* Changes from version 3.1 to 3.2 + ------------------------------- + + redirected all output in Lua's core to _ERRORMESSAGE and _ALERT. + + increased limit on the number of constants and globals per function + (from 2^16 to 2^24). + + debugging info (lua_debug and hooks) moved into lua_state and new API + functions provided to get and set this info. + + new debug lib gives full debugging access within Lua. + + new table functions "foreachi", "sort", "tinsert", "tremove", "getn". + + new io functions "flush", "seek". + +* Changes from version 3.0 to 3.1 + ------------------------------- + + NEW FEATURE: anonymous functions with closures (via "upvalues"). + + new syntax: + - local variables in chunks. + - better scope control with DO block END. + - constructors can now be also written: { record-part; list-part }. + - more general syntax for function calls and lvalues, e.g.: + f(x).y=1 + o:f(x,y):g(z) + f"string" is sugar for f("string") + + strings may now contain arbitrary binary data (e.g., embedded zeros). + + major code re-organization and clean-up; reduced module interdependecies. + + no arbitrary limits on the total number of constants and globals. + + support for multiple global contexts. + + better syntax error messages. + + new traversal functions "foreach" and "foreachvar". + + the default for numbers is now double. + changing it to use floats or longs is easy. + + complete debug information stored in pre-compiled chunks. + + sample interpreter now prompts user when run interactively, and also + handles control-C interruptions gracefully. + +* Changes from version 2.5 to 3.0 + ------------------------------- + + NEW CONCEPT: "tag methods". + Tag methods replace fallbacks as the meta-mechanism for extending the + semantics of Lua. Whereas fallbacks had a global nature, tag methods + work on objects having the same tag (e.g., groups of tables). + Existing code that uses fallbacks should work without change. + + new, general syntax for constructors {[exp] = exp, ... }. + + support for handling variable number of arguments in functions (varargs). + + support for conditional compilation ($if ... $else ... $end). + + cleaner semantics in API simplifies host code. + + better support for writing libraries (auxlib.h). + + better type checking and error messages in the standard library. + + luac can now also undump. + +* Changes from version 2.4 to 2.5 + ------------------------------- + + io and string libraries are now based on pattern matching; + the old libraries are still available for compatibility + + dofile and dostring can now return values (via return statement) + + better support for 16- and 64-bit machines + + expanded documentation, with more examples + +* Changes from version 2.2 to 2.4 + ------------------------------- + + external compiler creates portable binary files that can be loaded faster + + interface for debugging and profiling + + new "getglobal" fallback + + new functions for handling references to Lua objects + + new functions in standard lib + + only one copy of each string is stored + + expanded documentation, with more examples + +* Changes from version 2.1 to 2.2 + ------------------------------- + + functions now may be declared with any "lvalue" as a name + + garbage collection of functions + + support for pipes + +* Changes from version 1.1 to 2.1 + ------------------------------- + + object-oriented support + + fallbacks + + simplified syntax for tables + + many internal improvements + +(end of HISTORY)
Added: vendor/lua/current/INSTALL =================================================================== --- vendor/lua/current/INSTALL (rev 0) +++ vendor/lua/current/INSTALL 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,99 @@ +INSTALL for Lua 5.1 + +* Building Lua + ------------ + Lua is built in the src directory, but the build process can be + controlled from the top-level Makefile. + + Building Lua on Unix systems should be very easy. First do "make" and + see if your platform is listed. If so, just do "make xxx", where xxx + is your platform name. The platforms currently supported are: + aix ansi bsd freebsd generic linux macosx mingw posix solaris + + If your platform is not listed, try the closest one or posix, generic, + ansi, in this order. + + See below for customization instructions and for instructions on how + to build with other Windows compilers. + + If you want to check that Lua has been built correctly, do "make test" + after building Lua. Also, have a look at the example programs in test. + +* Installing Lua + -------------- + Once you have built Lua, you may want to install it in an official + place in your system. In this case, do "make install". The official + place and the way to install files are defined in Makefile. You must + have the right permissions to install files. + + If you want to build and install Lua in one step, do "make xxx install", + where xxx is your platform name. + + If you want to install Lua locally, then do "make local". This will + create directories bin, include, lib, man, and install Lua there as + follows: + + bin: lua luac + include: lua.h luaconf.h lualib.h lauxlib.h lua.hpp + lib: liblua.a + man/man1: lua.1 luac.1 + + These are the only directories you need for development. + + There are man pages for lua and luac, in both nroff and html, and a + reference manual in html in doc, some sample code in test, and some + useful stuff in etc. You don't need these directories for development. + + If you want to install Lua locally, but in some other directory, do + "make install INSTALL_TOP=xxx", where xxx is your chosen directory. + + See below for instructions for Windows and other systems. + +* Customization + ------------- + Three things can be customized by editing a file: + - Where and how to install Lua -- edit Makefile. + - How to build Lua -- edit src/Makefile. + - Lua features -- edit src/luaconf.h. + + You don't actually need to edit the Makefiles because you may set the + relevant variables when invoking make. + + On the other hand, if you need to select some Lua features, you'll need + to edit src/luaconf.h. The edited file will be the one installed, and + it will be used by any Lua clients that you build, to ensure consistency. + + We strongly recommend that you enable dynamic loading. This is done + automatically for all platforms listed above that have this feature + (and also Windows). See src/luaconf.h and also src/Makefile. + +* Building Lua on Windows and other systems + ----------------------------------------- + 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: + + library: lapi.c lcode.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 ldblib.c liolib.c lmathlib.c loslib.c + ltablib.c lstrlib.c loadlib.c linit.c + + interpreter: library, lua.c + + compiler: library, luac.c print.c + + If you use Visual Studio .NET, you can use etc/luavs.bat in its + "Command Prompt". + + 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 etc/all.c. + + To use Lua as a library in your own programs, you'll need to know how to + create and use libraries with your compiler. + + As mentioned above, you may edit luaconf.h to select some features before + building Lua. + +(end of INSTALL)
Added: vendor/lua/current/Makefile =================================================================== --- vendor/lua/current/Makefile (rev 0) +++ vendor/lua/current/Makefile 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,120 @@ +# makefile for installing Lua +# see INSTALL for installation instructions +# see src/Makefile and src/luaconf.h for further customization + +# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= + +# Your platform. See PLATS for possible values. +PLAT= none + +# Where to install. The installation starts in the src directory, so take care +# if INSTALL_TOP is not an absolute path. (Man pages are installed from the +# doc directory.) You may want to make these paths consistent with LUA_ROOT, +# LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc). +# +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 +INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V +INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V + +# How to install. If you don't have "install" (unlikely) then get install-sh at +# http://dev.w3.org/cvsweb/libwww/config/install-sh +# or use cp instead. +INSTALL_EXEC= $(INSTALL) -p -m 0755 +INSTALL_DATA= $(INSTALL) -p -m 0644 + +# Utilities. +INSTALL= install +MKDIR= mkdir + +# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= + +# Convenience platforms targets. +PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris + +# What to install. +TO_BIN= lua luac +TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp +TO_LIB= liblua.a +TO_MAN= lua.1 luac.1 + +# Lua version and release. +V= 5.1 +R= 5.1.3 + +all: $(PLAT) + +$(PLATS) clean: + cd src && $(MAKE) $@ + +test: dummy + src/lua test/hello.lua + +install: dummy + cd src && $(MKDIR) -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) + cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) + cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) + cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) + cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) + +local: + $(MAKE) install INSTALL_TOP=.. + +none: + @echo "Please do" + @echo " make PLATFORM" + @echo "where PLATFORM is one of these:" + @echo " $(PLATS)" + @echo "See INSTALL for complete instructions." + +# make may get confused with test/ and INSTALL in a case-insensitive OS +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" + +# 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 + +# (end of Makefile)
Added: vendor/lua/current/README =================================================================== --- vendor/lua/current/README (rev 0) +++ vendor/lua/current/README 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,37 @@ +README for Lua 5.1 + +See INSTALL for installation instructions. +See HISTORY for a summary of changes since the last released version. + +* What is Lua? + ------------ + Lua is a powerful, light-weight programming language designed for extending + applications. Lua is also frequently used as a general-purpose, stand-alone + language. Lua is free software. + + For complete information, visit Lua's web site at http://www.lua.org/ . + For an executive summary, see http://www.lua.org/about.html . + + Lua has been used in many different projects around the world. + For a short list, see http://www.lua.org/uses.html . + +* Availability + ------------ + Lua is freely available for both academic and commercial purposes. + See COPYRIGHT and http://www.lua.org/license.html for details. + Lua can be downloaded at http://www.lua.org/download.html . + +* Installation + ------------ + Lua is implemented in pure ANSI C, and compiles unmodified in all known + platforms that have an ANSI C compiler. In most Unix-like platforms, simply + do "make" with a suitable target. See INSTALL for detailed instructions. + +* Origin + ------ + Lua is developed at Lua.org, a laboratory of the Department of Computer + Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro + in Brazil). + For more information about the authors, see http://www.lua.org/authors.html . + +(end of README)
Added: vendor/lua/current/doc/amazon.gif =================================================================== (Binary files differ)
Property changes on: vendor/lua/current/doc/amazon.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
Added: vendor/lua/current/doc/contents.html =================================================================== --- vendor/lua/current/doc/contents.html (rev 0) +++ vendor/lua/current/doc/contents.html 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,499 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<HTML> +<HEAD> +<TITLE>Lua 5.1 Reference Manual - contents</TITLE> +<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css"> +<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1"> +<STYLE TYPE="text/css"> +ul { + list-style-type: none ; + list-style-position: outside ; +} +</STYLE> +</HEAD> + +<BODY> + +<HR> +<H1> +<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A> +Lua 5.1 Reference Manual +</H1> + +This is an online version of +<BLOCKQUOTE> +<A HREF="http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20"> +<IMG SRC="cover.png" ALT="" TITLE="buy from Amazon" BORDER=1 ALIGN="left" HSPACE=12> +</A> +<B>Lua 5.1 Reference Manual</B> +<BR>by R. Ierusalimschy, L. H. de Figueiredo, W. Celes +<BR>Lua.org, August 2006 +<BR>ISBN 85-903798-3-3 +<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20"> +<IMG SRC="amazon.gif" ALT="[Buy from Amazon]" BORDER=0></A> +<BR CLEAR="all"> +</BLOCKQUOTE> +<P> + +Buy a copy of this book and +<A HREF="http://www.lua.org/donations.html">help to support</A> +the Lua project. +<P> + +The reference manual is the official definition of the Lua language. +For a complete introduction to Lua programming, see the book +<A HREF="http://www.lua.org/docs.html#books">Programming in Lua</A>. +<P> + +<A HREF="manual.html">start</A> +· +<A HREF="#contents">contents</A> +· +<A HREF="#index">index</A> +· +<A HREF="http://www.lua.org/manual/5.1/pt/">portugu\xEAs</A> +· +<A HREF="http://www.lua.org/manual/5.1/es/">espa\xF1ol</A> +<HR> +<SMALL> +Copyright © 2006-2008 Lua.org, PUC-Rio. +Freely available under the terms of the +<a href="http://www.lua.org/license.html#5">Lua license</a>. +</SMALL> +<P> + +<H2><A NAME="contents">Contents</A></H2> +<UL style="padding: 0"> +<LI><A HREF="manual.html">1 - Introduction</A> +<P> +<LI><A HREF="manual.html#2">2 - The Language</A> +<UL> +<LI><A HREF="manual.html#2.1">2.1 - Lexical Conventions</A> +<LI><A HREF="manual.html#2.2">2.2 - Values and Types</A> +<UL> +<LI><A HREF="manual.html#2.2.1">2.2.1 - Coercion</A> +</UL> +<LI><A HREF="manual.html#2.3">2.3 - Variables</A> +<LI><A HREF="manual.html#2.4">2.4 - Statements</A> +<UL> +<LI><A HREF="manual.html#2.4.1">2.4.1 - Chunks</A> +<LI><A HREF="manual.html#2.4.2">2.4.2 - Blocks</A> +<LI><A HREF="manual.html#2.4.3">2.4.3 - Assignment</A> +<LI><A HREF="manual.html#2.4.4">2.4.4 - Control Structures</A> +<LI><A HREF="manual.html#2.4.5">2.4.5 - For Statement</A> +<LI><A HREF="manual.html#2.4.6">2.4.6 - Function Calls as Statements</A> +<LI><A HREF="manual.html#2.4.7">2.4.7 - Local Declarations</A> +</UL> +<LI><A HREF="manual.html#2.5">2.5 - Expressions</A> +<UL> +<LI><A HREF="manual.html#2.5.1">2.5.1 - Arithmetic Operators</A> +<LI><A HREF="manual.html#2.5.2">2.5.2 - Relational Operators</A> +<LI><A HREF="manual.html#2.5.3">2.5.3 - Logical Operators</A> +<LI><A HREF="manual.html#2.5.4">2.5.4 - Concatenation</A> +<LI><A HREF="manual.html#2.5.5">2.5.5 - The Length Operator</A> +<LI><A HREF="manual.html#2.5.6">2.5.6 - Precedence</A> +<LI><A HREF="manual.html#2.5.7">2.5.7 - Table Constructors</A> +<LI><A HREF="manual.html#2.5.8">2.5.8 - Function Calls</A> +<LI><A HREF="manual.html#2.5.9">2.5.9 - Function Definitions</A> +</UL> +<LI><A HREF="manual.html#2.6">2.6 - Visibility Rules</A> +<LI><A HREF="manual.html#2.7">2.7 - Error Handling</A> +<LI><A HREF="manual.html#2.8">2.8 - Metatables</A> +<LI><A HREF="manual.html#2.9">2.9 - Environments</A> +<LI><A HREF="manual.html#2.10">2.10 - Garbage Collection</A> +<UL> +<LI><A HREF="manual.html#2.10.1">2.10.1 - Garbage-Collection Metamethods</A> +<LI><A HREF="manual.html#2.10.2">2.10.2 - Weak Tables</A> +</UL> +<LI><A HREF="manual.html#2.11">2.11 - Coroutines</A> +</UL> +<P> +<LI><A HREF="manual.html#3">3 - The Application Program Interface</A> +<UL> +<LI><A HREF="manual.html#3.1">3.1 - The Stack</A> +<LI><A HREF="manual.html#3.2">3.2 - Stack Size</A> +<LI><A HREF="manual.html#3.3">3.3 - Pseudo-Indices</A> +<LI><A HREF="manual.html#3.4">3.4 - C Closures</A> +<LI><A HREF="manual.html#3.5">3.5 - Registry</A> +<LI><A HREF="manual.html#3.6">3.6 - Error Handling in C</A> +<LI><A HREF="manual.html#3.7">3.7 - Functions and Types</A> +<LI><A HREF="manual.html#3.8">3.8 - The Debug Interface</A> +</UL> +<P> +<LI><A HREF="manual.html#4">4 - The Auxiliary Library</A> +<UL> +<LI><A HREF="manual.html#4.1">4.1 - Functions and Types</A> +</UL> +<P> +<LI><A HREF="manual.html#5">5 - Standard Libraries</A> +<UL> +<LI><A HREF="manual.html#5.1">5.1 - Basic Functions</A> +<LI><A HREF="manual.html#5.2">5.2 - Coroutine Manipulation</A> +<LI><A HREF="manual.html#5.3">5.3 - Modules</A> +<LI><A HREF="manual.html#5.4">5.4 - String Manipulation</A> +<UL> +<LI><A HREF="manual.html#5.4.1">5.4.1 - Patterns</A> +</UL> +<LI><A HREF="manual.html#5.5">5.5 - Table Manipulation</A> +<LI><A HREF="manual.html#5.6">5.6 - Mathematical Functions</A> +<LI><A HREF="manual.html#5.7">5.7 - Input and Output Facilities</A> +<LI><A HREF="manual.html#5.8">5.8 - Operating System Facilities</A> +<LI><A HREF="manual.html#5.9">5.9 - The Debug Library</A> +</UL> +<P> +<LI><A HREF="manual.html#6">6 - Lua Stand-alone</A> +<P> +<LI><A HREF="manual.html#7">7 - Incompatibilities with the Previous Version</A> +<UL> +<LI><A HREF="manual.html#7.1">7.1 - Changes in the Language</A> +<LI><A HREF="manual.html#7.2">7.2 - Changes in the Libraries</A> +<LI><A HREF="manual.html#7.3">7.3 - Changes in the API</A> +</UL> +<P> +<LI><A HREF="manual.html#8">8 - The Complete Syntax of Lua</A> +</UL> + +<H2><A NAME="index">Index</A></H2> +<TABLE WIDTH="100%"> +<TR VALIGN="top"> +<TD> +<H3><A NAME="functions">Lua functions</A></H3> +<A HREF="manual.html#pdf-_G">_G</A><BR> +<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR> +<A HREF="manual.html#pdf-assert">assert</A><BR> +<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR> +<A HREF="manual.html#pdf-dofile">dofile</A><BR> +<A HREF="manual.html#pdf-error">error</A><BR> +<A HREF="manual.html#pdf-getfenv">getfenv</A><BR> +<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR> +<A HREF="manual.html#pdf-ipairs">ipairs</A><BR> +<A HREF="manual.html#pdf-load">load</A><BR> +<A HREF="manual.html#pdf-loadfile">loadfile</A><BR> +<A HREF="manual.html#pdf-loadstring">loadstring</A><BR> +<A HREF="manual.html#pdf-module">module</A><BR> +<A HREF="manual.html#pdf-next">next</A><BR> +<A HREF="manual.html#pdf-pairs">pairs</A><BR> +<A HREF="manual.html#pdf-pcall">pcall</A><BR> +<A HREF="manual.html#pdf-print">print</A><BR> +<A HREF="manual.html#pdf-rawequal">rawequal</A><BR> +<A HREF="manual.html#pdf-rawget">rawget</A><BR> +<A HREF="manual.html#pdf-rawset">rawset</A><BR> +<A HREF="manual.html#pdf-require">require</A><BR> +<A HREF="manual.html#pdf-select">select</A><BR> +<A HREF="manual.html#pdf-setfenv">setfenv</A><BR> +<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR> +<A HREF="manual.html#pdf-tonumber">tonumber</A><BR> +<A HREF="manual.html#pdf-tostring">tostring</A><BR> +<A HREF="manual.html#pdf-type">type</A><BR> +<A HREF="manual.html#pdf-unpack">unpack</A><BR> +<A HREF="manual.html#pdf-xpcall">xpcall</A><BR> +<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> + +<A HREF="manual.html#pdf-debug.debug">debug.debug</A><BR> +<A HREF="manual.html#pdf-debug.getfenv">debug.getfenv</A><BR> +<A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR> +<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.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> +<A HREF="manual.html#pdf-debug.setupvalue">debug.setupvalue</A><BR> +<A HREF="manual.html#pdf-debug.traceback">debug.traceback</A><BR> + +</TD> +<TD> +<H3> </H3> +<A HREF="manual.html#pdf-file:close">file:close</A><BR> +<A HREF="manual.html#pdf-file:flush">file:flush</A><BR> +<A HREF="manual.html#pdf-file:lines">file:lines</A><BR> +<A HREF="manual.html#pdf-file:read">file:read</A><BR> +<A HREF="manual.html#pdf-file:seek">file:seek</A><BR> +<A HREF="manual.html#pdf-file:setvbuf">file:setvbuf</A><BR> +<A HREF="manual.html#pdf-file:write">file:write</A><BR> +<P> + +<A HREF="manual.html#pdf-io.close">io.close</A><BR> +<A HREF="manual.html#pdf-io.flush">io.flush</A><BR> +<A HREF="manual.html#pdf-io.input">io.input</A><BR> +<A HREF="manual.html#pdf-io.lines">io.lines</A><BR> +<A HREF="manual.html#pdf-io.open">io.open</A><BR> +<A HREF="manual.html#pdf-io.output">io.output</A><BR> +<A HREF="manual.html#pdf-io.popen">io.popen</A><BR> +<A HREF="manual.html#pdf-io.read">io.read</A><BR> +<A HREF="manual.html#pdf-io.stderr">io.stderr</A><BR> +<A HREF="manual.html#pdf-io.stdin">io.stdin</A><BR> +<A HREF="manual.html#pdf-io.stdout">io.stdout</A><BR> +<A HREF="manual.html#pdf-io.tmpfile">io.tmpfile</A><BR> +<A HREF="manual.html#pdf-io.type">io.type</A><BR> +<A HREF="manual.html#pdf-io.write">io.write</A><BR> +<P> + +<A HREF="manual.html#pdf-math.abs">math.abs</A><BR> +<A HREF="manual.html#pdf-math.acos">math.acos</A><BR> +<A HREF="manual.html#pdf-math.asin">math.asin</A><BR> +<A HREF="manual.html#pdf-math.atan">math.atan</A><BR> +<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR> +<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR> +<A HREF="manual.html#pdf-math.cos">math.cos</A><BR> +<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR> +<A HREF="manual.html#pdf-math.deg">math.deg</A><BR> +<A HREF="manual.html#pdf-math.exp">math.exp</A><BR> +<A HREF="manual.html#pdf-math.floor">math.floor</A><BR> +<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR> +<A HREF="manual.html#pdf-math.frexp">math.frexp</A><BR> +<A HREF="manual.html#pdf-math.huge">math.huge</A><BR> +<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR> +<A HREF="manual.html#pdf-math.log">math.log</A><BR> +<A HREF="manual.html#pdf-math.log10">math.log10</A><BR> +<A HREF="manual.html#pdf-math.max">math.max</A><BR> +<A HREF="manual.html#pdf-math.min">math.min</A><BR> +<A HREF="manual.html#pdf-math.modf">math.modf</A><BR> +<A HREF="manual.html#pdf-math.pi">math.pi</A><BR> +<A HREF="manual.html#pdf-math.pow">math.pow</A><BR> +<A HREF="manual.html#pdf-math.rad">math.rad</A><BR> +<A HREF="manual.html#pdf-math.random">math.random</A><BR> +<A HREF="manual.html#pdf-math.randomseed">math.randomseed</A><BR> +<A HREF="manual.html#pdf-math.sin">math.sin</A><BR> +<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR> +<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR> +<A HREF="manual.html#pdf-math.tan">math.tan</A><BR> +<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR> +<P> + +<A HREF="manual.html#pdf-os.clock">os.clock</A><BR> +<A HREF="manual.html#pdf-os.date">os.date</A><BR> +<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR> +<A HREF="manual.html#pdf-os.execute">os.execute</A><BR> +<A HREF="manual.html#pdf-os.exit">os.exit</A><BR> +<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR> +<A HREF="manual.html#pdf-os.remove">os.remove</A><BR> +<A HREF="manual.html#pdf-os.rename">os.rename</A><BR> +<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR> +<A HREF="manual.html#pdf-os.time">os.time</A><BR> +<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR> +<P> + +<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR> +<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR> +<A HREF="manual.html#pdf-package.loaders">package.loaders</A><BR> +<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR> +<A HREF="manual.html#pdf-package.path">package.path</A><BR> +<A HREF="manual.html#pdf-package.preload">package.preload</A><BR> +<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR> +<P> + +<A HREF="manual.html#pdf-string.byte">string.byte</A><BR> +<A HREF="manual.html#pdf-string.char">string.char</A><BR> +<A HREF="manual.html#pdf-string.dump">string.dump</A><BR> +<A HREF="manual.html#pdf-string.find">string.find</A><BR> +<A HREF="manual.html#pdf-string.format">string.format</A><BR> +<A HREF="manual.html#pdf-string.gmatch">string.gmatch</A><BR> +<A HREF="manual.html#pdf-string.gsub">string.gsub</A><BR> +<A HREF="manual.html#pdf-string.len">string.len</A><BR> +<A HREF="manual.html#pdf-string.lower">string.lower</A><BR> +<A HREF="manual.html#pdf-string.match">string.match</A><BR> +<A HREF="manual.html#pdf-string.rep">string.rep</A><BR> +<A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR> +<A HREF="manual.html#pdf-string.sub">string.sub</A><BR> +<A HREF="manual.html#pdf-string.upper">string.upper</A><BR> +<P> + +<A HREF="manual.html#pdf-table.concat">table.concat</A><BR> +<A HREF="manual.html#pdf-table.insert">table.insert</A><BR> +<A HREF="manual.html#pdf-table.maxn">table.maxn</A><BR> +<A HREF="manual.html#pdf-table.remove">table.remove</A><BR> +<A HREF="manual.html#pdf-table.sort">table.sort</A><BR> + +</TD> +<TD> +<H3>C API</H3> +<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR> +<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR> +<A HREF="manual.html#lua_Debug">lua_Debug</A><BR> +<A HREF="manual.html#lua_Hook">lua_Hook</A><BR> +<A HREF="manual.html#lua_Integer">lua_Integer</A><BR> +<A HREF="manual.html#lua_Number">lua_Number</A><BR> +<A HREF="manual.html#lua_Reader">lua_Reader</A><BR> +<A HREF="manual.html#lua_State">lua_State</A><BR> +<A HREF="manual.html#lua_Writer">lua_Writer</A><BR> +<P> + +<A HREF="manual.html#lua_atpanic">lua_atpanic</A><BR> +<A HREF="manual.html#lua_call">lua_call</A><BR> +<A HREF="manual.html#lua_checkstack">lua_checkstack</A><BR> +<A HREF="manual.html#lua_close">lua_close</A><BR> +<A HREF="manual.html#lua_concat">lua_concat</A><BR> +<A HREF="manual.html#lua_cpcall">lua_cpcall</A><BR> +<A HREF="manual.html#lua_createtable">lua_createtable</A><BR> +<A HREF="manual.html#lua_dump">lua_dump</A><BR> +<A HREF="manual.html#lua_equal">lua_equal</A><BR> +<A HREF="manual.html#lua_error">lua_error</A><BR> +<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_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> +<A HREF="manual.html#lua_gethookcount">lua_gethookcount</A><BR> +<A HREF="manual.html#lua_gethookmask">lua_gethookmask</A><BR> +<A HREF="manual.html#lua_getinfo">lua_getinfo</A><BR> +<A HREF="manual.html#lua_getlocal">lua_getlocal</A><BR> +<A HREF="manual.html#lua_getmetatable">lua_getmetatable</A><BR> +<A HREF="manual.html#lua_getstack">lua_getstack</A><BR> +<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_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> +<A HREF="manual.html#lua_isfunction">lua_isfunction</A><BR> +<A HREF="manual.html#lua_islightuserdata">lua_islightuserdata</A><BR> +<A HREF="manual.html#lua_isnil">lua_isnil</A><BR> +<A HREF="manual.html#lua_isnone">lua_isnone</A><BR> +<A HREF="manual.html#lua_isnoneornil">lua_isnoneornil</A><BR> +<A HREF="manual.html#lua_isnumber">lua_isnumber</A><BR> +<A HREF="manual.html#lua_isstring">lua_isstring</A><BR> +<A HREF="manual.html#lua_istable">lua_istable</A><BR> +<A HREF="manual.html#lua_isthread">lua_isthread</A><BR> +<A HREF="manual.html#lua_isuserdata">lua_isuserdata</A><BR> +<A HREF="manual.html#lua_lessthan">lua_lessthan</A><BR> +<A HREF="manual.html#lua_load">lua_load</A><BR> +<A HREF="manual.html#lua_newstate">lua_newstate</A><BR> +<A HREF="manual.html#lua_newtable">lua_newtable</A><BR> +<A HREF="manual.html#lua_newthread">lua_newthread</A><BR> +<A HREF="manual.html#lua_newuserdata">lua_newuserdata</A><BR> +<A HREF="manual.html#lua_next">lua_next</A><BR> +<A HREF="manual.html#lua_objlen">lua_objlen</A><BR> +<A HREF="manual.html#lua_pcall">lua_pcall</A><BR> +<A HREF="manual.html#lua_pop">lua_pop</A><BR> +<A HREF="manual.html#lua_pushboolean">lua_pushboolean</A><BR> +<A HREF="manual.html#lua_pushcclosure">lua_pushcclosure</A><BR> +<A HREF="manual.html#lua_pushcfunction">lua_pushcfunction</A><BR> +<A HREF="manual.html#lua_pushfstring">lua_pushfstring</A><BR> +<A HREF="manual.html#lua_pushinteger">lua_pushinteger</A><BR> +<A HREF="manual.html#lua_pushlightuserdata">lua_pushlightuserdata</A><BR> +<A HREF="manual.html#lua_pushliteral">lua_pushliteral</A><BR> +<A HREF="manual.html#lua_pushlstring">lua_pushlstring</A><BR> +<A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR> +<A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR> +<A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR> +<A HREF="manual.html#lua_pushthread">lua_pushthread</A><BR> +<A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR> +<A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR> +<A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR> +<A HREF="manual.html#lua_rawget">lua_rawget</A><BR> +<A HREF="manual.html#lua_rawgeti">lua_rawgeti</A><BR> +<A HREF="manual.html#lua_rawset">lua_rawset</A><BR> +<A HREF="manual.html#lua_rawseti">lua_rawseti</A><BR> +<A HREF="manual.html#lua_register">lua_register</A><BR> +<A HREF="manual.html#lua_remove">lua_remove</A><BR> +<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> +<A HREF="manual.html#lua_setlocal">lua_setlocal</A><BR> +<A HREF="manual.html#lua_setmetatable">lua_setmetatable</A><BR> +<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_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_tolstring">lua_tolstring</A><BR> +<A HREF="manual.html#lua_tonumber">lua_tonumber</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> +<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR> +<A HREF="manual.html#lua_type">lua_type</A><BR> +<A HREF="manual.html#lua_typename">lua_typename</A><BR> +<A HREF="manual.html#lua_upvalueindex">lua_upvalueindex</A><BR> +<A HREF="manual.html#lua_xmove">lua_xmove</A><BR> +<A HREF="manual.html#lua_yield">lua_yield</A><BR> + +</TD> +<TD> +<H3>auxiliary library</H3> +<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR> +<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR> +<P> + +<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR> +<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR> +<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR> +<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR> +<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR> +<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR> +<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR> +<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR> +<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR> +<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR> +<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR> +<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR> +<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR> +<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR> +<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR> +<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR> +<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR> +<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR> +<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR> +<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR> +<A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR> +<A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR> +<A HREF="manual.html#luaL_error">luaL_error</A><BR> +<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR> +<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR> +<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR> +<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_newmetatable">luaL_newmetatable</A><BR> +<A HREF="manual.html#luaL_newstate">luaL_newstate</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> +<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR> +<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR> +<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR> +<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR> +<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_typename">luaL_typename</A><BR> +<A HREF="manual.html#luaL_typerror">luaL_typerror</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: +Sat Jan 19 13:24:29 BRST 2008 +</SMALL> +<!-- +Last change: revised for Lua 5.1.3 +--> + +</BODY> +</HTML>
Added: vendor/lua/current/doc/cover.png =================================================================== (Binary files differ)
Property changes on: vendor/lua/current/doc/cover.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
Added: vendor/lua/current/doc/logo.gif =================================================================== (Binary files differ)
Property changes on: vendor/lua/current/doc/logo.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
Added: vendor/lua/current/doc/lua.1 =================================================================== --- vendor/lua/current/doc/lua.1 (rev 0) +++ vendor/lua/current/doc/lua.1 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,163 @@ +." $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ +.TH LUA 1 "$Date: 2006/01/06 16:03:34 $" +.SH NAME +lua - Lua interpreter +.SH SYNOPSIS +.B lua +[ +.I options +] +[ +.I script +[ +.I args +] +] +.SH DESCRIPTION +.B lua +is the stand-alone Lua interpreter. +It loads and executes Lua programs, +either in textual source form or +in precompiled binary form. +(Precompiled binaries are output by +.BR luac , +the Lua compiler.) +.B lua +can be used as a batch interpreter and also interactively. +.LP +The given +.I options +(see below) +are executed and then +the Lua program in file +.I script +is loaded and executed. +The given +.I args +are available to +.I script +as strings in a global table named +.BR arg . +If these arguments contain spaces or other characters special to the shell, +then they should be quoted +(but note that the quotes will be removed by the shell). +The arguments in +.B arg +start at 0, +which contains the string +.RI ' script '. +The index of the last argument is stored in +.BR arg.n . +The arguments given in the command line before +.IR script , +including the name of the interpreter, +are available in negative indices in +.BR arg . +.LP +At the very start, +before even handling the command line, +.B lua +executes the contents of the environment variable +.BR LUA_INIT , +if it is defined. +If the value of +.B LUA_INIT +is of the form +.RI '@ filename ', +then +.I filename +is executed. +Otherwise, the string is assumed to be a Lua statement and is executed. +.LP +Options start with +.B '-' +and are described below. +You can use +.B "'--'" +to signal the end of options. +.LP +If no arguments are given, +then +.B "-v -i" +is assumed when the standard input is a terminal; +otherwise, +.B "-" +is assumed. +.LP +In interactive mode, +.B lua +prompts the user, +reads lines from the standard input, +and executes them as they are read. +If a line does not contain a complete statement, +then a secondary prompt is displayed and +lines are read until a complete statement is formed or +a syntax error is found. +So, one way to interrupt the reading of an incomplete statement is +to force a syntax error: +adding a +.B ';' +in the middle of a statement is a sure way of forcing a syntax error +(except inside multiline strings and comments; these must be closed explicitly). +If a line starts with +.BR '=' , +then +.B lua +displays the values of all the expressions in the remainder of the +line. The expressions must be separated by commas. +The primary prompt is the value of the global variable +.BR _PROMPT , +if this value is a string; +otherwise, the default prompt is used. +Similarly, the secondary prompt is the value of the global variable +.BR _PROMPT2 . +So, +to change the prompts, +set the corresponding variable to a string of your choice. +You can do that after calling the interpreter +or on the command line +(but in this case you have to be careful with quotes +if the prompt string contains a space; otherwise you may confuse the shell.) +The default prompts are "> " and ">> ". +.SH OPTIONS +.TP +.B - +load and execute the standard input as a file, +that is, +not interactively, +even when the standard input is a terminal. +.TP +.BI -e " stat" +execute statement +.IR stat . +You need to quote +.I stat +if it contains spaces, quotes, +or other characters special to the shell. +.TP +.B -i +enter interactive mode after +.I script +is executed. +.TP +.BI -l " name" +call +.BI require(' name ') +before executing +.IR script . +Typically used to load libraries. +.TP +.B -v +show version information. +.SH "SEE ALSO" +.BR luac (1) +.br +http://www.lua.org/ +.SH DIAGNOSTICS +Error messages should be self explanatory. +.SH AUTHORS +R. Ierusalimschy, +L. H. de Figueiredo, +and +W. Celes +." EOF
Added: vendor/lua/current/doc/lua.css =================================================================== --- vendor/lua/current/doc/lua.css (rev 0) +++ vendor/lua/current/doc/lua.css 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,41 @@ +body { + color: #000000 ; + background-color: #FFFFFF ; + font-family: sans-serif ; + text-align: justify ; + margin-right: 20px ; + margin-left: 20px ; +} + +h1, h2, h3, h4 { + font-weight: normal ; + font-style: italic ; +} + +a:link { + color: #000080 ; + background-color: inherit ; + text-decoration: none ; +} + +a:visited { + background-color: inherit ; + text-decoration: none ; +} + +a:link:hover, a:visited:hover { + color: #000080 ; + background-color: #E0E0FF ; +} + +a:link:active, a:visited:active { + color: #FF0000 ; +} + +hr { + border: 0 ; + height: 1px ; + color: #a0a0a0 ; + background-color: #a0a0a0 ; +} +
Added: vendor/lua/current/doc/lua.html =================================================================== --- vendor/lua/current/doc/lua.html (rev 0) +++ vendor/lua/current/doc/lua.html 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,172 @@ +<!-- $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ --> +<HTML> +<HEAD> +<TITLE>LUA man page</TITLE> +<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css"> +</HEAD> + +<BODY BGCOLOR="#FFFFFF"> + +<H2>NAME</H2> +lua - Lua interpreter +<H2>SYNOPSIS</H2> +<B>lua</B> +[ +<I>options</I> +] +[ +<I>script</I> +[ +<I>args</I> +] +] +<H2>DESCRIPTION</H2> +<B>lua</B> +is the stand-alone Lua interpreter. +It loads and executes Lua programs, +either in textual source form or +in precompiled binary form. +(Precompiled binaries are output by +<B>luac</B>, +the Lua compiler.) +<B>lua</B> +can be used as a batch interpreter and also interactively. +<P> +The given +<I>options</I> +(see below) +are executed and then +the Lua program in file +<I>script</I> +is loaded and executed. +The given +<I>args</I> +are available to +<I>script</I> +as strings in a global table named +<B>arg</B>. +If these arguments contain spaces or other characters special to the shell, +then they should be quoted +(but note that the quotes will be removed by the shell). +The arguments in +<B>arg</B> +start at 0, +which contains the string +'<I>script</I>'. +The index of the last argument is stored in +<B>arg.n</B>. +The arguments given in the command line before +<I>script</I>, +including the name of the interpreter, +are available in negative indices in +<B>arg</B>. +<P> +At the very start, +before even handling the command line, +<B>lua</B> +executes the contents of the environment variable +<B>LUA_INIT</B>, +if it is defined. +If the value of +<B>LUA_INIT</B> +is of the form +'@<I>filename</I>', +then +<I>filename</I> +is executed. +Otherwise, the string is assumed to be a Lua statement and is executed. +<P> +Options start with +<B>'-'</B> +and are described below. +You can use +<B>'--'</B> +to signal the end of options. +<P> +If no arguments are given, +then +<B>"-v -i"</B> +is assumed when the standard input is a terminal; +otherwise, +<B>"-"</B> +is assumed. +<P> +In interactive mode, +<B>lua</B> +prompts the user, +reads lines from the standard input, +and executes them as they are read. +If a line does not contain a complete statement, +then a secondary prompt is displayed and +lines are read until a complete statement is formed or +a syntax error is found. +So, one way to interrupt the reading of an incomplete statement is +to force a syntax error: +adding a +<B>';'</B> +in the middle of a statement is a sure way of forcing a syntax error +(except inside multiline strings and comments; these must be closed explicitly). +If a line starts with +<B>'='</B>, +then +<B>lua</B> +displays the values of all the expressions in the remainder of the +line. The expressions must be separated by commas. +The primary prompt is the value of the global variable +<B>_PROMPT</B>, +if this value is a string; +otherwise, the default prompt is used. +Similarly, the secondary prompt is the value of the global variable +<B>_PROMPT2</B>. +So, +to change the prompts, +set the corresponding variable to a string of your choice. +You can do that after calling the interpreter +or on the command line +(but in this case you have to be careful with quotes +if the prompt string contains a space; otherwise you may confuse the shell.) +The default prompts are "> " and ">> ". +<H2>OPTIONS</H2> +<P> +<B>-</B> +load and execute the standard input as a file, +that is, +not interactively, +even when the standard input is a terminal. +<P> +<B>-e </B><I>stat</I> +execute statement +<I>stat</I>. +You need to quote +<I>stat </I> +if it contains spaces, quotes, +or other characters special to the shell. +<P> +<B>-i</B> +enter interactive mode after +<I>script</I> +is executed. +<P> +<B>-l </B><I>name</I> +call +<B>require</B>('<I>name</I>') +before executing +<I>script</I>. +Typically used to load libraries. +<P> +<B>-v</B> +show version information. +<H2>SEE ALSO</H2> +<B>luac</B>(1) +<BR> +<A HREF="http://www.lua.org/">http://www.lua.org/</A> +<H2>DIAGNOSTICS</H2> +Error messages should be self explanatory. +<H2>AUTHORS</H2> +R. Ierusalimschy, +L. H. de Figueiredo, +and +W. Celes +<!-- EOF --> +</BODY> +</HTML>
Added: vendor/lua/current/doc/luac.1 =================================================================== --- vendor/lua/current/doc/luac.1 (rev 0) +++ vendor/lua/current/doc/luac.1 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,136 @@ +." $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ +.TH LUAC 1 "$Date: 2006/01/06 16:03:34 $" +.SH NAME +luac - Lua compiler +.SH SYNOPSIS +.B luac +[ +.I options +] [ +.I filenames +] +.SH DESCRIPTION +.B luac +is the Lua compiler. +It translates programs written in the Lua programming language +into binary files that can be later loaded and executed. +.LP +The main advantages of precompiling chunks are: +faster loading, +protecting source code from accidental user changes, +and +off-line syntax checking. +.LP +Pre-compiling does not imply faster execution +because in Lua chunks are always compiled into bytecodes before being executed. +.B luac +simply allows those bytecodes to be saved in a file for later execution. +.LP +Pre-compiled chunks are not necessarily smaller than the corresponding source. +The main goal in pre-compiling is faster loading. +.LP +The binary files created by +.B luac +are portable only among architectures with the same word size and byte order. +.LP +.B luac +produces a single output file containing the bytecodes +for all source files given. +By default, +the output file is named +.BR luac.out , +but you can change this with the +.B -o +option. +.LP +In the command line, +you can mix +text files containing Lua source and +binary files containing precompiled chunks. +This is useful to combine several precompiled chunks, +even from different (but compatible) platforms, +into a single precompiled chunk. +.LP +You can use +.B "'-'" +to indicate the standard input as a source file +and +.B "'--'" +to signal the end of options +(that is, +all remaining arguments will be treated as files even if they start with +.BR "'-'" ). +.LP +The internal format of the binary files produced by +.B luac +is likely to change when a new version of Lua is released. +So, +save the source files of all Lua programs that you precompile. +.LP +.SH OPTIONS +Options must be separate. +.TP +.B -l +produce a listing of the compiled bytecode for Lua's virtual machine. +Listing bytecodes is useful to learn about Lua's virtual machine. +If no files are given, then +.B luac +loads +.B luac.out +and lists its contents. +.TP +.BI -o " file" +output to +.IR file , +instead of the default +.BR luac.out . +(You can use +.B "'-'" +for standard output, +but not on platforms that open standard output in text mode.) +The output file may be a source file because +all files are loaded before the output file is written. +Be careful not to overwrite precious files. +.TP +.B -p +load files but do not generate any output file. +Used mainly for syntax checking and for testing precompiled chunks: +corrupted files will probably generate errors when loaded. +Lua always performs a thorough integrity test on precompiled chunks. +Bytecode that passes this test is completely safe, +in the sense that it will not break the interpreter. +However, +there is no guarantee that such code does anything sensible. +(None can be given, because the halting problem is unsolvable.) +If no files are given, then +.B luac +loads +.B luac.out +and tests its contents. +No messages are displayed if the file passes the integrity test. +.TP +.B -s +strip debug information before writing the output file. +This saves some space in very large chunks, +but if errors occur when running a stripped chunk, +then the error messages may not contain the full information they usually do. +For instance, +line numbers and names of local variables are lost. +.TP +.B -v +show version information. +.SH FILES +.TP 15 +.B luac.out +default output file +.SH "SEE ALSO" +.BR lua (1) +.br +http://www.lua.org/ +.SH DIAGNOSTICS +Error messages should be self explanatory. +.SH AUTHORS +L. H. de Figueiredo, +R. Ierusalimschy and +W. Celes +." EOF
Added: vendor/lua/current/doc/luac.html =================================================================== --- vendor/lua/current/doc/luac.html (rev 0) +++ vendor/lua/current/doc/luac.html 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,145 @@ +<!-- $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ --> +<HTML> +<HEAD> +<TITLE>LUAC man page</TITLE> +<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css"> +</HEAD> + +<BODY BGCOLOR="#FFFFFF"> + +<H2>NAME</H2> +luac - Lua compiler +<H2>SYNOPSIS</H2> +<B>luac</B> +[ +<I>options</I> +] [ +<I>filenames</I> +] +<H2>DESCRIPTION</H2> +<B>luac</B> +is the Lua compiler. +It translates programs written in the Lua programming language +into binary files that can be later loaded and executed. +<P> +The main advantages of precompiling chunks are: +faster loading, +protecting source code from accidental user changes, +and +off-line syntax checking. +<P> +Precompiling does not imply faster execution +because in Lua chunks are always compiled into bytecodes before being executed. +<B>luac</B> +simply allows those bytecodes to be saved in a file for later execution. +<P> +Precompiled chunks are not necessarily smaller than the corresponding source. +The main goal in precompiling is faster loading. +<P> +The binary files created by +<B>luac</B> +are portable only among architectures with the same word size and byte order. +<P> +<B>luac</B> +produces a single output file containing the bytecodes +for all source files given. +By default, +the output file is named +<B>luac.out</B>, +but you can change this with the +<B>-o</B> +option. +<P> +In the command line, +you can mix +text files containing Lua source and +binary files containing precompiled chunks. +This is useful because several precompiled chunks, +even from different (but compatible) platforms, +can be combined into a single precompiled chunk. +<P> +You can use +<B>'-'</B> +to indicate the standard input as a source file +and +<B>'--'</B> +to signal the end of options +(that is, +all remaining arguments will be treated as files even if they start with +<B>'-'</B>). +<P> +The internal format of the binary files produced by +<B>luac</B> +is likely to change when a new version of Lua is released. +So, +save the source files of all Lua programs that you precompile. +<P> +<H2>OPTIONS</H2> +Options must be separate. +<P> +<B>-l</B> +produce a listing of the compiled bytecode for Lua's virtual machine. +Listing bytecodes is useful to learn about Lua's virtual machine. +If no files are given, then +<B>luac</B> +loads +<B>luac.out</B> +and lists its contents. +<P> +<B>-o </B><I>file</I> +output to +<I>file</I>, +instead of the default +<B>luac.out</B>. +(You can use +<B>'-'</B> +for standard output, +but not on platforms that open standard output in text mode.) +The output file may be a source file because +all files are loaded before the output file is written. +Be careful not to overwrite precious files. +<P> +<B>-p</B> +load files but do not generate any output file. +Used mainly for syntax checking and for testing precompiled chunks: +corrupted files will probably generate errors when loaded. +Lua always performs a thorough integrity test on precompiled chunks. +Bytecode that passes this test is completely safe, +in the sense that it will not break the interpreter. +However, +there is no guarantee that such code does anything sensible. +(None can be given, because the halting problem is unsolvable.) +If no files are given, then +<B>luac</B> +loads +<B>luac.out</B> +and tests its contents. +No messages are displayed if the file passes the integrity test. +<P> +<B>-s</B> +strip debug information before writing the output file. +This saves some space in very large chunks, +but if errors occur when running a stripped chunk, +then the error messages may not contain the full information they usually do. +For instance, +line numbers and names of local variables are lost. +<P> +<B>-v</B> +show version information. +<H2>FILES</H2> +<P> +<B>luac.out</B> +default output file +<H2>SEE ALSO</H2> +<B>lua</B>(1) +<BR> +<A HREF="http://www.lua.org/">http://www.lua.org/</A> +<H2>DIAGNOSTICS</H2> +Error messages should be self explanatory. +<H2>AUTHORS</H2> +L. H. de Figueiredo, +R. Ierusalimschy and +W. Celes +<!-- EOF --> +</BODY> +</HTML>
Added: vendor/lua/current/doc/manual.css =================================================================== --- vendor/lua/current/doc/manual.css (rev 0) +++ vendor/lua/current/doc/manual.css 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,13 @@ +h3 code { + font-family: inherit ; +} + +pre { + font-size: 105% ; +} + +span.apii { + float: right ; + font-family: inherit ; +} +
Added: vendor/lua/current/doc/manual.html =================================================================== --- vendor/lua/current/doc/manual.html (rev 0) +++ vendor/lua/current/doc/manual.html 2008-02-24 22:39:13 UTC (rev 9512) @@ -0,0 +1,8764 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + +<head> +<title>Lua 5.1 Reference Manual</title> +<link rel="stylesheet" href="lua.css"> +<link rel="stylesheet" href="manual.css"> +<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1"> +</head> + +<body> + +<hr> +<h1> +<a href="http://www.lua.org/"><img src="logo.gif" alt="" border="0"></a> +Lua 5.1 Reference Manual +</h1> + +by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes +<p> +<small> +Copyright © 2006-2008 Lua.org, PUC-Rio. +Freely available under the terms of the +<a href="http://www.lua.org/license.html#5">Lua license</a>. +</small> +<hr> +<p> + +<a href="contents.html#contents">contents</A> +· +<a href="contents.html#index">index</A> + +<!-- ====================================================================== --> +<p> + +<!-- $Id: manual.of,v 1.45 2008/01/19 00:17:30 roberto Exp $ --> + + + + +<h1>1 - <a name="1">Introduction</a></h1> + +<p> +Lua is an extension programming language designed to support +general procedural programming with data description +facilities. +It also offers good support for object-oriented programming, +functional programming, and data-driven programming. +Lua is intended to be used as a powerful, light-weight +scripting language for any program that needs one. +Lua is implemented as a library, written in <em>clean</em> C +(that is, in the common subset of ANSI C and C++). + + +<p> +Being an extension language, Lua has no notion of a "main" program: +it only works <em>embedded</em> in a host client, +called the <em>embedding program</em> or simply the <em>host</em>. +This host program can invoke functions to execute a piece of Lua code, +can write and read Lua variables, +and can register C functions to be called by Lua code. +Through the use of C functions, Lua can be augmented to cope with +a wide range of different domains, +thus creating customized programming languages sharing a syntactical framework. +The Lua distribution includes a sample host program called <code>lua</code>, +which uses the Lua library to offer a complete, stand-alone Lua interpreter. + + +<p> +Lua is free software, +and is provided as usual with no guarantees, +as stated in its license. +The implementation described in this manual is available +at Lua's official web site, <code>www.lua.org</code>. + + +<p> +Like any other reference manual, +this document is dry in places. +For a discussion of the decisions behind the design of Lua, +see the technical papers available at Lua's web site. +For a detailed introduction to programming in Lua, +see Roberto's book, <em>Programming in Lua (Second Edition)</em>. + + + +<h1>2 - <a name="2">The Language</a></h1> + +<p> +This section describes the lexis, the syntax, and the semantics of Lua. +In other words, +this section describes +which tokens are valid, +how they can be combined, +and what their combinations mean. + + +<p> +The language constructs will be explained using the usual extended BNF notation, +in which +{<em>a</em>} means 0 or more <em>a</em>'s, and +[<em>a</em>] means an optional <em>a</em>. +Non-terminals are shown like non-terminal, +keywords are shown like <b>kword</b>, +and other terminal symbols are shown like `<b>=</b>´. +The complete syntax of Lua can be found at the end of this manual. + + + +<h2>2.1 - <a name="2.1">Lexical Conventions</a></h2> + +<p> +<em>Names</em> +(also called <em>identifiers</em>) +in Lua can be any string of letters, +digits, and underscores, +not beginning with a digit. +This coincides with the definition of names in most languages. +(The definition of letter depends on the current locale: +any character considered alphabetic by the current locale +can be used in an identifier.) +Identifiers are used to name variables and table fields. + + +<p> +The following <em>keywords</em> are reserved +and cannot be used as names: + + +<pre> + and break do else elseif + end false for function if + in local nil not or + repeat return then true until while +</pre> + +<p> +Lua is a case-sensitive language: +<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code> +are two different, valid names. +As a convention, names starting with an underscore followed by +uppercase letters (such as <code>_VERSION</code>) +are reserved for internal global variables used by Lua. + + +<p> +The following strings denote other tokens: + +<pre> + + - * / % ^ # + == ~= <= >= < > = + ( ) { } [ ] + ; : , . .. ... +</pre> + +<p> +<em>Literal strings</em> +can be delimited by matching single or double quotes, +and can contain the following C-like escape sequences: +'<code>\a</code>' (bell), +'<code>\b</code>' (backspace), +'<code>\f</code>' (form feed), +'<code>\n</code>' (newline), +'<code>\r</code>' (carriage return), +'<code>\t</code>' (horizontal tab), +'<code>\v</code>' (vertical tab), +'<code>\</code>' (backslash), +'<code>"</code>' (quotation mark [double quote]), +and '<code>'</code>' (apostrophe [single quote]). +Moreover, a backslash followed by a real newline +results in a newline in the string. +A character in a string may also be specified by its numerical value +using the escape sequence <code><em>ddd</em></code>, +where <em>ddd</em> is a sequence of up to three decimal digits. +(Note that if a numerical escape is to be followed by a digit, +it must be expressed using exactly three digits.) +Strings in Lua may contain any 8-bit value, including embedded zeros, +which can be specified as '<code>\0</code>'. + + +<p> +To put a double (single) quote, a newline, a backslash, +a carriage return, +or an embedded zero +inside a literal string enclosed by double (single) quotes +you must use an escape sequence. +Any other character may be directly inserted into the literal. +(Some control characters may cause problems for the file system, +but Lua has no problem with them.) + + +<p> +Literal strings can also be defined using a long format +enclosed by <em>long brackets</em>. +We define an <em>opening long bracket of level <em>n</em></em> as an opening +square bracket followed by <em>n</em> equal signs followed by another +opening square bracket. +So, an opening long bracket of level 0 is written as <code>[[</code>, +an opening long bracket of level 1 is written as <code>[=[</code>, +and so on. +A <em>closing long bracket</em> is defined similarly; +for instance, a closing long bracket of level 4 is written as <code>]====]</code>. +A long string starts with an opening long bracket of any level and +ends at the first closing long bracket of the same level. +Literals in this bracketed form may run for several lines, +do not interpret any escape sequences, +and ignore long brackets of any other level. +They may contain anything except a closing bracket of the proper level. + + +<p> +For convenience, +when the opening long bracket is immediately followed by a newline, +the newline is not included in the string. +As an example, in a system using ASCII +(in which '<code>a</code>' is coded as 97, +newline is coded as 10, and '<code>1</code>' is coded as 49), +the five literals below denote the same string: + +<pre> + a = 'alo\n123"' + a = "alo\n123"" + a = '\97lo\10\04923"' + a = [[alo + 123"]] + a = [==[ + alo + 123"]==] +</pre> + +<p> +A <em>numerical constant</em> may be written with an optional decimal part +and an optional decimal exponent. +Lua also accepts integer hexadecimal constants, +by prefixing them with <code>0x</code>. +Examples of valid numerical constants are + +<pre> + 3 3.0 3.1416 314.16e-2 0.31416E1 0xff 0x56 +</pre> + +<p> +A <em>comment</em> starts with a double hyphen (<code>--</code>) +anywhere outside a string. +If the text immediately after <code>--</code> is not an opening long bracket, +the comment is a <em>short comment</em>, +which runs until the end of the line. +Otherwise, it is a <em>long comment</em>, +which runs until the corresponding closing long bracket. +Long comments are frequently used to disable code temporarily. + + + + + +<h2>2.2 - <a name="2.2">Values and Types</a></h2> + +<p> +Lua is a <em>dynamically typed language</em>. +This means that +variables do not have types; only values do. +There are no type definitions in the language. +All values carry their own type. + + +<p> +All values in Lua are <em>first-class values</em>. +This means that all values can be stored in variables, +passed as arguments to other functions, and returned as results. + + +<p> +There are eight basic types in Lua: +<em>nil</em>, <em>boolean</em>, <em>number</em>, +<em>string</em>, <em>function</em>, <em>userdata</em>, +<em>thread</em>, and <em>table</em>. +<em>Nil</em> is the type of the value <b>nil</b>, +whose main property is to be different from any other value; +it usually represents the absence of a useful value. +<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>. +Both <b>nil</b> and <b>false</b> make a condition false; +any other value makes it true. +<em>Number</em> represents real (double-precision floating-point) numbers. +(It is easy to build Lua interpreters that use other +internal representations for numbers, +such as single-precision float or long integers; +see file <code>luaconf.h</code>.) +<em>String</em> represents arrays of characters. + +Lua is 8-bit clean: +strings may contain any 8-bit character, +including embedded zeros ('<code>\0</code>') (see <a href="#2.1">§2.1</a>). + + +<p> +Lua can call (and manipulate) functions written in Lua and +functions written in C +(see <a href="#2.5.8">§2.5.8</a>). + + +<p> +The type <em>userdata</em> is provided to allow arbitrary C data to +be stored in Lua variables. +This type corresponds to a block of raw memory +and has no pre-defined operations in Lua, +except assignment and identity test. +However, by using <em>metatables</em>, +the programmer can define operations for userdata values +(see <a href="#2.8">§2.8</a>). +Userdata values cannot be created or modified in Lua, +only through the C API. +This guarantees the integrity of data owned by the host program. + + +<p> +The type <em>thread</em> represents independent threads of execution +and it is used to implement coroutines (see <a href="#2.11">§2.11</a>). +Do not confuse Lua threads with operating-system threads. +Lua supports coroutines on all systems, +even those that do not support threads. + + +<p> +The type <em>table</em> implements associative arrays, +that is, arrays that can be indexed not only with numbers, +but with any value (except <b>nil</b>). +Tables can be <em>heterogeneous</em>; +that is, they can contain values of all types (except <b>nil</b>). +Tables are the sole data structuring mechanism in Lua; +they may be used to represent ordinary arrays, +symbol tables, sets, records, graphs, trees, etc. +To represent records, Lua uses the field name as an index. +The language supports this representation by +providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>. +There are several convenient ways to create tables in Lua +(see <a href="#2.5.7">§2.5.7</a>). + + +<p> +Like indices, +the value of a table field can be of any type (except <b>nil</b>). +In particular, +because functions are first-class values, +table fields may contain functions. +Thus tables may also carry <em>methods</em> (see <a href="#2.5.9">§2.5.9</a>). + + +<p> +Tables, functions, threads, and (full) userdata values are <em>objects</em>: +variables do not actually <em>contain</em> these values, +only <em>references</em> to them. +Assignment, parameter passing, and function returns +always manipulate references to such values; +these operations do not imply any kind of copy. + + +<p> +The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type +of a given value. + + + +<h3>2.2.1 - <a name="2.2.1">Coercion</a></h3> + +<p> +Lua provides automatic conversion between +string and number values at run time. +Any arithmetic operation applied to a string tries to convert +this string to a number, following the usual conversion rules. +Conversely, whenever a number is used where a string is expected, +the number is converted to a string, in a reasonable format. +For complete control over how numbers are converted to strings, +use the <code>format</code> function from the string library +(see <a href="#pdf-string.format"><code>string.format</code></a>). + + + + + + + +<h2>2.3 - <a name="2.3">Variables</a></h2> + +<p> +Variables are places that store values. + +There are three kinds of variables in Lua: +global variables, local variables, and table fields. + + +<p> +A single name can denote a global variable or a local variable +(or a function's formal parameter, +which is a particular kind of local variable): + +<pre> + var ::= Name +</pre><p> +Name denotes identifiers, as defined in <a href="#2.1">§2.1</a>. + + +<p> +Any variable is assumed to be global unless explicitly declared +as a local (see <a href="#2.4.7">§2.4.7</a>). +Local variables are <em>lexically scoped</em>: +local variables can be freely accessed by functions +defined inside their scope (see <a href="#2.6">§2.6</a>). + + +<p> +Before the first assignment to a variable, its value is <b>nil</b>. + + +<p> +Square brackets are used to index a table: + +<pre> + var ::= prefixexp `<b>[</b>´ exp `<b>]</b>´ +</pre><p> +The meaning of accesses to global variables +and table fields can be changed via metatables. +An access to an indexed variable <code>t[i]</code> is equivalent to +a call <code>gettable_event(t,i)</code>. +(See <a href="#2.8">§2.8</a> for a complete description of the +<code>gettable_event</code> function. +This function is not defined or callable in Lua. +We use it here only for explanatory purposes.) + + +<p> +The syntax <code>var.Name</code> is just syntactic sugar for +<code>var["Name"]</code>: + +<pre> + var ::= prefixexp `<b>.</b>´ Name +</pre> + +<p> +All global variables live as fields in ordinary Lua tables, +called <em>environment tables</em> or simply +<em>environments</em> (see <a href="#2.9">§2.9</a>). +Each function has its own reference to an environment, +so that all global variables in this function +will refer to this environment table. +When a function is created, +it inherits the environment from the function that created it. +To get the environment table of a Lua function, +you call <a href="#pdf-getfenv"><code>getfenv</code></a>. +To replace it, +you call <a href="#pdf-setfenv"><code>setfenv</code></a>. +(You can only manipulate the environment of C functions +through the debug library; (see <a href="#5.9">§5.9</a>).) + + +<p> +An access to a global variable <code>x</code> +is equivalent to <code>_env.x</code>, +which in turn is equivalent to + +<pre> + gettable_event(_env, "x") +</pre><p> +where <code>_env</code> is the environment of the running function. +(See <a href="#2.8">§2.8</a> for a complete description of the +<code>gettable_event</code> function. +This function is not defined or callable in Lua. +Similarly, the <code>_env</code> variable is not defined in Lua. +We use them here only for explanatory purposes.) + + + + + +<h2>2.4 - <a name="2.4">Statements</a></h2> + +<p> +Lua supports an almost conventional set of statements, +similar to those in Pascal or C. +This set includes +assignment, control structures, function calls, +and variable declarations. + + + +<h3>2.4.1 - <a name="2.4.1">Chunks</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. +Each statement can be optionally followed by a semicolon: + +<pre> + chunk ::= {stat [`<b>;</b>´]} +</pre><p> +There are no empty statements and thus '<code>;;</code>' is not legal. + + +<p> +Lua handles a chunk as the body of an anonymous function +with a variable number of arguments +(see <a href="#2.5.9">§2.5.9</a>). +As such, chunks can define local variables, +receive arguments, and return values. + + +<p> +A chunk may be stored in a file or in a string inside the host program. +When a chunk is executed, first it is pre-compiled into instructions for +a virtual machine, +and then the compiled code is executed +by an interpreter for the virtual machine. + + +<p> +Chunks may also be pre-compiled into binary form; +see program <code>luac</code> for details. +Programs in source and compiled forms are interchangeable; +Lua automatically detects the file type and acts accordingly. + + + + + + +<h3>2.4.2 - <a name="2.4.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 may 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="#2.4.4">§2.4.4</a>). + + + + + +<h3>2.4.3 - <a name="2.4.3">Assignment</a></h3> + +<p> +Lua allows multiple assignment. +Therefore, the syntax for assignment +defines a list of variables on the left side +and a list of expressions on the right side. +The elements in both lists are separated by commas: + +<pre> + stat ::= varlist `<b>=</b>´ explist + varlist ::= var {`<b>,</b>´ var} + explist ::= exp {`<b>,</b>´ exp} +</pre><p> +Expressions are discussed in <a href="#2.5">§2.5</a>. + + +<p> +Before the assignment, +the list of values is <em>adjusted</em> to the length of +the list of variables. +If there are more values than needed, +the excess values are thrown away. +If there are fewer values than needed, +the list is extended with as many <b>nil</b>'s as needed. +If the list of expressions ends with a function call, +then all values returned by this call enter in the list of values, +before the adjustment +(except when the call is enclosed in parentheses; see <a href="#2.5">§2.5</a>). + + +<p> +The assignment statement first evaluates all its expressions +and only then are the assignments performed. +Thus the code + +<pre> + i = 3 + i, a[i] = i+1, 20 +</pre><p> +sets <code>a[3]</code> to 20, without affecting <code>a[4]</code> +because the <code>i</code> in <code>a[i]</code> is evaluated (to 3) +before it is assigned 4. +Similarly, the line + +<pre> + x, y = y, x +</pre><p> +exchanges the values of <code>x</code> and <code>y</code>. + + +<p> +The meaning of assignments to global variables +and table fields can be changed via metatables. +An assignment to an indexed variable <code>t[i] = val</code> is equivalent to +<code>settable_event(t,i,val)</code>. +(See <a href="#2.8">§2.8</a> for a complete description of the +<code>settable_event</code> function. +This function is not defined or callable in Lua. +We use it here only for explanatory purposes.) + + +<p> +An assignment to a global variable <code>x = val</code> +is equivalent to the assignment +<code>_env.x = val</code>, +which in turn is equivalent to + +<pre> + settable_event(_env, "x", val) +</pre><p> +where <code>_env</code> is the environment of the running function. +(The <code>_env</code> variable is not defined in Lua. +We use it here only for explanatory purposes.) + + + + + +<h3>2.4.4 - <a name="2.4.4">Control Structures</a></h3><p> +The control structures +<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and +familiar syntax: + + + + +<pre> + stat ::= <b>while</b> exp <b>do</b> block <b>end</b> + stat ::= <b>repeat</b> block <b>until</b> exp + stat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> +</pre><p> +Lua also has a <b>for</b> statement, in two flavors (see <a href="#2.4.5">§2.4.5</a>). + + +<p> +The condition expression of a +control structure may return any value. +Both <b>false</b> and <b>nil</b> are considered false. +All values different from <b>nil</b> and <b>false</b> are considered true +(in particular, the number 0 and the empty string are also true). + + +<p> +In the <b>repeat</b>–<b>until</b> loop, +the inner block does not end at the <b>until</b> keyword, +but only after the condition. +So, the condition can refer to local variables +declared inside the loop block. + + +<p> +The <b>return</b> statement is used to return values +from a function or a chunk (which is just a function). + +Functions and chunks may return more than one value, +so the syntax for the <b>return</b> statement is + +<pre> + stat ::= <b>return</b> [explist] +</pre> + +<p> +The <b>break</b> statement is used to terminate the execution of a +<b>while</b>, <b>repeat</b>, or <b>for</b> loop, +skipping to the next statement after the loop: + + +<pre> + stat ::= <b>break</b> +</pre><p> +A <b>break</b> ends the innermost enclosing loop. + + +<p> +The <b>return</b> and <b>break</b> +statements can only be written as the <em>last</em> statement of a block. +If it is really necessary to <b>return</b> or <b>break</b> in the +middle of a block, +then an explicit inner block can be used, +as in the idioms +<code>do return end</code> and <code>do break end</code>, +because now <b>return</b> and <b>break</b> are the last statements in +their (inner) blocks. + + + + + +<h3>2.4.5 - <a name="2.4.5">For Statement</a></h3> + +<p> + +The <b>for</b> statement has two forms: +one numeric and one generic. + + +<p> +The numeric <b>for</b> loop repeats a block of code while a +control variable runs through an arithmetic progression. +It has the following syntax: + +<pre> + stat ::= <b>for</b> Name `<b>=</b>´ exp `<b>,</b>´ exp [`<b>,</b>´ exp] <b>do</b> block <b>end</b> +</pre><p> +The <em>block</em> is repeated for <em>name</em> starting at the value of +the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the +third <em>exp</em>. +More precisely, a <b>for</b> statement like + +<pre> + for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end +</pre><p> +is equivalent to the code: + +<pre> + do + local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>) + if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end + while (<em>step</em> > 0 and <em>var</em> <= <em>limit</em>) or (<em>step</em> <= 0 and <em>var</em> >= <em>limit</em>) do + local v = <em>var</em> + <em>block</em> + <em>var</em> = <em>var</em> + <em>step</em> + end + end +</pre><p> +Note the following: + +<ul> + +<li> +All three control expressions are evaluated only once, +before the loop starts. +They must all result in numbers. +</li> + +<li> +<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables. +The names are here for explanatory purposes only. +</li> + +<li> +If the third expression (the step) is absent, +then a step of 1 is used. +</li> + +<li> +You can use <b>break</b> to exit a <b>for</b> loop. +</li> + +<li> +The loop variable <code>v</code> is local to the loop; +you cannot use its value after the <b>for</b> ends or is broken. +If you need this value, +assign it to another variable before breaking or exiting the loop. +</li> + +</ul> + +<p> +The generic <b>for</b> statement works over functions, +called <em>iterators</em>. +On each iteration, the iterator function is called to produce a new value, +stopping when this new value is <b>nil</b>. +The generic <b>for</b> loop has the following syntax: + +<pre> + stat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> + namelist ::= Name {`<b>,</b>´ Name} +</pre><p> +A <b>for</b> statement like + +<pre> + for <em>var_1</em>, ···, <em>var_n</em> in <em>explist</em> do <em>block</em> end +</pre><p> +is equivalent to the code: + +<pre> + do + local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em> + while true do + local <em>var_1</em>, ···, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>) + <em>var</em> = <em>var_1</em> + if <em>var</em> == nil then break end + <em>block</em> + end + end +</pre><p> +Note the following: + +<ul> + +<li> +<code><em>explist</em></code> is evaluated only once. +Its results are an <em>iterator</em> function, +a <em>state</em>, +and an initial value for the first <em>iterator variable</em>. +</li> + +<li> +<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables. +The names are here for explanatory purposes only. +</li> + +<li> +You can use <b>break</b> to exit a <b>for</b> loop. +</li> + +<li> +The loop variables <code><em>var_i</em></code> are local to the loop; +you cannot use their values after the <b>for</b> ends. +If you need these values, +then assign them to other variables before breaking or exiting the loop. +</li> + +</ul> + + + + +<h3>2.4.6 - <a name="2.4.6">Function Calls as Statements</a></h3><p> +To allow possible side-effects, +function calls can be executed as statements: + +<pre> + stat ::= functioncall +</pre><p> +In this case, all returned values are thrown away. +Function calls are explained in <a href="#2.5.8">§2.5.8</a>. + + + + + +<h3>2.4.7 - <a name="2.4.7">Local Declarations</a></h3><p> +Local variables may be declared anywhere inside a block. +The declaration may include an initial assignment: + +<pre> + stat ::= <b>local</b> namelist [`<b>=</b>´ explist] +</pre><p> +If present, an initial assignment has the same semantics +of a multiple assignment (see <a href="#2.4.3">§2.4.3</a>). +Otherwise, all variables are initialized with <b>nil</b>. + + +<p> +A chunk is also a block (see <a href="#2.4.1">§2.4.1</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. + + +<p> +The visibility rules for local variables are explained in <a href="#2.6">§2.6</a>. + + + + + + + +<h2>2.5 - <a name="2.5">Expressions</a></h2> + +<p> +The basic expressions in Lua are the following: + +<pre> + exp ::= prefixexp + exp ::= <b>nil</b> | <b>false</b> | <b>true</b> + exp ::= Number + exp ::= String + exp ::= function + exp ::= tableconstructor + exp ::= `<b>...</b>´ + exp ::= exp binop exp + exp ::= unop exp + prefixexp ::= var | functioncall | `<b>(</b>´ exp `<b>)</b>´ +</pre> + +<p> +Numbers and literal strings are explained in <a href="#2.1">§2.1</a>; +variables are explained in <a href="#2.3">§2.3</a>; +function definitions are explained in <a href="#2.5.9">§2.5.9</a>; +function calls are explained in <a href="#2.5.8">§2.5.8</a>; +table constructors are explained in <a href="#2.5.7">§2.5.7</a>. +Vararg expressions, +denoted by three dots ('<code>...</code>'), can only be used when +directly inside a vararg function; +they are explained in <a href="#2.5.9">§2.5.9</a>. + + +<p> +Binary operators comprise arithmetic operators (see <a href="#2.5.1">§2.5.1</a>), +relational operators (see <a href="#2.5.2">§2.5.2</a>), logical operators (see <a href="#2.5.3">§2.5.3</a>), +and the concatenation operator (see <a href="#2.5.4">§2.5.4</a>). +Unary operators comprise the unary minus (see <a href="#2.5.1">§2.5.1</a>), +the unary <b>not</b> (see <a href="#2.5.3">§2.5.3</a>), +and the unary <em>length operator</em> (see <a href="#2.5.5">§2.5.5</a>). + + +<p> +Both function calls and vararg expressions may result in multiple values. +If the expression is used as a statement (see <a href="#2.4.6">§2.4.6</a>) +(only possible for function calls), +then its return list is adjusted to zero elements, +thus discarding all returned values. +If the expression is used as the last (or the only) element +of a list of expressions, +then no adjustment is made +(unless the call is enclosed in parentheses). +In all other contexts, +Lua adjusts the result list to one element, +discarding all values except the first one. + + +<p> +Here are some examples: + +<pre> + f() -- adjusted to 0 results + g(f(), x) -- f() is adjusted to 1 result + g(x, f()) -- g gets x plus all results from f() + a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil) + a,b = ... -- a gets the first vararg parameter, b gets + -- the second (both a and b may get nil if there + -- is no corresponding vararg parameter) + + a,b,c = x, f() -- f() is adjusted to 2 results + a,b,c = f() -- f() is adjusted to 3 results + return f() -- returns all results from f() + return ... -- returns all received vararg parameters + return x,y,f() -- returns x, y, and all results from f() + {f()} -- creates a list with all results from f() + {...} -- creates a list with all vararg parameters + {f(), nil} -- f() is adjusted to 1 result +</pre> + +<p> +An expression enclosed in parentheses always results in only one value. +Thus, +<code>(f(x,y,z))</code> is always a single value, +even if <code>f</code> returns several values. +(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code> +or <b>nil</b> if <code>f</code> does not return any values.) + + + +<h3>2.5.1 - <a name="2.5.1">Arithmetic Operators</a></h3><p> +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). +If the operands are numbers, or strings that can be converted to +numbers (see <a href="#2.2.1">§2.2.1</a>), +then all operations have the usual meaning. +Exponentiation works for any exponent. +For instance, <code>x^(-0.5)</code> computes the inverse of the square root of <code>x</code>. +Modulo is defined as + +<pre> + a % b == a - math.floor(a/b)*b +</pre><p> +That is, it is the remainder of a division that rounds +the quotient towards minus infinity. + + + + + +<h3>2.5.2 - <a name="2.5.2">Relational Operators</a></h3><p> +The relational operators in Lua are + +<pre> + == ~= < > <= >= +</pre><p> +These operators always result in <b>false</b> or <b>true</b>. + + +<p> +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) +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), +this new object is different from any previously existing object. + + +<p> +You can change the way that Lua compares tables and userdata +by using the "eq" metamethod (see <a href="#2.8">§2.8</a>). + + +<p> +The conversion rules of <a href="#2.2.1">§2.2.1</a> +<em>do not</em> apply to equality comparisons. +Thus, <code>"0"==0</code> evaluates to <b>false</b>, +and <code>t[0]</code> and <code>t["0"]</code> denote different +entries in a table. + + +<p> +The operator <code>~=</code> is exactly the negation of equality (<code>==</code>). + + +<p> +The order operators work as follows. +If both arguments are numbers, then they are compared as such. +Otherwise, if both arguments are strings, +then their values are compared according to the current locale. +Otherwise, Lua tries to call the "lt" or the "le" +metamethod (see <a href="#2.8">§2.8</a>). + + + + + +<h3>2.5.3 - <a name="2.5.3">Logical Operators</a></h3><p> +The logical operators in Lua are +<b>and</b>, <b>or</b>, and <b>not</b>. +Like the control structures (see <a href="#2.4.4">§2.4.4</a>), +all logical operators consider both <b>false</b> and <b>nil</b> as false +and anything else as true. + + +<p> +The negation operator <b>not</b> always returns <b>false</b> or <b>true</b>. +The conjunction operator <b>and</b> returns its first argument +if this value is <b>false</b> or <b>nil</b>; +otherwise, <b>and</b> returns its second argument. +The disjunction operator <b>or</b> returns its first argument +if this value is different from <b>nil</b> and <b>false</b>; +otherwise, <b>or</b> returns its second argument. +Both <b>and</b> and <b>or</b> use short-cut evaluation; +that is, +the second operand is evaluated only if necessary. +Here are some examples: + +<pre> + 10 or 20 --> 10 + 10 or error() --> 10 + nil or "a" --> "a" + nil and 10 --> nil + false and error() --> false + false and nil --> false + false or nil --> nil + 10 and 20 --> 20 +</pre><p> +(In this manual, +--> indicates the result of the preceding expression.) + + + + + +<h3>2.5.4 - <a name="2.5.4">Concatenation</a></h3><p> +The string concatenation operator in Lua is +denoted by two dots ('<code>..</code>'). +If both operands are strings or numbers, then they are converted to +strings according to the rules mentioned in <a href="#2.2.1">§2.2.1</a>. +Otherwise, the "concat" metamethod is called (see <a href="#2.8">§2.8</a>). + + + + + +<h3>2.5.5 - <a name="2.5.5">The Length Operator</a></h3> + +<p> +The length operator is denoted by the unary operator <code>#</code>. +The length of a string is its number of bytes +(that is, the usual meaning of string length when each +character is one byte). + + +<p> +The length of a table <code>t</code> is defined to 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> may be zero. +For a regular array, with non-nil values from 1 to a given <code>n</code>, +its length is exactly that <code>n</code>, +the index of its last value. +If the array has "holes" +(that is, <b>nil</b> values between other non-nil values), +then <code>#t</code> may be any of the indices that +directly precedes a <b>nil</b> value +(that is, it may consider any such <b>nil</b> value as the end of +the array). + + + + + +<h3>2.5.6 - <a name="2.5.6">Precedence</a></h3><p> +Operator precedence in Lua follows the table below, +from lower to higher priority: + +<pre> + or + and + < > <= >= ~= == + .. + + - + * / % + not # - (unary) + ^ +</pre><p> +As usual, +you can use parentheses to change the precedences of an expression. +The concatenation ('<code>..</code>') and exponentiation ('<code>^</code>') +operators are right associative. +All other binary operators are left associative. + + + + + +<h3>2.5.7 - <a name="2.5.7">Table Constructors</a></h3><p> +Table constructors are expressions that create tables. +Every time a constructor is evaluated, a new table is created. +Constructors can be used to create empty tables, +or to create a table and initialize some of its fields. +The general syntax for constructors is + +<pre> + tableconstructor ::= `<b>{</b>´ [fieldlist] `<b>}</b>´ + fieldlist ::= field {fieldsep field} [fieldsep] + field ::= `<b>[</b>´ exp `<b>]</b>´ `<b>=</b>´ exp | Name `<b>=</b>´ exp | exp + fieldsep ::= `<b>,</b>´ | `<b>;</b>´ +</pre> + +<p> +Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry +with key <code>exp1</code> and value <code>exp2</code>. +A field of the form <code>name = exp</code> is equivalent to +<code>["name"] = exp</code>. +Finally, fields of the form <code>exp</code> are equivalent to +<code>[i] = exp</code>, where <code>i</code> are consecutive numerical integers, +starting with 1. +Fields in the other formats do not affect this counting. +For example, + +<pre> + a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } +</pre><p> +is equivalent to + +<pre> + do + local t = {} + t[f(1)] = g + t[1] = "x" -- 1st exp + t[2] = "y" -- 2nd exp + t.x = 1 -- t["x"] = 1 + t[3] = f(x) -- 3rd exp + t[30] = 23 + t[4] = 45 -- 4th exp + a = t + end +</pre> + +<p> +If the last field in the list has the form <code>exp</code> +and the expression is a function call or a vararg expression, +then all values returned by this expression enter the list consecutively +(see <a href="#2.5.8">§2.5.8</a>). +To avoid this, +enclose the function call (or the vararg expression) +in parentheses (see <a href="#2.5">§2.5</a>). + + +<p> +The field list may have an optional trailing separator, +as a convenience for machine-generated code. + + + + + +<h3>2.5.8 - <a name="2.5.8">Function Calls</a></h3><p> +A function call in Lua has the following syntax: + +<pre> + functioncall ::= prefixexp args +</pre><p> +In a function call, +first prefixexp and args are evaluated. +If the value of prefixexp has type <em>function</em>, +then this function is called +with the given arguments. +Otherwise, the prefixexp "call" metamethod is called, +having as first parameter the value of prefixexp, +followed by the original call arguments +(see <a href="#2.8">§2.8</a>). + + +<p> +The form + +<pre> + functioncall ::= prefixexp `<b>:</b>´ Name args +</pre><p> +can be used to call "methods". +A call <code>v:name(<em>args</em>)</code> +is syntactic sugar for <code>v.name(v,<em>args</em>)</code>, +except that <code>v</code> is evaluated only once. + + +<p> +Arguments have the following syntax: + +<pre> + args ::= `<b>(</b>´ [explist] `<b>)</b>´ + args ::= tableconstructor + args ::= String +</pre><p> +All argument expressions are evaluated before the call. +A call of the form <code>f{<em>fields</em>}</code> is +syntactic sugar for <code>f({<em>fields</em>})</code>; +that is, the argument list is a single new table. +A call of the form <code>f'<em>string</em>'</code> +(or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>) +is syntactic sugar for <code>f('<em>string</em>')</code>; +that is, the argument list is a single literal string. + + +<p> +As an exception to the free-format syntax of Lua, +you cannot put a line break before the '<code>(</code>' in a function call. +This restriction avoids some ambiguities in the language. +If you write + +<pre> + a = f + (g).x(a) +</pre><p> +Lua would see that as a single statement, <code>a = f(g).x(a)</code>. +So, if you want two statements, you must add a semi-colon between them. +If you actually want to call <code>f</code>, +you must remove the line break before <code>(g)</code>. + + +<p> +A call of the form <code>return</code> <em>functioncall</em> is called +a <em>tail call</em>. +Lua implements <em>proper tail calls</em> +(or <em>proper tail recursion</em>): +in a tail call, +the called function reuses the stack entry of the calling function. +Therefore, there is no limit on the number of nested tail calls that +a program can execute. +However, a tail call erases any debug information about the +calling function. +Note that a tail call only happens with a particular syntax, +where the <b>return</b> has one single function call as argument; +this syntax makes the calling function return exactly +the returns of the called function. +So, none of the following examples are tail calls: + +<pre> + return (f(x)) -- results adjusted to 1 + return 2 * f(x) + return x, f(x) -- additional results + f(x); return -- results discarded + return x or f(x) -- results adjusted to 1 +</pre> + + + + +<h3>2.5.9 - <a name="2.5.9">Function Definitions</a></h3> + +<p> +The syntax for function definition is + +<pre> + function ::= <b>function</b> funcbody + funcbody ::= `<b>(</b>´ [parlist] `<b>)</b>´ block <b>end</b> +</pre> + +<p> +The following syntactic sugar simplifies function definitions: + +<pre> + stat ::= <b>function</b> funcname funcbody + stat ::= <b>local</b> <b>function</b> Name funcbody
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.