updated to Lua 5.2.4

This commit is contained in:
Remy Marquis 2015-03-18 16:04:12 +01:00
parent 5d31d90fa4
commit c800015f3e
53 changed files with 190 additions and 1764 deletions

View file

@ -1,34 +0,0 @@
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-2012 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)

View file

@ -1,183 +0,0 @@
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)

View file

@ -1,99 +0,0 @@
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)

View file

@ -36,7 +36,7 @@ RM= rm -f
# == 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 posix32bit solaris
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
# What to install.
TO_BIN= lua luac
@ -46,7 +46,7 @@ TO_MAN= lua.1 luac.1
# Lua version and release.
V= 5.2
R= $V.3
R= $V.4
# Targets start here.
all: $(PLAT)

View file

@ -1,9 +1,6 @@
This is Lua 5.2.3, released on 11 Nov 2013.
This is Lua 5.2.4, released on 25 Feb 2015.
For installation instructions, license details, and
further information about Lua, see doc/readme.html.
This is a slightly modified version for ET: Legacy
src/Makefile is adjusted to fit our posix and posix32bit requirements

View file

@ -7,7 +7,6 @@
<STYLE TYPE="text/css">
ul {
list-style-type: none ;
list-style-position: outside ;
}
</STYLE>
</HEAD>
@ -33,7 +32,7 @@ For a complete introduction to Lua programming, see the book
<A HREF="#index">index</A>
<HR>
<SMALL>
Copyright &copy; 2011&ndash;2013 Lua.org, PUC-Rio.
Copyright &copy; 2011&ndash;2015 Lua.org, PUC-Rio.
Freely available under the terms of the
<A HREF="http://www.lua.org/license.html">Lua license</A>.
</SMALL>
@ -139,10 +138,10 @@ Freely available under the terms of the
<TD>
<H3><A NAME="functions">Lua functions</A></H3>
<P>
<A HREF="manual.html#6.1">basic</A><BR>
<A HREF="manual.html#pdf-_G">_G</A><BR>
<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
<P>
<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>
@ -168,6 +167,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
<P>
<A HREF="manual.html#6.7">bit32</A><BR>
<A HREF="manual.html#pdf-bit32.arshift">bit32.arshift</A><BR>
<A HREF="manual.html#pdf-bit32.band">bit32.band</A><BR>
<A HREF="manual.html#pdf-bit32.bnot">bit32.bnot</A><BR>
@ -182,6 +182,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-bit32.rshift">bit32.rshift</A><BR>
<P>
<A HREF="manual.html#6.2">coroutine</A><BR>
<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>
@ -190,6 +191,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-coroutine.yield">coroutine.yield</A><BR>
<P>
<A HREF="manual.html#6.10">debug</A><BR>
<A HREF="manual.html#pdf-debug.debug">debug.debug</A><BR>
<A HREF="manual.html#pdf-debug.getuservalue">debug.getuservalue</A><BR>
<A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR>
@ -208,15 +210,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-debug.upvaluejoin">debug.upvaluejoin</A><BR>
<P>
<A HREF="manual.html#pdf-file:close">file:close</A><BR>
<A HREF="manual.html#pdf-file:flush">file:flush</A><BR>
<A HREF="manual.html#pdf-file:lines">file:lines</A><BR>
<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#6.8">io</A><BR>
<A HREF="manual.html#pdf-io.close">io.close</A><BR>
<A HREF="manual.html#pdf-io.flush">io.flush</A><BR>
<A HREF="manual.html#pdf-io.input">io.input</A><BR>
@ -231,11 +225,19 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-io.tmpfile">io.tmpfile</A><BR>
<A HREF="manual.html#pdf-io.type">io.type</A><BR>
<A HREF="manual.html#pdf-io.write">io.write</A><BR>
<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>
</TD>
<TD>
<H3>&nbsp;</H3>
<P>
<A HREF="manual.html#6.6">math</A><BR>
<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
@ -267,6 +269,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
<P>
<A HREF="manual.html#6.9">os</A><BR>
<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
<A HREF="manual.html#pdf-os.date">os.date</A><BR>
<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
@ -280,6 +283,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>
<P>
<A HREF="manual.html#6.3">package</A><BR>
<A HREF="manual.html#pdf-package.config">package.config</A><BR>
<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
@ -290,6 +294,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-package.searchpath">package.searchpath</A><BR>
<P>
<A HREF="manual.html#6.4">string</A><BR>
<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
<A HREF="manual.html#pdf-string.char">string.char</A><BR>
<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
@ -306,6 +311,7 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-string.upper">string.upper</A><BR>
<P>
<A HREF="manual.html#6.5">table</A><BR>
<A HREF="manual.html#pdf-table.concat">table.concat</A><BR>
<A HREF="manual.html#pdf-table.insert">table.insert</A><BR>
<A HREF="manual.html#pdf-table.pack">table.pack</A><BR>
@ -313,6 +319,14 @@ Freely available under the terms of the
<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
<A HREF="manual.html#pdf-table.unpack">table.unpack</A><BR>
<H3><A NAME="env">environment<BR>variables</A></H3>
<A HREF="manual.html#pdf-LUA_CPATH">LUA_CPATH</A><BR>
<A HREF="manual.html#pdf-LUA_CPATH_5_2">LUA_CPATH_5_2</A><BR>
<A HREF="manual.html#pdf-LUA_INIT">LUA_INIT</A><BR>
<A HREF="manual.html#pdf-LUA_INIT_5_2">LUA_INIT_5_2</A><BR>
<A HREF="manual.html#pdf-LUA_PATH">LUA_PATH</A><BR>
<A HREF="manual.html#pdf-LUA_PATH_5_2">LUA_PATH_5_2</A><BR>
</TD>
<TD>
<H3>C API</H3>
@ -516,6 +530,67 @@ Freely available under the terms of the
<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
<A HREF="manual.html#luaL_where">luaL_where</A><BR>
<H3><A NAME="library">standard library</A></H3>
<P>
<A HREF="manual.html#pdf-luaopen_base">luaopen_base</A><BR>
<A HREF="manual.html#pdf-luaopen_bit32">luaopen_bit32</A><BR>
<A HREF="manual.html#pdf-luaopen_coroutine">luaopen_coroutine</A><BR>
<A HREF="manual.html#pdf-luaopen_debug">luaopen_debug</A><BR>
<A HREF="manual.html#pdf-luaopen_io">luaopen_io</A><BR>
<A HREF="manual.html#pdf-luaopen_math">luaopen_math</A><BR>
<A HREF="manual.html#pdf-luaopen_os">luaopen_os</A><BR>
<A HREF="manual.html#pdf-luaopen_package">luaopen_package</A><BR>
<A HREF="manual.html#pdf-luaopen_string">luaopen_string</A><BR>
<A HREF="manual.html#pdf-luaopen_table">luaopen_table</A><BR>
<H3><A NAME="constants">constants</A></H3>
<A HREF="manual.html#pdf-LUA_ERRERR">LUA_ERRERR</A><BR>
<A HREF="manual.html#pdf-LUA_ERRFILE">LUA_ERRFILE</A><BR>
<A HREF="manual.html#pdf-LUA_ERRGCMM">LUA_ERRGCMM</A><BR>
<A HREF="manual.html#pdf-LUA_ERRMEM">LUA_ERRMEM</A><BR>
<A HREF="manual.html#pdf-LUA_ERRRUN">LUA_ERRRUN</A><BR>
<A HREF="manual.html#pdf-LUA_ERRSYNTAX">LUA_ERRSYNTAX</A><BR>
<A HREF="manual.html#pdf-LUA_HOOKCALL">LUA_HOOKCALL</A><BR>
<A HREF="manual.html#pdf-LUA_HOOKCOUNT">LUA_HOOKCOUNT</A><BR>
<A HREF="manual.html#pdf-LUA_HOOKLINE">LUA_HOOKLINE</A><BR>
<A HREF="manual.html#pdf-LUA_HOOKRET">LUA_HOOKRET</A><BR>
<A HREF="manual.html#pdf-LUA_HOOKTAILCALL">LUA_HOOKTAILCALL</A><BR>
<A HREF="manual.html#pdf-LUA_MASKCALL">LUA_MASKCALL</A><BR>
<A HREF="manual.html#pdf-LUA_MASKCOUNT">LUA_MASKCOUNT</A><BR>
<A HREF="manual.html#pdf-LUA_MASKLINE">LUA_MASKLINE</A><BR>
<A HREF="manual.html#pdf-LUA_MASKRET">LUA_MASKRET</A><BR>
<A HREF="manual.html#pdf-LUA_MINSTACK">LUA_MINSTACK</A><BR>
<A HREF="manual.html#pdf-LUA_MULTRET">LUA_MULTRET</A><BR>
<A HREF="manual.html#pdf-LUA_NOREF">LUA_NOREF</A><BR>
<A HREF="manual.html#pdf-LUA_OK">LUA_OK</A><BR>
<A HREF="manual.html#pdf-LUA_OPADD">LUA_OPADD</A><BR>
<A HREF="manual.html#pdf-LUA_OPDIV">LUA_OPDIV</A><BR>
<A HREF="manual.html#pdf-LUA_OPEQ">LUA_OPEQ</A><BR>
<A HREF="manual.html#pdf-LUA_OPLE">LUA_OPLE</A><BR>
<A HREF="manual.html#pdf-LUA_OPLT">LUA_OPLT</A><BR>
<A HREF="manual.html#pdf-LUA_OPMOD">LUA_OPMOD</A><BR>
<A HREF="manual.html#pdf-LUA_OPMUL">LUA_OPMUL</A><BR>
<A HREF="manual.html#pdf-LUA_OPPOW">LUA_OPPOW</A><BR>
<A HREF="manual.html#pdf-LUA_OPSUB">LUA_OPSUB</A><BR>
<A HREF="manual.html#pdf-LUA_OPUNM">LUA_OPUNM</A><BR>
<A HREF="manual.html#pdf-LUA_REFNIL">LUA_REFNIL</A><BR>
<A HREF="manual.html#pdf-LUA_REGISTRYINDEX">LUA_REGISTRYINDEX</A><BR>
<A HREF="manual.html#pdf-LUA_RIDX_GLOBALS">LUA_RIDX_GLOBALS</A><BR>
<A HREF="manual.html#pdf-LUA_RIDX_MAINTHREAD">LUA_RIDX_MAINTHREAD</A><BR>
<A HREF="manual.html#pdf-LUA_TBOOLEAN">LUA_TBOOLEAN</A><BR>
<A HREF="manual.html#pdf-LUA_TFUNCTION">LUA_TFUNCTION</A><BR>
<A HREF="manual.html#pdf-LUA_TLIGHTUSERDATA">LUA_TLIGHTUSERDATA</A><BR>
<A HREF="manual.html#pdf-LUA_TNIL">LUA_TNIL</A><BR>
<A HREF="manual.html#pdf-LUA_TNONE">LUA_TNONE</A><BR>
<A HREF="manual.html#pdf-LUA_TNUMBER">LUA_TNUMBER</A><BR>
<A HREF="manual.html#pdf-LUA_TSTRING">LUA_TSTRING</A><BR>
<A HREF="manual.html#pdf-LUA_TTABLE">LUA_TTABLE</A><BR>
<A HREF="manual.html#pdf-LUA_TTHREAD">LUA_TTHREAD</A><BR>
<A HREF="manual.html#pdf-LUA_TUSERDATA">LUA_TUSERDATA</A><BR>
<A HREF="manual.html#pdf-LUA_USE_APICHECK">LUA_USE_APICHECK</A><BR>
<A HREF="manual.html#pdf-LUA_YIELD">LUA_YIELD</A><BR>
<A HREF="manual.html#pdf-LUAL_BUFFERSIZE">LUAL_BUFFERSIZE</A><BR>
</TD>
</TR>
</TABLE>
@ -523,10 +598,10 @@ Freely available under the terms of the
<HR>
<SMALL CLASS="footer">
Last update:
Tue Mar 12 11:22:18 BRT 2013
Mon Feb 23 22:24:36 BRT 2015
</SMALL>
<!--
Last change: revised for Lua 5.2.2
Last change: revised for Lua 5.2.4
-->
</BODY>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -11,6 +11,7 @@ body {
background-color: #FFFFFF ;
font-family: Helvetica, Arial, sans-serif ;
text-align: justify ;
line-height: 1.25 ;
}
h1, h2, h3, h4 {
@ -53,12 +54,17 @@ a:visited {
a:link:hover, a:visited:hover {
color: #000080 ;
background-color: #D0D0FF ;
border-radius: 4px ;
}
a:link:active, a:visited:active {
color: #FF0000 ;
}
h1 a img {
vertical-align: text-bottom ;
}
hr {
border: 0 ;
height: 1px ;
@ -86,11 +92,15 @@ table hr {
input[type=text] {
border: solid #a0a0a0 2px ;
border-radius: 2em ;
-moz-border-radius: 2em ;
background-image: url('images/search.png') ;
background-repeat: no-repeat;
background-repeat: no-repeat ;
background-position: 4px center ;
padding-left: 20px ;
height: 2em ;
}
pre.session {
background-color: #F8F8F8 ;
padding: 1em ;
border-radius: 8px ;
}

View file

@ -1,172 +0,0 @@
<!-- $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 "&gt; " and "&gt;&gt; ".
<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>

View file

@ -1,145 +0,0 @@
<!-- $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>

View file

@ -19,7 +19,7 @@ Lua 5.2 Reference Manual
by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
<p>
<small>
Copyright &copy; 2011&ndash;2013 Lua.org, PUC-Rio.
Copyright &copy; 2011&ndash;2015 Lua.org, PUC-Rio.
Freely available under the terms of the
<a href="http://www.lua.org/license.html">Lua license</a>.
</small>
@ -33,7 +33,7 @@ Freely available under the terms of the
<!-- ====================================================================== -->
<p>
<!-- $Id: manual.of,v 1.103 2013/03/14 18:51:56 roberto Exp $ -->
<!-- $Id: manual.of,v 1.104 2013/06/01 00:13:11 roberto Exp $ -->
@ -2088,7 +2088,7 @@ the length of a table <code>t</code> is only defined if the
table is a <em>sequence</em>,
that is,
the set of its positive numeric keys is equal to <em>{1..n}</em>
for some integer <em>n</em>.
for some non-negative integer <em>n</em>.
In that case, <em>n</em> is its length.
Note that a table like
@ -4065,7 +4065,7 @@ Note that <code>f</code> is used twice.
<p>
Pushes onto the stack a formatted string
and returns a pointer to this string.
It is similar to the ANSI&nbsp;C function <code>sprintf</code>,
It is similar to the ISO&nbsp;C function <code>sprintf</code>,
but has some important differences:
<ul>
@ -7906,7 +7906,7 @@ after the two indices.
<p>
Returns a formatted version of its variable number of arguments
following the description given in its first argument (which must be a string).
The format string follows the same rules as the ANSI&nbsp;C function <code>sprintf</code>.
The format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.
The only differences are that the options/modifiers
<code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>,
and <code>p</code> are not supported
@ -9486,7 +9486,7 @@ if the information is not available.
<p>
If <code>format</code> is not "<code>*t</code>",
then <code>date</code> returns the date as a string,
formatted according to the same rules as the ANSI&nbsp;C function <code>strftime</code>.
formatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.
<p>
@ -9521,7 +9521,7 @@ this value is exactly <code>t2</code><em>-</em><code>t1</code>.
<p>
This function is equivalent to the ANSI&nbsp;C function <code>system</code>.
This function is equivalent to the ISO&nbsp;C function <code>system</code>.
It passes <code>command</code> to be executed by an operating system shell.
Its first result is <b>true</b>
if the command terminated successfully,
@ -9556,7 +9556,7 @@ When called without a <code>command</code>,
<p>
Calls the ANSI&nbsp;C function <code>exit</code> to terminate the host program.
Calls the ISO&nbsp;C function <code>exit</code> to terminate the host program.
If <code>code</code> is <b>true</b>,
the returned status is <code>EXIT_SUCCESS</code>;
if <code>code</code> is <b>false</b>,
@ -9893,7 +9893,7 @@ returns <b>nil</b>.
Sets the given function as a hook.
The string <code>mask</code> and the number <code>count</code> describe
when the hook will be called.
The string mask may have the following characters,
The string mask may have any combination of the following characters,
with the given meaning:
<ul>
@ -9901,8 +9901,9 @@ with the given meaning:
<li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>
<li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>
</ul><p>
With a <code>count</code> different from zero,
the hook is called after every <code>count</code> instructions.
Moreover,
with a <code>count</code> different from zero,
the hook is called also after every <code>count</code> instructions.
<p>
@ -10497,10 +10498,10 @@ Here is the complete syntax of Lua in extended BNF.
<HR>
<SMALL CLASS="footer">
Last update:
Thu Mar 21 12:58:59 BRT 2013
Mon Feb 23 22:24:44 BRT 2015
</SMALL>
<!--
Last change: revised for Lua 5.2.2
Last change: revised for Lua 5.2.4
-->
</body></html>

View file

@ -98,8 +98,8 @@ If you don't have the time or the inclination to compile Lua yourself,
get a binary from
<A HREF="http://lua-users.org/wiki/LuaBinaries">LuaBinaries</A>.
Try also
<A HREF="http://luaforwindows.luaforge.net/">Lua for Windows</A>,
an easy-to-use distribution of Lua that includes many useful libraries.
<A HREF="http://luadist.org/">LuaDist</A>,
a multi-platform distribution of Lua that includes batteries.
<H3>Building Lua</H3>
@ -110,8 +110,8 @@ Here are the details.
<OL>
<LI>
Open a terminal window and move to
the top-level directory, which is named <TT>lua-5.2.3</TT>.
The Makefile there controls both the build process and the installation process.
the top-level directory, which is named <TT>lua-5.2.x</TT>.
The <TT>Makefile</TT> there controls both the build process and the installation process.
<P>
<LI>
Do "<KBD>make</KBD>" and see if your platform is listed.
@ -136,11 +136,12 @@ and liblua.a (the library).
<P>
<LI>
To check that Lua has been built correctly, do "<KBD>make test</KBD>"
after building Lua. This will run the interpreter and print its version string.
after building Lua. This will run the interpreter and print its version.
</OL>
<P>
If you're running Linux and get compilation errors,
make sure you have installed the <TT>readline</TT> development package.
make sure you have installed the <TT>readline</TT> development package
(which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).
If you get link errors after that,
then try "<KBD>make linux MYLIBS=-ltermcap</KBD>".
@ -148,7 +149,7 @@ then try "<KBD>make linux MYLIBS=-ltermcap</KBD>".
<P>
Once you have built Lua, you may want to install it in an official
place in your system. In this case, do "<KBD>make install</KBD>". The official
place and the way to install files are defined in the Makefile. You'll
place and the way to install files are defined in the <TT>Makefile</TT>. You'll
probably need the right permissions to install files.
<P>
@ -158,11 +159,13 @@ then try "<KBD>make linux MYLIBS=-ltermcap</KBD>".
<P>
To install Lua locally, do "<KBD>make local</KBD>".
This will create a directory <TT>install</TT> with subdirectories
<TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>,
<TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, <TT>share</TT>,
and install Lua as listed below.
To install Lua locally, but in some other directory, do
"<KBD>make install INSTALL_TOP=xxx</KBD>", where xxx is your chosen directory.
The installation starts in the <TT>src</TT> and <TT>doc</TT> directories,
so take care if <TT>INSTALL_TOP</TT> is not an absolute path.
<DL CLASS="display">
<DT>
@ -186,8 +189,8 @@ then try "<KBD>make linux MYLIBS=-ltermcap</KBD>".
<P>
These are the only directories you need for development.
If you only want to run Lua programs,
you only need the files in bin and man.
The files in include and lib are needed for
you only need the files in <TT>bin</TT> and <TT>man</TT>.
The files in <TT>include</TT> and <TT>lib</TT> are needed for
embedding Lua in C or C++ programs.
<H3><A NAME="customization">Customization</A></H3>
@ -203,7 +206,7 @@ then try "<KBD>make linux MYLIBS=-ltermcap</KBD>".
You don't actually need to edit the Makefiles because you may set the
relevant variables in the command line when invoking make.
Nevertheless, it's probably best to edit and save the Makefiles to
record the changes you need.
record the changes you've made.
<P>
On the other hand, if you need to customize some Lua features, you'll need
@ -254,6 +257,7 @@ compiler:
be linked statically into the host program and its symbols exported for
dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.
For Windows, we recommend that the Lua library be a DLL.
In all cases, the compiler luac should be linked statically.
<P>
As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize
@ -375,7 +379,7 @@ For details, see
<A HREF="http://www.lua.org/license.html">this</A>.
<BLOCKQUOTE STYLE="padding-bottom: 0em">
Copyright &copy; 1994&ndash;2013 Lua.org, PUC-Rio.
Copyright &copy; 1994&ndash;2015 Lua.org, PUC-Rio.
<P>
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -403,10 +407,10 @@ THE SOFTWARE.
<HR>
<SMALL CLASS="footer">
Last update:
Sat Nov 9 22:39:16 BRST 2013
Mon Feb 23 22:25:08 BRT 2015
</SMALL>
<!--
Last change: revised for Lua 5.2.3
Last change: revised for Lua 5.2.4
-->
</BODY>

View file

@ -1,44 +0,0 @@
# makefile for Lua etc
TOP= ..
LIB= $(TOP)/src
INC= $(TOP)/src
BIN= $(TOP)/src
SRC= $(TOP)/src
TST= $(TOP)/test
CC= gcc
CFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS)
MYCFLAGS=
MYLDFLAGS= -Wl,-E
MYLIBS= -lm
#MYLIBS= -lm -Wl,-E -ldl -lreadline -lhistory -lncurses
RM= rm -f
default:
@echo 'Please choose a target: min noparser one strict clean'
min: min.c
$(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS)
echo 'print"Hello there!"' | ./a.out
noparser: noparser.o
$(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS)
$(BIN)/luac $(TST)/hello.lua
-./a.out luac.out
-./a.out -e'a=1'
one:
$(CC) $(CFLAGS) all.c $(MYLIBS)
./a.out $(TST)/hello.lua
strict:
-$(BIN)/lua -e 'print(a);b=2'
-$(BIN)/lua -lstrict -e 'print(a)'
-$(BIN)/lua -e 'function f() b=2 end f()'
-$(BIN)/lua -lstrict -e 'function f() b=2 end f()'
clean:
$(RM) a.out core core.* *.o luac.out
.PHONY: default min noparser one strict clean

View file

@ -1,37 +0,0 @@
This directory contains some useful files and code.
Unlike the code in ../src, everything here is in the public domain.
If any of the makes fail, you're probably not using the same libraries
used to build Lua. Set MYLIBS in Makefile accordingly.
all.c
Full Lua interpreter in a single file.
Do "make one" for a demo.
lua.hpp
Lua header files for C++ using 'extern "C"'.
lua.ico
A Lua icon for Windows (and web sites: save as favicon.ico).
Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.
lua.pc
pkg-config data for Lua
luavs.bat
Script to build Lua under "Visual Studio .NET Command Prompt".
Run it from the toplevel as etc\luavs.bat.
min.c
A minimal Lua interpreter.
Good for learning and for starting your own.
Do "make min" for a demo.
noparser.c
Linking with noparser.o avoids loading the parsing modules in lualib.a.
Do "make noparser" for a demo.
strict.lua
Traps uses of undeclared global variables.
Do "make strict" for a demo.

View file

@ -1,38 +0,0 @@
/*
* all.c -- Lua core, libraries and interpreter in a single file
*/
#define luaall_c
#include "lapi.c"
#include "lcode.c"
#include "ldebug.c"
#include "ldo.c"
#include "ldump.c"
#include "lfunc.c"
#include "lgc.c"
#include "llex.c"
#include "lmem.c"
#include "lobject.c"
#include "lopcodes.c"
#include "lparser.c"
#include "lstate.c"
#include "lstring.c"
#include "ltable.c"
#include "ltm.c"
#include "lundump.c"
#include "lvm.c"
#include "lzio.c"
#include "lauxlib.c"
#include "lbaselib.c"
#include "ldblib.c"
#include "liolib.c"
#include "linit.c"
#include "lmathlib.c"
#include "loadlib.c"
#include "loslib.c"
#include "lstrlib.c"
#include "ltablib.c"
#include "lua.c"

View file

@ -1,9 +0,0 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -1,31 +0,0 @@
# lua.pc -- pkg-config data for Lua
# vars from install Makefile
# grep '^V=' ../Makefile
V= 5.1
# grep '^R=' ../Makefile
R= 5.1.5
# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'
prefix= /usr/local
INSTALL_BIN= ${prefix}/bin
INSTALL_INC= ${prefix}/include
INSTALL_LIB= ${prefix}/lib
INSTALL_MAN= ${prefix}/man/man1
INSTALL_LMOD= ${prefix}/share/lua/${V}
INSTALL_CMOD= ${prefix}/lib/lua/${V}
# canonical vars
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: Lua
Description: An Extensible Extension Language
Version: ${R}
Requires:
Libs: -L${libdir} -llua -lm
Cflags: -I${includedir}
# (end of lua.pc)

View file

@ -1,28 +0,0 @@
@rem Script to build Lua under "Visual Studio .NET Command Prompt".
@rem Do not run from this directory; run it from the toplevel: etc\luavs.bat .
@rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.
@rem (contributed by David Manura and Mike Pall)
@setlocal
@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
@set MYLINK=link /nologo
@set MYMT=mt /nologo
cd src
%MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c
del lua.obj luac.obj
%MYLINK% /DLL /out:lua51.dll l*.obj
if exist lua51.dll.manifest^
%MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2
%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c
%MYLINK% /out:lua.exe lua.obj lua51.lib
if exist lua.exe.manifest^
%MYMT% -manifest lua.exe.manifest -outputresource:lua.exe
%MYCOMPILE% l*.c print.c
del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^
loslib.obj ltablib.obj lstrlib.obj loadlib.obj
%MYLINK% /out:luac.exe *.obj
if exist luac.exe.manifest^
%MYMT% -manifest luac.exe.manifest -outputresource:luac.exe
del *.obj *.manifest
cd ..

View file

@ -1,39 +0,0 @@
/*
* min.c -- a minimal Lua interpreter
* loads stdin only with minimal error handling.
* no interaction, and no standard library, only a "print" function.
*/
#include <stdio.h>
#include "lua.h"
#include "lauxlib.h"
static int print(lua_State *L)
{
int n=lua_gettop(L);
int i;
for (i=1; i<=n; i++)
{
if (i>1) printf("\t");
if (lua_isstring(L,i))
printf("%s",lua_tostring(L,i));
else if (lua_isnil(L,i))
printf("%s","nil");
else if (lua_isboolean(L,i))
printf("%s",lua_toboolean(L,i) ? "true" : "false");
else
printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i));
}
printf("\n");
return 0;
}
int main(void)
{
lua_State *L=lua_open();
lua_register(L,"print",print);
if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1));
lua_close(L);
return 0;
}

