├── COPYRIGHT ├── HISTORY ├── INSTALL ├── Makefile ├── README ├── doc ├── contents.html ├── cover.png ├── logo.gif ├── lua.1 ├── lua.css ├── lua.html ├── luac.1 ├── luac.html ├── manual.css ├── manual.html └── readme.html ├── etc ├── Makefile ├── README ├── all.c ├── lua.hpp ├── lua.ico ├── lua.pc ├── luavs.bat ├── min.c ├── noparser.c └── strict.lua ├── src ├── Makefile ├── lapi.c ├── lapi.h ├── lauxlib.c ├── lauxlib.h ├── lbaselib.c ├── lcode.c ├── lcode.h ├── ldblib.c ├── ldebug.c ├── ldebug.h ├── ldo.c ├── ldo.h ├── ldump.c ├── lfunc.c ├── lfunc.h ├── lgc.c ├── lgc.h ├── linit.c ├── liolib.c ├── llex.c ├── llex.h ├── llimits.h ├── lmathlib.c ├── lmem.c ├── lmem.h ├── loadlib.c ├── lobject.c ├── lobject.h ├── lopcodes.c ├── lopcodes.h ├── loslib.c ├── lparser.c ├── lparser.h ├── lstate.c ├── lstate.h ├── lstring.c ├── lstring.h ├── lstrlib.c ├── ltable.c ├── ltable.h ├── ltablib.c ├── ltm.c ├── ltm.h ├── lua.c ├── lua.h ├── luac.c ├── luaconf.h ├── lualib.h ├── lundump.c ├── lundump.h ├── lvm.c ├── lvm.h ├── lzio.c ├── lzio.h └── print.c └── test ├── README ├── bisect.lua ├── cf.lua ├── echo.lua ├── env.lua ├── factorial.lua ├── fib.lua ├── fibfor.lua ├── globals.lua ├── hello.lua ├── life.lua ├── luac.lua ├── printf.lua ├── readonly.lua ├── sieve.lua ├── sort.lua ├── table.lua ├── trace-calls.lua ├── trace-globals.lua └── xd.lua /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 1994-2012 Lua.org, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /HISTORY: -------------------------------------------------------------------------------- 1 | HISTORY for Lua 5.1 2 | 3 | * Changes from version 5.0 to 5.1 4 | ------------------------------- 5 | Language: 6 | + new module system. 7 | + new semantics for control variables of fors. 8 | + new semantics for setn/getn. 9 | + new syntax/semantics for varargs. 10 | + new long strings and comments. 11 | + new `mod' operator (`%') 12 | + new length operator #t 13 | + metatables for all types 14 | API: 15 | + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer. 16 | + user supplies memory allocator (lua_open becomes lua_newstate). 17 | + luaopen_* functions must be called through Lua. 18 | Implementation: 19 | + new configuration scheme via luaconf.h. 20 | + incremental garbage collection. 21 | + better handling of end-of-line in the lexer. 22 | + fully reentrant parser (new Lua function `load') 23 | + better support for 64-bit machines. 24 | + native loadlib support for Mac OS X. 25 | + standard distribution in only one library (lualib.a merged into lua.a) 26 | 27 | * Changes from version 4.0 to 5.0 28 | ------------------------------- 29 | Language: 30 | + lexical scoping. 31 | + Lua coroutines. 32 | + standard libraries now packaged in tables. 33 | + tags replaced by metatables and tag methods replaced by metamethods, 34 | stored in metatables. 35 | + proper tail calls. 36 | + each function can have its own global table, which can be shared. 37 | + new __newindex metamethod, called when we insert a new key into a table. 38 | + new block comments: --[[ ... ]]. 39 | + new generic for. 40 | + new weak tables. 41 | + new boolean type. 42 | + new syntax "local function". 43 | + (f()) returns the first value returned by f. 44 | + {f()} fills a table with all values returned by f. 45 | + \n ignored in [[\n . 46 | + fixed and-or priorities. 47 | + more general syntax for function definition (e.g. function a.x.y:f()...end). 48 | + more general syntax for function calls (e.g. (print or write)(9)). 49 | + new functions (time/date, tmpfile, unpack, require, load*, etc.). 50 | API: 51 | + chunks are loaded by using lua_load; new luaL_loadfile and luaL_loadbuffer. 52 | + introduced lightweight userdata, a simple "void*" without a metatable. 53 | + new error handling protocol: the core no longer prints error messages; 54 | all errors are reported to the caller on the stack. 55 | + new lua_atpanic for host cleanup. 56 | + new, signal-safe, hook scheme. 57 | Implementation: 58 | + new license: MIT. 59 | + new, faster, register-based virtual machine. 60 | + support for external multithreading and coroutines. 61 | + new and consistent error message format. 62 | + the core no longer needs "stdio.h" for anything (except for a single 63 | use of sprintf to convert numbers to strings). 64 | + lua.c now runs the environment variable LUA_INIT, if present. It can 65 | be "@filename", to run a file, or the chunk itself. 66 | + support for user extensions in lua.c. 67 | sample implementation given for command line editing. 68 | + new dynamic loading library, active by default on several platforms. 69 | + safe garbage-collector metamethods. 70 | + precompiled bytecodes checked for integrity (secure binary dostring). 71 | + strings are fully aligned. 72 | + position capture in string.find. 73 | + read('*l') can read lines with embedded zeros. 74 | 75 | * Changes from version 3.2 to 4.0 76 | ------------------------------- 77 | Language: 78 | + new "break" and "for" statements (both numerical and for tables). 79 | + uniform treatment of globals: globals are now stored in a Lua table. 80 | + improved error messages. 81 | + no more '$debug': full speed *and* full debug information. 82 | + new read form: read(N) for next N bytes. 83 | + general read patterns now deprecated. 84 | (still available with -DCOMPAT_READPATTERNS.) 85 | + all return values are passed as arguments for the last function 86 | (old semantics still available with -DLUA_COMPAT_ARGRET) 87 | + garbage collection tag methods for tables now deprecated. 88 | + there is now only one tag method for order. 89 | API: 90 | + New API: fully re-entrant, simpler, and more efficient. 91 | + New debug API. 92 | Implementation: 93 | + faster than ever: cleaner virtual machine and new hashing algorithm. 94 | + non-recursive garbage-collector algorithm. 95 | + reduced memory usage for programs with many strings. 96 | + improved treatment for memory allocation errors. 97 | + improved support for 16-bit machines (we hope). 98 | + code now compiles unmodified as both ANSI C and C++. 99 | + numbers in bases other than 10 are converted using strtoul. 100 | + new -f option in Lua to support #! scripts. 101 | + luac can now combine text and binaries. 102 | 103 | * Changes from version 3.1 to 3.2 104 | ------------------------------- 105 | + redirected all output in Lua's core to _ERRORMESSAGE and _ALERT. 106 | + increased limit on the number of constants and globals per function 107 | (from 2^16 to 2^24). 108 | + debugging info (lua_debug and hooks) moved into lua_state and new API 109 | functions provided to get and set this info. 110 | + new debug lib gives full debugging access within Lua. 111 | + new table functions "foreachi", "sort", "tinsert", "tremove", "getn". 112 | + new io functions "flush", "seek". 113 | 114 | * Changes from version 3.0 to 3.1 115 | ------------------------------- 116 | + NEW FEATURE: anonymous functions with closures (via "upvalues"). 117 | + new syntax: 118 | - local variables in chunks. 119 | - better scope control with DO block END. 120 | - constructors can now be also written: { record-part; list-part }. 121 | - more general syntax for function calls and lvalues, e.g.: 122 | f(x).y=1 123 | o:f(x,y):g(z) 124 | f"string" is sugar for f("string") 125 | + strings may now contain arbitrary binary data (e.g., embedded zeros). 126 | + major code re-organization and clean-up; reduced module interdependecies. 127 | + no arbitrary limits on the total number of constants and globals. 128 | + support for multiple global contexts. 129 | + better syntax error messages. 130 | + new traversal functions "foreach" and "foreachvar". 131 | + the default for numbers is now double. 132 | changing it to use floats or longs is easy. 133 | + complete debug information stored in pre-compiled chunks. 134 | + sample interpreter now prompts user when run interactively, and also 135 | handles control-C interruptions gracefully. 136 | 137 | * Changes from version 2.5 to 3.0 138 | ------------------------------- 139 | + NEW CONCEPT: "tag methods". 140 | Tag methods replace fallbacks as the meta-mechanism for extending the 141 | semantics of Lua. Whereas fallbacks had a global nature, tag methods 142 | work on objects having the same tag (e.g., groups of tables). 143 | Existing code that uses fallbacks should work without change. 144 | + new, general syntax for constructors {[exp] = exp, ... }. 145 | + support for handling variable number of arguments in functions (varargs). 146 | + support for conditional compilation ($if ... $else ... $end). 147 | + cleaner semantics in API simplifies host code. 148 | + better support for writing libraries (auxlib.h). 149 | + better type checking and error messages in the standard library. 150 | + luac can now also undump. 151 | 152 | * Changes from version 2.4 to 2.5 153 | ------------------------------- 154 | + io and string libraries are now based on pattern matching; 155 | the old libraries are still available for compatibility 156 | + dofile and dostring can now return values (via return statement) 157 | + better support for 16- and 64-bit machines 158 | + expanded documentation, with more examples 159 | 160 | * Changes from version 2.2 to 2.4 161 | ------------------------------- 162 | + external compiler creates portable binary files that can be loaded faster 163 | + interface for debugging and profiling 164 | + new "getglobal" fallback 165 | + new functions for handling references to Lua objects 166 | + new functions in standard lib 167 | + only one copy of each string is stored 168 | + expanded documentation, with more examples 169 | 170 | * Changes from version 2.1 to 2.2 171 | ------------------------------- 172 | + functions now may be declared with any "lvalue" as a name 173 | + garbage collection of functions 174 | + support for pipes 175 | 176 | * Changes from version 1.1 to 2.1 177 | ------------------------------- 178 | + object-oriented support 179 | + fallbacks 180 | + simplified syntax for tables 181 | + many internal improvements 182 | 183 | (end of HISTORY) 184 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | INSTALL for Lua 5.1 2 | 3 | * Building Lua 4 | ------------ 5 | Lua is built in the src directory, but the build process can be 6 | controlled from the top-level Makefile. 7 | 8 | Building Lua on Unix systems should be very easy. First do "make" and 9 | see if your platform is listed. If so, just do "make xxx", where xxx 10 | is your platform name. The platforms currently supported are: 11 | aix ansi bsd freebsd generic linux macosx mingw posix solaris 12 | 13 | If your platform is not listed, try the closest one or posix, generic, 14 | ansi, in this order. 15 | 16 | See below for customization instructions and for instructions on how 17 | to build with other Windows compilers. 18 | 19 | If you want to check that Lua has been built correctly, do "make test" 20 | after building Lua. Also, have a look at the example programs in test. 21 | 22 | * Installing Lua 23 | -------------- 24 | Once you have built Lua, you may want to install it in an official 25 | place in your system. In this case, do "make install". The official 26 | place and the way to install files are defined in Makefile. You must 27 | have the right permissions to install files. 28 | 29 | If you want to build and install Lua in one step, do "make xxx install", 30 | where xxx is your platform name. 31 | 32 | If you want to install Lua locally, then do "make local". This will 33 | create directories bin, include, lib, man, and install Lua there as 34 | follows: 35 | 36 | bin: lua luac 37 | include: lua.h luaconf.h lualib.h lauxlib.h lua.hpp 38 | lib: liblua.a 39 | man/man1: lua.1 luac.1 40 | 41 | These are the only directories you need for development. 42 | 43 | There are man pages for lua and luac, in both nroff and html, and a 44 | reference manual in html in doc, some sample code in test, and some 45 | useful stuff in etc. You don't need these directories for development. 46 | 47 | If you want to install Lua locally, but in some other directory, do 48 | "make install INSTALL_TOP=xxx", where xxx is your chosen directory. 49 | 50 | See below for instructions for Windows and other systems. 51 | 52 | * Customization 53 | ------------- 54 | Three things can be customized by editing a file: 55 | - Where and how to install Lua -- edit Makefile. 56 | - How to build Lua -- edit src/Makefile. 57 | - Lua features -- edit src/luaconf.h. 58 | 59 | You don't actually need to edit the Makefiles because you may set the 60 | relevant variables when invoking make. 61 | 62 | On the other hand, if you need to select some Lua features, you'll need 63 | to edit src/luaconf.h. The edited file will be the one installed, and 64 | it will be used by any Lua clients that you build, to ensure consistency. 65 | 66 | We strongly recommend that you enable dynamic loading. This is done 67 | automatically for all platforms listed above that have this feature 68 | (and also Windows). See src/luaconf.h and also src/Makefile. 69 | 70 | * Building Lua on Windows and other systems 71 | ----------------------------------------- 72 | If you're not using the usual Unix tools, then the instructions for 73 | building Lua depend on the compiler you use. You'll need to create 74 | projects (or whatever your compiler uses) for building the library, 75 | the interpreter, and the compiler, as follows: 76 | 77 | library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c 78 | lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c 79 | ltable.c ltm.c lundump.c lvm.c lzio.c 80 | lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c 81 | ltablib.c lstrlib.c loadlib.c linit.c 82 | 83 | interpreter: library, lua.c 84 | 85 | compiler: library, luac.c print.c 86 | 87 | If you use Visual Studio .NET, you can use etc/luavs.bat in its 88 | "Command Prompt". 89 | 90 | If all you want is to build the Lua interpreter, you may put all .c files 91 | in a single project, except for luac.c and print.c. Or just use etc/all.c. 92 | 93 | To use Lua as a library in your own programs, you'll need to know how to 94 | create and use libraries with your compiler. 95 | 96 | As mentioned above, you may edit luaconf.h to select some features before 97 | building Lua. 98 | 99 | (end of INSTALL) 100 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # makefile for installing Lua 2 | # see INSTALL for installation instructions 3 | # see src/Makefile and src/luaconf.h for further customization 4 | 5 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 6 | 7 | # Your platform. See PLATS for possible values. 8 | PLAT= none 9 | 10 | # Where to install. The installation starts in the src and doc directories, 11 | # so take care if INSTALL_TOP is not an absolute path. 12 | INSTALL_TOP= /usr/local 13 | INSTALL_BIN= $(INSTALL_TOP)/bin 14 | INSTALL_INC= $(INSTALL_TOP)/include 15 | INSTALL_LIB= $(INSTALL_TOP)/lib 16 | INSTALL_MAN= $(INSTALL_TOP)/man/man1 17 | # 18 | # You probably want to make INSTALL_LMOD and INSTALL_CMOD consistent with 19 | # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc). 20 | INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V 21 | INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V 22 | 23 | # How to install. If your install program does not support "-p", then you 24 | # may have to run ranlib on the installed liblua.a (do "make ranlib"). 25 | INSTALL= install -p 26 | INSTALL_EXEC= $(INSTALL) -m 0755 27 | INSTALL_DATA= $(INSTALL) -m 0644 28 | # 29 | # If you don't have install you can use cp instead. 30 | # INSTALL= cp -p 31 | # INSTALL_EXEC= $(INSTALL) 32 | # INSTALL_DATA= $(INSTALL) 33 | 34 | # Utilities. 35 | MKDIR= mkdir -p 36 | RANLIB= ranlib 37 | 38 | # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= 39 | 40 | # Convenience platforms targets. 41 | PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris 42 | 43 | # What to install. 44 | TO_BIN= lua luac 45 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp 46 | TO_LIB= liblua.a 47 | TO_MAN= lua.1 luac.1 48 | 49 | # Lua version and release. 50 | V= 5.1 51 | R= 5.1.5 52 | 53 | all: $(PLAT) 54 | 55 | $(PLATS) clean: 56 | cd src && $(MAKE) $@ 57 | 58 | test: dummy 59 | src/lua test/hello.lua 60 | 61 | install: dummy 62 | cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) 63 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) 64 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) 65 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) 66 | cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) 67 | 68 | ranlib: 69 | cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB) 70 | 71 | local: 72 | $(MAKE) install INSTALL_TOP=.. 73 | 74 | none: 75 | @echo "Please do" 76 | @echo " make PLATFORM" 77 | @echo "where PLATFORM is one of these:" 78 | @echo " $(PLATS)" 79 | @echo "See INSTALL for complete instructions." 80 | 81 | # make may get confused with test/ and INSTALL in a case-insensitive OS 82 | dummy: 83 | 84 | # echo config parameters 85 | echo: 86 | @echo "" 87 | @echo "These are the parameters currently set in src/Makefile to build Lua $R:" 88 | @echo "" 89 | @cd src && $(MAKE) -s echo 90 | @echo "" 91 | @echo "These are the parameters currently set in Makefile to install Lua $R:" 92 | @echo "" 93 | @echo "PLAT = $(PLAT)" 94 | @echo "INSTALL_TOP = $(INSTALL_TOP)" 95 | @echo "INSTALL_BIN = $(INSTALL_BIN)" 96 | @echo "INSTALL_INC = $(INSTALL_INC)" 97 | @echo "INSTALL_LIB = $(INSTALL_LIB)" 98 | @echo "INSTALL_MAN = $(INSTALL_MAN)" 99 | @echo "INSTALL_LMOD = $(INSTALL_LMOD)" 100 | @echo "INSTALL_CMOD = $(INSTALL_CMOD)" 101 | @echo "INSTALL_EXEC = $(INSTALL_EXEC)" 102 | @echo "INSTALL_DATA = $(INSTALL_DATA)" 103 | @echo "" 104 | @echo "See also src/luaconf.h ." 105 | @echo "" 106 | 107 | # echo private config parameters 108 | pecho: 109 | @echo "V = $(V)" 110 | @echo "R = $(R)" 111 | @echo "TO_BIN = $(TO_BIN)" 112 | @echo "TO_INC = $(TO_INC)" 113 | @echo "TO_LIB = $(TO_LIB)" 114 | @echo "TO_MAN = $(TO_MAN)" 115 | 116 | # echo config parameters as Lua code 117 | # uncomment the last sed expression if you want nil instead of empty strings 118 | lecho: 119 | @echo "-- installation parameters for Lua $R" 120 | @echo "VERSION = '$V'" 121 | @echo "RELEASE = '$R'" 122 | @$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' 123 | @echo "-- EOF" 124 | 125 | # list targets that do not create files (but not all makes understand .PHONY) 126 | .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho 127 | 128 | # (end of Makefile) 129 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README for Lua 5.1 2 | 3 | See INSTALL for installation instructions. 4 | See HISTORY for a summary of changes since the last released version. 5 | 6 | * What is Lua? 7 | ------------ 8 | Lua is a powerful, light-weight programming language designed for extending 9 | applications. Lua is also frequently used as a general-purpose, stand-alone 10 | language. Lua is free software. 11 | 12 | For complete information, visit Lua's web site at http://www.lua.org/ . 13 | For an executive summary, see http://www.lua.org/about.html . 14 | 15 | Lua has been used in many different projects around the world. 16 | For a short list, see http://www.lua.org/uses.html . 17 | 18 | * Availability 19 | ------------ 20 | Lua is freely available for both academic and commercial purposes. 21 | See COPYRIGHT and http://www.lua.org/license.html for details. 22 | Lua can be downloaded at http://www.lua.org/download.html . 23 | 24 | * Installation 25 | ------------ 26 | Lua is implemented in pure ANSI C, and compiles unmodified in all known 27 | platforms that have an ANSI C compiler. In most Unix-like platforms, simply 28 | do "make" with a suitable target. See INSTALL for detailed instructions. 29 | 30 | * Origin 31 | ------ 32 | Lua is developed at Lua.org, a laboratory of the Department of Computer 33 | Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro 34 | in Brazil). 35 | For more information about the authors, see http://www.lua.org/authors.html . 36 | 37 | (end of README) 38 | -------------------------------------------------------------------------------- /doc/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsnyder/lua/5ca4b4e3f1d37ad0a6ecf390e41109018f02e8d1/doc/cover.png -------------------------------------------------------------------------------- /doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsnyder/lua/5ca4b4e3f1d37ad0a6ecf390e41109018f02e8d1/doc/logo.gif -------------------------------------------------------------------------------- /doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ 2 | .TH LUA 1 "$Date: 2006/01/06 16:03:34 $" 3 | .SH NAME 4 | lua \- Lua interpreter 5 | .SH SYNOPSIS 6 | .B lua 7 | [ 8 | .I options 9 | ] 10 | [ 11 | .I script 12 | [ 13 | .I args 14 | ] 15 | ] 16 | .SH DESCRIPTION 17 | .B lua 18 | is the stand-alone Lua interpreter. 19 | It loads and executes Lua programs, 20 | either in textual source form or 21 | in precompiled binary form. 22 | (Precompiled binaries are output by 23 | .BR luac , 24 | the Lua compiler.) 25 | .B lua 26 | can be used as a batch interpreter and also interactively. 27 | .LP 28 | The given 29 | .I options 30 | (see below) 31 | are executed and then 32 | the Lua program in file 33 | .I script 34 | is loaded and executed. 35 | The given 36 | .I args 37 | are available to 38 | .I script 39 | as strings in a global table named 40 | .BR arg . 41 | If these arguments contain spaces or other characters special to the shell, 42 | then they should be quoted 43 | (but note that the quotes will be removed by the shell). 44 | The arguments in 45 | .B arg 46 | start at 0, 47 | which contains the string 48 | .RI ' script '. 49 | The index of the last argument is stored in 50 | .BR arg.n . 51 | The arguments given in the command line before 52 | .IR script , 53 | including the name of the interpreter, 54 | are available in negative indices in 55 | .BR arg . 56 | .LP 57 | At the very start, 58 | before even handling the command line, 59 | .B lua 60 | executes the contents of the environment variable 61 | .BR LUA_INIT , 62 | if it is defined. 63 | If the value of 64 | .B LUA_INIT 65 | is of the form 66 | .RI '@ filename ', 67 | then 68 | .I filename 69 | is executed. 70 | Otherwise, the string is assumed to be a Lua statement and is executed. 71 | .LP 72 | Options start with 73 | .B '\-' 74 | and are described below. 75 | You can use 76 | .B "'\--'" 77 | to signal the end of options. 78 | .LP 79 | If no arguments are given, 80 | then 81 | .B "\-v \-i" 82 | is assumed when the standard input is a terminal; 83 | otherwise, 84 | .B "\-" 85 | is assumed. 86 | .LP 87 | In interactive mode, 88 | .B lua 89 | prompts the user, 90 | reads lines from the standard input, 91 | and executes them as they are read. 92 | If a line does not contain a complete statement, 93 | then a secondary prompt is displayed and 94 | lines are read until a complete statement is formed or 95 | a syntax error is found. 96 | So, one way to interrupt the reading of an incomplete statement is 97 | to force a syntax error: 98 | adding a 99 | .B ';' 100 | in the middle of a statement is a sure way of forcing a syntax error 101 | (except inside multiline strings and comments; these must be closed explicitly). 102 | If a line starts with 103 | .BR '=' , 104 | then 105 | .B lua 106 | displays the values of all the expressions in the remainder of the 107 | line. The expressions must be separated by commas. 108 | The primary prompt is the value of the global variable 109 | .BR _PROMPT , 110 | if this value is a string; 111 | otherwise, the default prompt is used. 112 | Similarly, the secondary prompt is the value of the global variable 113 | .BR _PROMPT2 . 114 | So, 115 | to change the prompts, 116 | set the corresponding variable to a string of your choice. 117 | You can do that after calling the interpreter 118 | or on the command line 119 | (but in this case you have to be careful with quotes 120 | if the prompt string contains a space; otherwise you may confuse the shell.) 121 | The default prompts are "> " and ">> ". 122 | .SH OPTIONS 123 | .TP 124 | .B \- 125 | load and execute the standard input as a file, 126 | that is, 127 | not interactively, 128 | even when the standard input is a terminal. 129 | .TP 130 | .BI \-e " stat" 131 | execute statement 132 | .IR stat . 133 | You need to quote 134 | .I stat 135 | if it contains spaces, quotes, 136 | or other characters special to the shell. 137 | .TP 138 | .B \-i 139 | enter interactive mode after 140 | .I script 141 | is executed. 142 | .TP 143 | .BI \-l " name" 144 | call 145 | .BI require(' name ') 146 | before executing 147 | .IR script . 148 | Typically used to load libraries. 149 | .TP 150 | .B \-v 151 | show version information. 152 | .SH "SEE ALSO" 153 | .BR luac (1) 154 | .br 155 | http://www.lua.org/ 156 | .SH DIAGNOSTICS 157 | Error messages should be self explanatory. 158 | .SH AUTHORS 159 | R. Ierusalimschy, 160 | L. H. de Figueiredo, 161 | and 162 | W. Celes 163 | .\" EOF 164 | -------------------------------------------------------------------------------- /doc/lua.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #000000 ; 3 | background-color: #FFFFFF ; 4 | font-family: Helvetica, Arial, sans-serif ; 5 | text-align: justify ; 6 | margin-right: 30px ; 7 | margin-left: 30px ; 8 | } 9 | 10 | h1, h2, h3, h4 { 11 | font-family: Verdana, Geneva, sans-serif ; 12 | font-weight: normal ; 13 | font-style: italic ; 14 | } 15 | 16 | h2 { 17 | padding-top: 0.4em ; 18 | padding-bottom: 0.4em ; 19 | padding-left: 30px ; 20 | padding-right: 30px ; 21 | margin-left: -30px ; 22 | background-color: #E0E0FF ; 23 | } 24 | 25 | h3 { 26 | padding-left: 0.5em ; 27 | border-left: solid #E0E0FF 1em ; 28 | } 29 | 30 | table h3 { 31 | padding-left: 0px ; 32 | border-left: none ; 33 | } 34 | 35 | a:link { 36 | color: #000080 ; 37 | background-color: inherit ; 38 | text-decoration: none ; 39 | } 40 | 41 | a:visited { 42 | background-color: inherit ; 43 | text-decoration: none ; 44 | } 45 | 46 | a:link:hover, a:visited:hover { 47 | color: #000080 ; 48 | background-color: #E0E0FF ; 49 | } 50 | 51 | a:link:active, a:visited:active { 52 | color: #FF0000 ; 53 | } 54 | 55 | hr { 56 | border: 0 ; 57 | height: 1px ; 58 | color: #a0a0a0 ; 59 | background-color: #a0a0a0 ; 60 | } 61 | 62 | :target { 63 | background-color: #F8F8F8 ; 64 | padding: 8px ; 65 | border: solid #a0a0a0 2px ; 66 | } 67 | 68 | .footer { 69 | color: gray ; 70 | font-size: small ; 71 | } 72 | 73 | input[type=text] { 74 | border: solid #a0a0a0 2px ; 75 | border-radius: 2em ; 76 | -moz-border-radius: 2em ; 77 | background-image: url('images/search.png') ; 78 | background-repeat: no-repeat; 79 | background-position: 4px center ; 80 | padding-left: 20px ; 81 | height: 2em ; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /doc/lua.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |35 | The given 36 | options 37 | (see below) 38 | are executed and then 39 | the Lua program in file 40 | script 41 | is loaded and executed. 42 | The given 43 | args 44 | are available to 45 | script 46 | as strings in a global table named 47 | arg. 48 | If these arguments contain spaces or other characters special to the shell, 49 | then they should be quoted 50 | (but note that the quotes will be removed by the shell). 51 | The arguments in 52 | arg 53 | start at 0, 54 | which contains the string 55 | 'script'. 56 | The index of the last argument is stored in 57 | arg.n. 58 | The arguments given in the command line before 59 | script, 60 | including the name of the interpreter, 61 | are available in negative indices in 62 | arg. 63 |
64 | At the very start, 65 | before even handling the command line, 66 | lua 67 | executes the contents of the environment variable 68 | LUA_INIT, 69 | if it is defined. 70 | If the value of 71 | LUA_INIT 72 | is of the form 73 | '@filename', 74 | then 75 | filename 76 | is executed. 77 | Otherwise, the string is assumed to be a Lua statement and is executed. 78 |
79 | Options start with 80 | '-' 81 | and are described below. 82 | You can use 83 | '--' 84 | to signal the end of options. 85 |
86 | If no arguments are given, 87 | then 88 | "-v -i" 89 | is assumed when the standard input is a terminal; 90 | otherwise, 91 | "-" 92 | is assumed. 93 |
94 | In interactive mode, 95 | lua 96 | prompts the user, 97 | reads lines from the standard input, 98 | and executes them as they are read. 99 | If a line does not contain a complete statement, 100 | then a secondary prompt is displayed and 101 | lines are read until a complete statement is formed or 102 | a syntax error is found. 103 | So, one way to interrupt the reading of an incomplete statement is 104 | to force a syntax error: 105 | adding a 106 | ';' 107 | in the middle of a statement is a sure way of forcing a syntax error 108 | (except inside multiline strings and comments; these must be closed explicitly). 109 | If a line starts with 110 | '=', 111 | then 112 | lua 113 | displays the values of all the expressions in the remainder of the 114 | line. The expressions must be separated by commas. 115 | The primary prompt is the value of the global variable 116 | _PROMPT, 117 | if this value is a string; 118 | otherwise, the default prompt is used. 119 | Similarly, the secondary prompt is the value of the global variable 120 | _PROMPT2. 121 | So, 122 | to change the prompts, 123 | set the corresponding variable to a string of your choice. 124 | You can do that after calling the interpreter 125 | or on the command line 126 | (but in this case you have to be careful with quotes 127 | if the prompt string contains a space; otherwise you may confuse the shell.) 128 | The default prompts are "> " and ">> ". 129 |
131 | - 132 | load and execute the standard input as a file, 133 | that is, 134 | not interactively, 135 | even when the standard input is a terminal. 136 |
137 | -e stat 138 | execute statement 139 | stat. 140 | You need to quote 141 | stat 142 | if it contains spaces, quotes, 143 | or other characters special to the shell. 144 |
145 | -i 146 | enter interactive mode after 147 | script 148 | is executed. 149 |
150 | -l name 151 | call 152 | require('name') 153 | before executing 154 | script. 155 | Typically used to load libraries. 156 |
157 | -v 158 | show version information. 159 |
25 | The main advantages of precompiling chunks are: 26 | faster loading, 27 | protecting source code from accidental user changes, 28 | and 29 | off-line syntax checking. 30 |
31 | Precompiling does not imply faster execution 32 | because in Lua chunks are always compiled into bytecodes before being executed. 33 | luac 34 | simply allows those bytecodes to be saved in a file for later execution. 35 |
36 | Precompiled chunks are not necessarily smaller than the corresponding source. 37 | The main goal in precompiling is faster loading. 38 |
39 | The binary files created by 40 | luac 41 | are portable only among architectures with the same word size and byte order. 42 |
43 | luac 44 | produces a single output file containing the bytecodes 45 | for all source files given. 46 | By default, 47 | the output file is named 48 | luac.out, 49 | but you can change this with the 50 | -o 51 | option. 52 |
53 | In the command line, 54 | you can mix 55 | text files containing Lua source and 56 | binary files containing precompiled chunks. 57 | This is useful because several precompiled chunks, 58 | even from different (but compatible) platforms, 59 | can be combined into a single precompiled chunk. 60 |
61 | You can use 62 | '-' 63 | to indicate the standard input as a source file 64 | and 65 | '--' 66 | to signal the end of options 67 | (that is, 68 | all remaining arguments will be treated as files even if they start with 69 | '-'). 70 |
71 | The internal format of the binary files produced by 72 | luac 73 | is likely to change when a new version of Lua is released. 74 | So, 75 | save the source files of all Lua programs that you precompile. 76 |
77 |
80 | -l 81 | produce a listing of the compiled bytecode for Lua's virtual machine. 82 | Listing bytecodes is useful to learn about Lua's virtual machine. 83 | If no files are given, then 84 | luac 85 | loads 86 | luac.out 87 | and lists its contents. 88 |
89 | -o file 90 | output to 91 | file, 92 | instead of the default 93 | luac.out. 94 | (You can use 95 | '-' 96 | for standard output, 97 | but not on platforms that open standard output in text mode.) 98 | The output file may be a source file because 99 | all files are loaded before the output file is written. 100 | Be careful not to overwrite precious files. 101 |
102 | -p 103 | load files but do not generate any output file. 104 | Used mainly for syntax checking and for testing precompiled chunks: 105 | corrupted files will probably generate errors when loaded. 106 | Lua always performs a thorough integrity test on precompiled chunks. 107 | Bytecode that passes this test is completely safe, 108 | in the sense that it will not break the interpreter. 109 | However, 110 | there is no guarantee that such code does anything sensible. 111 | (None can be given, because the halting problem is unsolvable.) 112 | If no files are given, then 113 | luac 114 | loads 115 | luac.out 116 | and tests its contents. 117 | No messages are displayed if the file passes the integrity test. 118 |
119 | -s 120 | strip debug information before writing the output file. 121 | This saves some space in very large chunks, 122 | but if errors occur when running a stripped chunk, 123 | then the error messages may not contain the full information they usually do. 124 | For instance, 125 | line numbers and names of local variables are lost. 126 |
127 | -v 128 | show version information. 129 |
131 | luac.out 132 | default output file 133 |
32 | 33 |
lsizenode))
361 |
362 |
363 | #define luaO_nilobject (&luaO_nilobject_)
364 |
365 | LUAI_DATA const TValue luaO_nilobject_;
366 |
367 | #define ceillog2(x) (luaO_log2((x)-1) + 1)
368 |
369 | LUAI_FUNC int luaO_log2 (unsigned int x);
370 | LUAI_FUNC int luaO_int2fb (unsigned int x);
371 | LUAI_FUNC int luaO_fb2int (int x);
372 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
373 | LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);
374 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
375 | va_list argp);
376 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
377 | LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
378 |
379 |
380 | #endif
381 |
382 |
--------------------------------------------------------------------------------
/src/lopcodes.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** See Copyright Notice in lua.h
4 | */
5 |
6 |
7 | #define lopcodes_c
8 | #define LUA_CORE
9 |
10 |
11 | #include "lopcodes.h"
12 |
13 |
14 | /* ORDER OP */
15 |
16 | const char *const luaP_opnames[NUM_OPCODES+1] = {
17 | "MOVE",
18 | "LOADK",
19 | "LOADBOOL",
20 | "LOADNIL",
21 | "GETUPVAL",
22 | "GETGLOBAL",
23 | "GETTABLE",
24 | "SETGLOBAL",
25 | "SETUPVAL",
26 | "SETTABLE",
27 | "NEWTABLE",
28 | "SELF",
29 | "ADD",
30 | "SUB",
31 | "MUL",
32 | "DIV",
33 | "MOD",
34 | "POW",
35 | "UNM",
36 | "NOT",
37 | "LEN",
38 | "CONCAT",
39 | "JMP",
40 | "EQ",
41 | "LT",
42 | "LE",
43 | "TEST",
44 | "TESTSET",
45 | "CALL",
46 | "TAILCALL",
47 | "RETURN",
48 | "FORLOOP",
49 | "FORPREP",
50 | "TFORLOOP",
51 | "SETLIST",
52 | "CLOSE",
53 | "CLOSURE",
54 | "VARARG",
55 | NULL
56 | };
57 |
58 |
59 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
60 |
61 | const lu_byte luaP_opmodes[NUM_OPCODES] = {
62 | /* T A B C mode opcode */
63 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
64 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
65 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
66 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */
67 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
68 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */
69 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
70 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */
71 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */
72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */
73 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */
74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */
75 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */
76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */
84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
89 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */
90 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
91 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
92 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
93 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */
94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */
97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
100 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
101 | };
102 |
103 |
--------------------------------------------------------------------------------
/src/lopcodes.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Opcodes for Lua virtual machine
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lopcodes_h
8 | #define lopcodes_h
9 |
10 | #include "llimits.h"
11 |
12 |
13 | /*===========================================================================
14 | We assume that instructions are unsigned numbers.
15 | All instructions have an opcode in the first 6 bits.
16 | Instructions can have the following fields:
17 | `A' : 8 bits
18 | `B' : 9 bits
19 | `C' : 9 bits
20 | `Bx' : 18 bits (`B' and `C' together)
21 | `sBx' : signed Bx
22 |
23 | A signed argument is represented in excess K; that is, the number
24 | value is the unsigned value minus K. K is exactly the maximum value
25 | for that argument (so that -max is represented by 0, and +max is
26 | represented by 2*max), which is half the maximum for the corresponding
27 | unsigned argument.
28 | ===========================================================================*/
29 |
30 |
31 | enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
32 |
33 |
34 | /*
35 | ** size and position of opcode arguments.
36 | */
37 | #define SIZE_C 9
38 | #define SIZE_B 9
39 | #define SIZE_Bx (SIZE_C + SIZE_B)
40 | #define SIZE_A 8
41 |
42 | #define SIZE_OP 6
43 |
44 | #define POS_OP 0
45 | #define POS_A (POS_OP + SIZE_OP)
46 | #define POS_C (POS_A + SIZE_A)
47 | #define POS_B (POS_C + SIZE_C)
48 | #define POS_Bx POS_C
49 |
50 |
51 | /*
52 | ** limits for opcode arguments.
53 | ** we use (signed) int to manipulate most arguments,
54 | ** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
55 | */
56 | #if SIZE_Bx < LUAI_BITSINT-1
57 | #define MAXARG_Bx ((1<