View file

@ -1,50 +0,0 @@
/*
* The code below can be used to make a Lua core that does not contain the
* parsing modules (lcode, llex, lparser), which represent 35% of the total core.
* You'll only be able to load binary files and strings, precompiled with luac.
* (Of course, you'll have to build luac with the original parsing modules!)
*
* To use this module, simply compile it ("make noparser" does that) and list
* its object file before the Lua libraries. The linker should then not load
* the parsing modules. To try it, do "make luab".
*
* If you also want to avoid the dump module (ldump.o), define NODUMP.
* #define NODUMP
*/
#define LUA_CORE
#include "llex.h"
#include "lparser.h"
#include "lzio.h"
LUAI_FUNC void luaX_init (lua_State *L) {
UNUSED(L);
}
LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
UNUSED(z);
UNUSED(buff);
UNUSED(name);
lua_pushliteral(L,"parser not loaded");
lua_error(L);
return NULL;
}
#ifdef NODUMP
#include "lundump.h"
LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) {
UNUSED(f);
UNUSED(w);
UNUSED(data);
UNUSED(strip);
#if 1
UNUSED(L);
return 0;
#else
lua_pushliteral(L,"dumper not loaded");
lua_error(L);
#endif
}
#endif

View file

@ -1,41 +0,0 @@
--
-- strict.lua
-- checks uses of undeclared global variables
-- All global variables must be 'declared' through a regular assignment
-- (even assigning nil will do) in a main chunk before being used
-- anywhere or assigned to inside a function.
--
local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget
local mt = getmetatable(_G)
if mt == nil then
mt = {}
setmetatable(_G, mt)
end
mt.__declared = {}
local function what ()
local d = getinfo(3, "S")
return d and d.what or "C"
end
mt.__newindex = function (t, n, v)
if not mt.__declared[n] then
local w = what()
if w ~= "main" and w ~= "C" then
error("assign to undeclared variable '"..n.."'", 2)
end
mt.__declared[n] = true
end
rawset(t, n, v)
end
mt.__index = function (t, n)
if not mt.__declared[n] and what() ~= "C" then
error("variable '"..n.."' is not declared", 2)
end
return rawget(t, n)
end

View file

@ -26,7 +26,7 @@ MYOBJS=
# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
PLATS= aix ansi bsd freebsd generic linux linux32bit macosx macosx32bit mingw posix posix32bit solaris
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
LUA_A= liblua.a
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
@ -115,10 +115,7 @@ mingw:
$(MAKE) "LUAC_T=luac.exe" luac.exe
posix:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -fPIC -DLUA_USE_DLOPEN" SYSLIBS="-ldl"
posix32bit:
$(MAKE) $(ALL) SYSCFLAGS="-m32 -DLUA_USE_POSIX -fPIC -DLUA_USE_DLOPEN" SYSLDFLAGS="-m32" SYSLIBS="-ldl"
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
solaris:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl"

View file

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.132.1.1 2013/04/12 18:48:47 roberto Exp $
** $Id: ldblib.c,v 1.132.1.2 2015/02/19 17:16:55 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -21,6 +21,11 @@
#define HOOKKEY "_HKEY"
static void checkstack (lua_State *L, lua_State *L1, int n) {
if (L != L1 && !lua_checkstack(L1, n))
luaL_error(L, "stack overflow");
}
static int db_getregistry (lua_State *L) {
lua_pushvalue(L, LUA_REGISTRYINDEX);
@ -114,6 +119,7 @@ static int db_getinfo (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
const char *options = luaL_optstring(L, arg+2, "flnStu");
checkstack(L, L1, 3);
if (lua_isnumber(L, arg+1)) {
if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
lua_pushnil(L); /* level out of range */
@ -173,6 +179,7 @@ static int db_getlocal (lua_State *L) {
else { /* stack-level argument */
if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
return luaL_argerror(L, arg+1, "level out of range");
checkstack(L, L1, 1);
name = lua_getlocal(L1, &ar, nvar);
if (name) {
lua_xmove(L1, L, 1); /* push local value */
@ -196,6 +203,7 @@ static int db_setlocal (lua_State *L) {
return luaL_argerror(L, arg+1, "level out of range");
luaL_checkany(L, arg+3);
lua_settop(L, arg+3);
checkstack(L, L1, 1);
lua_xmove(L, L1, 1);
lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
return 1;
@ -313,6 +321,7 @@ static int db_sethook (lua_State *L) {
lua_pushvalue(L, -1);
lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
}
checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_pushvalue(L, arg+1);
lua_rawset(L, -3); /* set new hook */
@ -331,6 +340,7 @@ static int db_gethook (lua_State *L) {
lua_pushliteral(L, "external hook");
else {
gethooktable(L);
checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_rawget(L, -2); /* get hook */
lua_remove(L, -2); /* remove hook table */

View file

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.90.1.3 2013/05/16 16:04:15 roberto Exp $
** $Id: ldebug.c,v 2.90.1.4 2015/02/19 17:05:13 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -47,6 +47,16 @@ static int currentline (CallInfo *ci) {
}
static void swapextra (lua_State *L) {
if (L->status == LUA_YIELD) {
CallInfo *ci = L->ci; /* get function that yielded */
StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
ci->func = restorestack(L, ci->extra);
ci->extra = savestack(L, temp);
}
}
/*
** this function can be called asynchronous (e.g. during a signal)
*/
@ -144,6 +154,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name;
lua_lock(L);
swapextra(L);
if (ar == NULL) { /* information about non-active function? */
if (!isLfunction(L->top - 1)) /* not a Lua function? */
name = NULL;
@ -158,6 +169,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
api_incr_top(L);
}
}
swapextra(L);
lua_unlock(L);
return name;
}
@ -165,11 +177,14 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
StkId pos = 0; /* to avoid warnings */
const char *name = findlocal(L, ar->i_ci, n, &pos);
const char *name;
lua_lock(L);
swapextra(L);
name = findlocal(L, ar->i_ci, n, &pos);
if (name)
setobjs2s(L, pos, L->top - 1);
L->top--; /* pop value */
swapextra(L);
lua_unlock(L);
return name;
}
@ -269,6 +284,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
CallInfo *ci;
StkId func;
lua_lock(L);
swapextra(L);
if (*what == '>') {
ci = NULL;
func = L->top - 1;
@ -287,6 +303,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
setobjs2s(L, L->top, func);
api_incr_top(L);
}
swapextra(L);
if (strchr(what, 'L'))
collectvalidlines(L, cl);
lua_unlock(L);

View file

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 2.140.1.2 2013/04/26 18:22:05 roberto Exp $
** $Id: lgc.c,v 2.140.1.3 2014/09/01 16:55:08 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -403,7 +403,7 @@ static int traverseephemeron (global_State *g, Table *h) {
reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
}
}
if (prop)
if (g->gcstate != GCSatomic || prop)
linktable(h, &g->ephemeron); /* have to propagate again */
else if (hasclears) /* does table have white keys? */
linktable(h, &g->allweak); /* may have to clean white keys */

View file

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 2.63.1.2 2013/08/30 15:49:41 roberto Exp $
** $Id: llex.c,v 2.63.1.3 2015/02/09 17:56:34 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -152,7 +152,7 @@ static void inclinenumber (LexState *ls) {
if (currIsNewline(ls) && ls->current != old)
next(ls); /* skip `\n\r' or `\r\n' */
if (++ls->linenumber >= MAX_INT)
luaX_syntaxerror(ls, "chunk has too many lines");
lexerror(ls, "chunk has too many lines", 0);
}

View file

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.71.1.1 2013/04/12 18:48:47 roberto Exp $
** $Id: lobject.h,v 2.71.1.2 2014/05/07 14:14:58 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -561,12 +561,12 @@ typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* log2 of size of `node' array */
struct Table *metatable;
int sizearray; /* size of `array' array */
TValue *array; /* array part */
Node *node;
Node *lastfree; /* any free position is before this position */
struct Table *metatable;
GCObject *gclist;
int sizearray; /* size of `array' array */
} Table;

View file

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.142.1.1 2013/04/12 18:48:47 roberto Exp $
** $Id: lopcodes.h,v 1.142.1.2 2014/10/20 18:32:09 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -196,7 +196,7 @@ OP_LEN,/* A B R(A) := length of R(B) */
OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1) */
OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */

View file

@ -1,10 +1,11 @@
/*
** $Id: ltablib.c,v 1.65.1.1 2013/04/12 18:48:47 roberto Exp $
** $Id: ltablib.c,v 1.65.1.2 2014/05/07 16:32:55 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
#include <limits.h>
#include <stddef.h>
#define ltablib_c
@ -134,13 +135,14 @@ static int pack (lua_State *L) {
static int unpack (lua_State *L) {
int i, e, n;
int i, e;
unsigned int n;
luaL_checktype(L, 1, LUA_TTABLE);
i = luaL_optint(L, 2, 1);
e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
if (i > e) return 0; /* empty range */
n = e - i + 1; /* number of elements */
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n))
return luaL_error(L, "too many results to unpack");
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
while (i++ < e) /* push arg[i + 1...e] */

View file

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.285.1.2 2013/11/11 12:09:16 roberto Exp $
** $Id: lua.h,v 1.285.1.4 2015/02/21 14:04:50 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -19,11 +19,11 @@
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "2"
#define LUA_VERSION_NUM 502
#define LUA_VERSION_RELEASE "3"
#define LUA_VERSION_RELEASE "4"
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2013 Lua.org, PUC-Rio"
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
@ -418,7 +418,7 @@ struct lua_Debug {
/******************************************************************************
* Copyright (C) 1994-2013 Lua.org, PUC-Rio.
* Copyright (C) 1994-2015 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

View file

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.176.1.1 2013/04/12 18:48:47 roberto Exp $
** $Id: luaconf.h,v 1.176.1.2 2013/11/21 17:26:16 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -326,7 +326,7 @@
/*
@@ LUA_INT32 is an signed integer with exactly 32 bits.
@@ LUA_INT32 is a signed integer with exactly 32 bits.
@@ LUAI_UMEM is an unsigned integer big enough to count the total
@* memory used by Lua.
@@ LUAI_MEM is a signed integer big enough to count the total memory
@ -350,7 +350,7 @@
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua to consume unlimited stack
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32

View file

@ -1,227 +0,0 @@
/*
** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
*/
#include <ctype.h>
#include <stdio.h>
#define luac_c
#define LUA_CORE
#include "ldebug.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lundump.h"
#define PrintFunction luaU_print
#define Sizeof(x) ((int)sizeof(x))
#define VOID(p) ((const void*)(p))
static void PrintString(const TString* ts)
{
const char* s=getstr(ts);
size_t i,n=ts->tsv.len;
putchar('"');
for (i=0; i<n; i++)
{
int c=s[i];
switch (c)
{
case '"': printf("\\\""); break;
case '\\': printf("\\\\"); break;
case '\a': printf("\\a"); break;
case '\b': printf("\\b"); break;
case '\f': printf("\\f"); break;
case '\n': printf("\\n"); break;
case '\r': printf("\\r"); break;
case '\t': printf("\\t"); break;
case '\v': printf("\\v"); break;
default: if (isprint((unsigned char)c))
putchar(c);
else
printf("\\%03u",(unsigned char)c);
}
}
putchar('"');
}
static void PrintConstant(const Proto* f, int i)
{
const TValue* o=&f->k[i];
switch (ttype(o))
{
case LUA_TNIL:
printf("nil");
break;
case LUA_TBOOLEAN:
printf(bvalue(o) ? "true" : "false");
break;
case LUA_TNUMBER:
printf(LUA_NUMBER_FMT,nvalue(o));
break;
case LUA_TSTRING:
PrintString(rawtsvalue(o));
break;
default: /* cannot happen */
printf("? type=%d",ttype(o));
break;
}
}
static void PrintCode(const Proto* f)
{
const Instruction* code=f->code;
int pc,n=f->sizecode;
for (pc=0; pc<n; pc++)
{
Instruction i=code[pc];
OpCode o=GET_OPCODE(i);
int a=GETARG_A(i);
int b=GETARG_B(i);
int c=GETARG_C(i);
int bx=GETARG_Bx(i);
int sbx=GETARG_sBx(i);
int line=getline(f,pc);
printf("\t%d\t",pc+1);
if (line>0) printf("[%d]\t",line); else printf("[-]\t");
printf("%-9s\t",luaP_opnames[o]);
switch (getOpMode(o))
{
case iABC:
printf("%d",a);
if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
break;
case iABx:
if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
break;
case iAsBx:
if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
break;
}
switch (o)
{
case OP_LOADK:
printf("\t; "); PrintConstant(f,bx);
break;
case OP_GETUPVAL:
case OP_SETUPVAL:
printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
break;
case OP_GETGLOBAL:
case OP_SETGLOBAL:
printf("\t; %s",svalue(&f->k[bx]));
break;
case OP_GETTABLE:
case OP_SELF:
if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
break;
case OP_SETTABLE:
case OP_ADD:
case OP_SUB:
case OP_MUL:
case OP_DIV:
case OP_POW:
case OP_EQ:
case OP_LT:
case OP_LE:
if (ISK(b) || ISK(c))
{
printf("\t; ");
if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
printf(" ");
if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
}
break;
case OP_JMP:
case OP_FORLOOP:
case OP_FORPREP:
printf("\t; to %d",sbx+pc+2);
break;
case OP_CLOSURE:
printf("\t; %p",VOID(f->p[bx]));
break;
case OP_SETLIST:
if (c==0) printf("\t; %d",(int)code[++pc]);
else printf("\t; %d",c);
break;
default:
break;
}
printf("\n");
}
}
#define SS(x) (x==1)?"":"s"
#define S(x) x,SS(x)
static void PrintHeader(const Proto* f)
{
const char* s=getstr(f->source);
if (*s=='@' || *s=='=')
s++;
else if (*s==LUA_SIGNATURE[0])
s="(bstring)";
else
s="(string)";
printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
(f->linedefined==0)?"main":"function",s,
f->linedefined,f->lastlinedefined,
S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
f->numparams,f->is_vararg?"+":"",SS(f->numparams),
S(f->maxstacksize),S(f->nups));
printf("%d local%s, %d constant%s, %d function%s\n",
S(f->sizelocvars),S(f->sizek),S(f->sizep));
}
static void PrintConstants(const Proto* f)
{
int i,n=f->sizek;
printf("constants (%d) for %p:\n",n,VOID(f));
for (i=0; i<n; i++)
{
printf("\t%d\t",i+1);
PrintConstant(f,i);
printf("\n");
}
}
static void PrintLocals(const Proto* f)
{
int i,n=f->sizelocvars;
printf("locals (%d) for %p:\n",n,VOID(f));
for (i=0; i<n; i++)
{
printf("\t%d\t%s\t%d\t%d\n",
i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
}
}
static void PrintUpvalues(const Proto* f)
{
int i,n=f->sizeupvalues;
printf("upvalues (%d) for %p:\n",n,VOID(f));
if (f->upvalues==NULL) return;
for (i=0; i<n; i++)
{
printf("\t%d\t%s\n",i,getstr(f->upvalues[i]));
}
}
void PrintFunction(const Proto* f, int full)
{
int i,n=f->sizep;
PrintHeader(f);
PrintCode(f);
if (full)
{
PrintConstants(f);
PrintLocals(f);
PrintUpvalues(f);
}
for (i=0; i<n; i++) PrintFunction(f->p[i],full);
}

View file

@ -1,26 +0,0 @@
These are simple tests for Lua. Some of them contain useful code.
They are meant to be run to make sure Lua is built correctly and also
to be read, to see how Lua programs look.
Here is a one-line summary of each program:
bisect.lua bisection method for solving non-linear equations
cf.lua temperature conversion table (celsius to farenheit)
echo.lua echo command line arguments
env.lua environment variables as automatic global variables
factorial.lua factorial without recursion
fib.lua fibonacci function with cache
fibfor.lua fibonacci numbers with coroutines and generators
globals.lua report global variable usage
hello.lua the first program in every language
life.lua Conway's Game of Life
luac.lua bare-bones luac
printf.lua an implementation of printf
readonly.lua make global variables readonly
sieve.lua the sieve of of Eratosthenes programmed with coroutines
sort.lua two implementations of a sort function
table.lua make table, grouping all data for the same item
trace-calls.lua trace calls
trace-globals.lua trace assigments to global variables
xd.lua hex dump

View file

@ -1,27 +0,0 @@
-- bisection method for solving non-linear equations
delta=1e-6 -- tolerance
function bisect(f,a,b,fa,fb)
local c=(a+b)/2
io.write(n," c=",c," a=",a," b=",b,"\n")
if c==a or c==b or math.abs(a-b)<delta then return c,b-a end
n=n+1
local fc=f(c)
if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end
end
-- find root of f in the inverval [a,b]. needs f(a)*f(b)<0
function solve(f,a,b)
n=0
local z,e=bisect(f,a,b,f(a),f(b))
io.write(string.format("after %d steps, root is %.17g with error %.1e, f=%.1e\n",n,z,e,f(z)))
end
-- our function
function f(x)
return x*x*x-x-1
end
-- find zero in [1,2]
solve(f,1,2)

View file

@ -1,16 +0,0 @@
-- temperature conversion table (celsius to farenheit)
for c0=-20,50-1,10 do
io.write("C ")
for c=c0,c0+10-1 do
io.write(string.format("%3.0f ",c))
end
io.write("\n")
io.write("F ")
for c=c0,c0+10-1 do
f=(9/5)*c+32
io.write(string.format("%3.0f ",f))
end
io.write("\n\n")
end

View file

@ -1,5 +0,0 @@
-- echo command line arguments
for i=0,table.getn(arg) do
print(i,arg[i])
end

View file

@ -1,7 +0,0 @@
-- read environment variables as if they were global variables
local f=function (t,i) return os.getenv(i) end
setmetatable(getfenv(),{__index=f})
-- an example
print(a,USER,PATH)

View file

@ -1,32 +0,0 @@
-- function closures are powerful
-- traditional fixed-point operator from functional programming
Y = function (g)
local a = function (f) return f(f) end
return a(function (f)
return g(function (x)
local c=f(f)
return c(x)
end)
end)
end
-- factorial without recursion
F = function (f)
return function (n)
if n == 0 then return 1
else return n*f(n-1) end
end
end
factorial = Y(F) -- factorial is the fixed point of F
-- now test it
function test(x)
io.write(x,"! = ",factorial(x),"\n")
end
for n=0,16 do
test(n)
end

View file

@ -1,40 +0,0 @@
-- fibonacci function with cache
-- very inefficient fibonacci function
function fib(n)
N=N+1
if n<2 then
return n
else
return fib(n-1)+fib(n-2)
end
end
-- a general-purpose value cache
function cache(f)
local c={}
return function (x)
local y=c[x]
if not y then
y=f(x)
c[x]=y
end
return y
end
end
-- run and time it
function test(s,f)
N=0
local c=os.clock()
local v=f(n)
local t=os.clock()-c
print(s,n,v,t,N)
end
n=arg[1] or 24 -- for other values, do lua fib.lua XX
n=tonumber(n)
print("","n","value","time","evals")
test("plain",fib)
fib=cache(fib)
test("cached",fib)

View file

@ -1,13 +0,0 @@
-- example of for with generator functions
function generatefib (n)
return coroutine.wrap(function ()
local a,b = 1, 1
while a <= n do
coroutine.yield(a)
a, b = b, a+b
end
end)
end
for i in generatefib(1000) do print(i) end

View file

@ -1,13 +0,0 @@
-- reads luac listings and reports global variable usage
-- lines where a global is written to are marked with "*"
-- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua
while 1 do
local s=io.read()
if s==nil then break end
local ok,_,l,op,g=string.find(s,"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$")
if ok then
if op=="S" then op="*" else op="" end
io.write(g,"\t",l,op,"\n")
end
end

View file

@ -1,3 +0,0 @@
-- the first program in every language
io.write("Hello world, from ",_VERSION,"!\n")

View file

@ -1,111 +0,0 @@
-- life.lua
-- original by Dave Bollinger <DBollinger@compuserve.com> posted to lua-l
-- modified to use ANSI terminal escape sequences
-- modified to use for instead of while
local write=io.write
ALIVE="¥" DEAD="þ"
ALIVE="O" DEAD="-"
function delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary
for i=1,10000 do end
-- local i=os.clock()+1 while(os.clock()<i) do end
end
function ARRAY2D(w,h)
local t = {w=w,h=h}
for y=1,h do
t[y] = {}
for x=1,w do
t[y][x]=0
end
end
return t
end
_CELLS = {}
-- give birth to a "shape" within the cell array
function _CELLS:spawn(shape,left,top)
for y=0,shape.h-1 do
for x=0,shape.w-1 do
self[top+y][left+x] = shape[y*shape.w+x+1]
end
end
end
-- run the CA and produce the next generation
function _CELLS:evolve(next)
local ym1,y,yp1,yi=self.h-1,self.h,1,self.h
while yi > 0 do
local xm1,x,xp1,xi=self.w-1,self.w,1,self.w
while xi > 0 do
local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] +
self[y][xm1] + self[y][xp1] +
self[yp1][xm1] + self[yp1][x] + self[yp1][xp1]
next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0
xm1,x,xp1,xi = x,xp1,xp1+1,xi-1
end
ym1,y,yp1,yi = y,yp1,yp1+1,yi-1
end
end
-- output the array to screen
function _CELLS:draw()
local out="" -- accumulate to reduce flicker
for y=1,self.h do
for x=1,self.w do
out=out..(((self[y][x]>0) and ALIVE) or DEAD)
end
out=out.."\n"
end
write(out)
end
-- constructor
function CELLS(w,h)
local c = ARRAY2D(w,h)
c.spawn = _CELLS.spawn
c.evolve = _CELLS.evolve
c.draw = _CELLS.draw
return c
end
--
-- shapes suitable for use with spawn() above
--
HEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 }
GLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 }
EXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 }
FISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 }
BUTTERFLY = { 1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1; w=5,h=5 }
-- the main routine
function LIFE(w,h)
-- create two arrays
local thisgen = CELLS(w,h)
local nextgen = CELLS(w,h)
-- create some life
-- about 1000 generations of fun, then a glider steady-state
thisgen:spawn(GLIDER,5,4)
thisgen:spawn(EXPLODE,25,10)
thisgen:spawn(FISH,4,12)
-- run until break
local gen=1
write("\027[2J") -- ANSI clear screen
while 1 do
thisgen:evolve(nextgen)
thisgen,nextgen = nextgen,thisgen
write("\027[H") -- ANSI home cursor
thisgen:draw()
write("Life - generation ",gen,"\n")
gen=gen+1
if gen>2000 then break end
--delay() -- no delay
end
end
LIFE(40,20)

View file

@ -1,7 +0,0 @@
-- bare-bones luac in Lua
-- usage: lua luac.lua file.lua
assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
f=assert(io.open("luac.out","wb"))
assert(f:write(string.dump(assert(loadfile(arg[1])))))
assert(f:close())

View file

@ -1,7 +0,0 @@
-- an implementation of printf
function printf(...)
io.write(string.format(...))
end
printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date())

View file

@ -1,12 +0,0 @@
-- make global variables readonly
local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end
local g={}
local G=getfenv()
setmetatable(g,{__index=G,__newindex=f})
setfenv(1,g)
-- an example
rawset(g,"x",3)
x=2
y=1 -- cannot redefine `y'

View file

@ -1,29 +0,0 @@
-- the sieve of of Eratosthenes programmed with coroutines
-- typical usage: lua -e N=1000 sieve.lua | column
-- generate all the numbers from 2 to n
function gen (n)
return coroutine.wrap(function ()
for i=2,n do coroutine.yield(i) end
end)
end
-- filter the numbers generated by `g', removing multiples of `p'
function filter (p, g)
return coroutine.wrap(function ()
while 1 do
local n = g()
if n == nil then return end
if math.mod(n, p) ~= 0 then coroutine.yield(n) end
end
end)
end
N=N or 1000 -- from command line
x = gen(N) -- generate primes up to N
while 1 do
local n = x() -- pick a number until done
if n == nil then break end
print(n) -- must be a prime number
x = filter(n, x) -- now remove its multiples
end

View file

@ -1,66 +0,0 @@
-- two implementations of a sort function
-- this is an example only. Lua has now a built-in function "sort"
-- extracted from Programming Pearls, page 110
function qsort(x,l,u,f)
if l<u then
local m=math.random(u-(l-1))+l-1 -- choose a random pivot in range l..u
x[l],x[m]=x[m],x[l] -- swap pivot to first position
local t=x[l] -- pivot value
m=l
local i=l+1
while i<=u do
-- invariant: x[l+1..m] < t <= x[m+1..i-1]
if f(x[i],t) then
m=m+1
x[m],x[i]=x[i],x[m] -- swap x[i] and x[m]
end
i=i+1
end
x[l],x[m]=x[m],x[l] -- swap pivot to a valid place
-- x[l+1..m-1] < x[m] <= x[m+1..u]
qsort(x,l,m-1,f)
qsort(x,m+1,u,f)
end
end
function selectionsort(x,n,f)
local i=1
while i<=n do
local m,j=i,i+1
while j<=n do
if f(x[j],x[m]) then m=j end
j=j+1
end
x[i],x[m]=x[m],x[i] -- swap x[i] and x[m]
i=i+1
end
end
function show(m,x)
io.write(m,"\n\t")
local i=1
while x[i] do
io.write(x[i])
i=i+1
if x[i] then io.write(",") end
end
io.write("\n")
end
function testsorts(x)
local n=1
while x[n] do n=n+1 end; n=n-1 -- count elements
show("original",x)
qsort(x,1,n,function (x,y) return x<y end)
show("after quicksort",x)
selectionsort(x,n,function (x,y) return x>y end)
show("after reverse selection sort",x)
qsort(x,1,n,function (x,y) return x<y end)
show("after quicksort again",x)
end
-- array to be sorted
x={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}
testsorts(x)

View file

@ -1,12 +0,0 @@
-- make table, grouping all data for the same item
-- input is 2 columns (item, data)
local A
while 1 do
local l=io.read()
if l==nil then break end
local _,_,a,b=string.find(l,'"?([_%w]+)"?%s*(.*)$')
if a~=A then A=a io.write("\n",a,":") end
io.write(" ",b)
end
io.write("\n")

View file

@ -1,32 +0,0 @@
-- trace calls
-- example: lua -ltrace-calls bisect.lua
local level=0
local function hook(event)
local t=debug.getinfo(3)
io.write(level," >>> ",string.rep(" ",level))
if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end
t=debug.getinfo(2)
if event=="call" then
level=level+1
else
level=level-1 if level<0 then level=0 end
end
if t.what=="main" then
if event=="call" then
io.write("begin ",t.short_src)
else
io.write("end ",t.short_src)
end
elseif t.what=="Lua" then
-- table.foreach(t,print)
io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">")
else
io.write(event," ",t.name or "(C)"," [",t.what,"] ")
end
io.write("\n")
end
debug.sethook(hook,"cr")
level=0

View file

@ -1,38 +0,0 @@
-- trace assigments to global variables
do
-- a tostring that quotes strings. note the use of the original tostring.
local _tostring=tostring
local tostring=function(a)
if type(a)=="string" then
return string.format("%q",a)
else
return _tostring(a)
end
end
local log=function (name,old,new)
local t=debug.getinfo(3,"Sl")
local line=t.currentline
io.write(t.short_src)
if line>=0 then io.write(":",line) end
io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n")
end
local g={}
local set=function (t,name,value)
log(name,g[name],value)
g[name]=value
end
setmetatable(getfenv(),{__index=g,__newindex=set})
end
-- an example
a=1
b=2
a=10
b=20
b=nil
b=200
print(a,b,c)

View file

@ -1,14 +0,0 @@
-- hex dump
-- usage: lua xd.lua < file
local offset=0
while true do
local s=io.read(16)
if s==nil then return end
io.write(string.format("%08X ",offset))
string.gsub(s,"(.)",
function (c) io.write(string.format("%02X ",string.byte(c))) end)
io.write(string.rep(" ",3*(16-string.len(s))))
io.write(" ",string.gsub(s,"%c","."),"\n")
offset=offset+16
end