diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-07 10:09:27 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-07 10:09:27 -0800 |
commit | 1f3ed8210d45b035a8f76185587f97e147fc7402 (patch) | |
tree | da907b4c8aef4e26e84d0ec4b7ab3a827cdb57ad | |
parent | 2b7ffea31612c16ab16735f6806195ab471ae409 (diff) | |
download | teliva-1f3ed8210d45b035a8f76185587f97e147fc7402.tar.gz |
delete some Lua 5.1 things
These are likely to suffer bitrot.
-rw-r--r-- | HISTORY | 183 | ||||
-rw-r--r-- | INSTALL | 99 | ||||
-rw-r--r-- | doc/lua.1 | 163 | ||||
-rw-r--r-- | doc/lua.html | 172 | ||||
-rw-r--r-- | doc/luac.1 | 136 | ||||
-rw-r--r-- | doc/luac.html | 145 | ||||
-rw-r--r-- | doc/readme.html | 40 | ||||
-rw-r--r-- | etc/Makefile | 44 | ||||
-rw-r--r-- | etc/README | 37 | ||||
-rw-r--r-- | etc/all.c | 38 | ||||
-rw-r--r-- | etc/lua.hpp | 9 | ||||
-rw-r--r-- | etc/lua.ico | bin | 1078 -> 0 bytes | |||
-rw-r--r-- | etc/lua.pc | 31 | ||||
-rw-r--r-- | etc/luavs.bat | 28 | ||||
-rw-r--r-- | etc/min.c | 39 | ||||
-rw-r--r-- | etc/noparser.c | 50 | ||||
-rw-r--r-- | etc/strict.lua | 41 | ||||
-rw-r--r-- | test/README | 26 | ||||
-rw-r--r-- | test/bisect.lua | 27 | ||||
-rw-r--r-- | test/cf.lua | 16 | ||||
-rw-r--r-- | test/echo.lua | 5 | ||||
-rw-r--r-- | test/env.lua | 7 | ||||
-rw-r--r-- | test/factorial.lua | 32 | ||||
-rw-r--r-- | test/fib.lua | 40 | ||||
-rw-r--r-- | test/fibfor.lua | 13 | ||||
-rw-r--r-- | test/globals.lua | 13 | ||||
-rw-r--r-- | test/hello.lua | 3 | ||||
-rw-r--r-- | test/life.lua | 111 | ||||
-rw-r--r-- | test/luac.lua | 7 | ||||
-rw-r--r-- | test/printf.lua | 7 | ||||
-rw-r--r-- | test/readonly.lua | 12 | ||||
-rw-r--r-- | test/sieve.lua | 29 | ||||
-rw-r--r-- | test/sort.lua | 66 | ||||
-rw-r--r-- | test/table.lua | 12 | ||||
-rw-r--r-- | test/trace-calls.lua | 32 | ||||
-rw-r--r-- | test/trace-globals.lua | 38 | ||||
-rw-r--r-- | test/xd.lua | 14 |
37 files changed, 0 insertions, 1765 deletions
diff --git a/HISTORY b/HISTORY deleted file mode 100644 index ce0c95b..0000000 --- a/HISTORY +++ /dev/null @@ -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) diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 17eb8ae..0000000 --- a/INSTALL +++ /dev/null @@ -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) diff --git a/doc/lua.1 b/doc/lua.1 deleted file mode 100644 index 24809cc..0000000 --- a/doc/lua.1 +++ /dev/null @@ -1,163 +0,0 @@ -.\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -.TH LUA 1 "$Date: 2006/01/06 16:03:34 $" -.SH NAME -lua \- Lua interpreter -.SH SYNOPSIS -.B lua -[ -.I options -] -[ -.I script -[ -.I args -] -] -.SH DESCRIPTION -.B lua -is the stand-alone Lua interpreter. -It loads and executes Lua programs, -either in textual source form or -in precompiled binary form. -(Precompiled binaries are output by -.BR luac , -the Lua compiler.) -.B lua -can be used as a batch interpreter and also interactively. -.LP -The given -.I options -(see below) -are executed and then -the Lua program in file -.I script -is loaded and executed. -The given -.I args -are available to -.I script -as strings in a global table named -.BR arg . -If these arguments contain spaces or other characters special to the shell, -then they should be quoted -(but note that the quotes will be removed by the shell). -The arguments in -.B arg -start at 0, -which contains the string -.RI ' script '. -The index of the last argument is stored in -.BR arg.n . -The arguments given in the command line before -.IR script , -including the name of the interpreter, -are available in negative indices in -.BR arg . -.LP -At the very start, -before even handling the command line, -.B lua -executes the contents of the environment variable -.BR LUA_INIT , -if it is defined. -If the value of -.B LUA_INIT -is of the form -.RI '@ filename ', -then -.I filename -is executed. -Otherwise, the string is assumed to be a Lua statement and is executed. -.LP -Options start with -.B '\-' -and are described below. -You can use -.B "'\--'" -to signal the end of options. -.LP -If no arguments are given, -then -.B "\-v \-i" -is assumed when the standard input is a terminal; -otherwise, -.B "\-" -is assumed. -.LP -In interactive mode, -.B lua -prompts the user, -reads lines from the standard input, -and executes them as they are read. -If a line does not contain a complete statement, -then a secondary prompt is displayed and -lines are read until a complete statement is formed or -a syntax error is found. -So, one way to interrupt the reading of an incomplete statement is -to force a syntax error: -adding a -.B ';' -in the middle of a statement is a sure way of forcing a syntax error -(except inside multiline strings and comments; these must be closed explicitly). -If a line starts with -.BR '=' , -then -.B lua -displays the values of all the expressions in the remainder of the -line. The expressions must be separated by commas. -The primary prompt is the value of the global variable -.BR _PROMPT , -if this value is a string; -otherwise, the default prompt is used. -Similarly, the secondary prompt is the value of the global variable -.BR _PROMPT2 . -So, -to change the prompts, -set the corresponding variable to a string of your choice. -You can do that after calling the interpreter -or on the command line -(but in this case you have to be careful with quotes -if the prompt string contains a space; otherwise you may confuse the shell.) -The default prompts are "> " and ">> ". -.SH OPTIONS -.TP -.B \- -load and execute the standard input as a file, -that is, -not interactively, -even when the standard input is a terminal. -.TP -.BI \-e " stat" -execute statement -.IR stat . -You need to quote -.I stat -if it contains spaces, quotes, -or other characters special to the shell. -.TP -.B \-i -enter interactive mode after -.I script -is executed. -.TP -.BI \-l " name" -call -.BI require(' name ') -before executing -.IR script . -Typically used to load libraries. -.TP -.B \-v -show version information. -.SH "SEE ALSO" -.BR luac (1) -.br -http://www.lua.org/ -.SH DIAGNOSTICS -Error messages should be self explanatory. -.SH AUTHORS -R. Ierusalimschy, -L. H. de Figueiredo, -and -W. Celes -.\" EOF diff --git a/doc/lua.html b/doc/lua.html deleted file mode 100644 index 1d435ab..0000000 --- a/doc/lua.html +++ /dev/null @@ -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 "> " and ">> ". -<H2>OPTIONS</H2> -<P> -<B>-</B> -load and execute the standard input as a file, -that is, -not interactively, -even when the standard input is a terminal. -<P> -<B>-e </B><I>stat</I> -execute statement -<I>stat</I>. -You need to quote -<I>stat </I> -if it contains spaces, quotes, -or other characters special to the shell. -<P> -<B>-i</B> -enter interactive mode after -<I>script</I> -is executed. -<P> -<B>-l </B><I>name</I> -call -<B>require</B>('<I>name</I>') -before executing -<I>script</I>. -Typically used to load libraries. -<P> -<B>-v</B> -show version information. -<H2>SEE ALSO</H2> -<B>luac</B>(1) -<BR> -<A HREF="http://www.lua.org/">http://www.lua.org/</A> -<H2>DIAGNOSTICS</H2> -Error messages should be self explanatory. -<H2>AUTHORS</H2> -R. Ierusalimschy, -L. H. de Figueiredo, -and -W. Celes -<!-- EOF --> -</BODY> -</HTML> diff --git a/doc/luac.1 b/doc/luac.1 deleted file mode 100644 index d814678..0000000 --- a/doc/luac.1 +++ /dev/null @@ -1,136 +0,0 @@ -.\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ -.TH LUAC 1 "$Date: 2006/01/06 16:03:34 $" -.SH NAME -luac \- Lua compiler -.SH SYNOPSIS -.B luac -[ -.I options -] [ -.I filenames -] -.SH DESCRIPTION -.B luac -is the Lua compiler. -It translates programs written in the Lua programming language -into binary files that can be later loaded and executed. -.LP -The main advantages of precompiling chunks are: -faster loading, -protecting source code from accidental user changes, -and -off-line syntax checking. -.LP -Pre-compiling does not imply faster execution -because in Lua chunks are always compiled into bytecodes before being executed. -.B luac -simply allows those bytecodes to be saved in a file for later execution. -.LP -Pre-compiled chunks are not necessarily smaller than the corresponding source. -The main goal in pre-compiling is faster loading. -.LP -The binary files created by -.B luac -are portable only among architectures with the same word size and byte order. -.LP -.B luac -produces a single output file containing the bytecodes -for all source files given. -By default, -the output file is named -.BR luac.out , -but you can change this with the -.B \-o -option. -.LP -In the command line, -you can mix -text files containing Lua source and -binary files containing precompiled chunks. -This is useful to combine several precompiled chunks, -even from different (but compatible) platforms, -into a single precompiled chunk. -.LP -You can use -.B "'\-'" -to indicate the standard input as a source file -and -.B "'\--'" -to signal the end of options -(that is, -all remaining arguments will be treated as files even if they start with -.BR "'\-'" ). -.LP -The internal format of the binary files produced by -.B luac -is likely to change when a new version of Lua is released. -So, -save the source files of all Lua programs that you precompile. -.LP -.SH OPTIONS -Options must be separate. -.TP -.B \-l -produce a listing of the compiled bytecode for Lua's virtual machine. -Listing bytecodes is useful to learn about Lua's virtual machine. -If no files are given, then -.B luac -loads -.B luac.out -and lists its contents. -.TP -.BI \-o " file" -output to -.IR file , -instead of the default -.BR luac.out . -(You can use -.B "'\-'" -for standard output, -but not on platforms that open standard output in text mode.) -The output file may be a source file because -all files are loaded before the output file is written. -Be careful not to overwrite precious files. -.TP -.B \-p -load files but do not generate any output file. -Used mainly for syntax checking and for testing precompiled chunks: -corrupted files will probably generate errors when loaded. -Lua always performs a thorough integrity test on precompiled chunks. -Bytecode that passes this test is completely safe, -in the sense that it will not break the interpreter. -However, -there is no guarantee that such code does anything sensible. -(None can be given, because the halting problem is unsolvable.) -If no files are given, then -.B luac -loads -.B luac.out -and tests its contents. -No messages are displayed if the file passes the integrity test. -.TP -.B \-s -strip debug information before writing the output file. -This saves some space in very large chunks, -but if errors occur when running a stripped chunk, -then the error messages may not contain the full information they usually do. -For instance, -line numbers and names of local variables are lost. -.TP -.B \-v -show version information. -.SH FILES -.TP 15 -.B luac.out -default output file -.SH "SEE ALSO" -.BR lua (1) -.br -http://www.lua.org/ -.SH DIAGNOSTICS -Error messages should be self explanatory. -.SH AUTHORS -L. H. de Figueiredo, -R. Ierusalimschy and -W. Celes -.\" EOF diff --git a/doc/luac.html b/doc/luac.html deleted file mode 100644 index 179ffe8..0000000 --- a/doc/luac.html +++ /dev/null @@ -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> diff --git a/doc/readme.html b/doc/readme.html deleted file mode 100644 index 3ed6a81..0000000 --- a/doc/readme.html +++ /dev/null @@ -1,40 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Lua documentation</TITLE> -<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css"> -</HEAD> - -<BODY> - -<HR> -<H1> -<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> -Documentation -</H1> - -This is the documentation included in the source distribution of Lua 5.1.5. - -<UL> -<LI><A HREF="contents.html">Reference manual</A> -<LI><A HREF="lua.html">lua man page</A> -<LI><A HREF="luac.html">luac man page</A> -<LI><A HREF="../README">lua/README</A> -<LI><A HREF="../etc/README">lua/etc/README</A> -<LI><A HREF="../test/README">lua/test/README</A> -</UL> - -Lua's -<A HREF="http://www.lua.org/">official web site</A> -contains updated documentation, -especially the -<A HREF="http://www.lua.org/manual/5.1/">reference manual</A>. -<P> - -<HR> -<SMALL> -Last update: -Fri Feb 3 09:44:42 BRST 2012 -</SMALL> - -</BODY> -</HTML> diff --git a/etc/Makefile b/etc/Makefile deleted file mode 100644 index 6d00008..0000000 --- a/etc/Makefile +++ /dev/null @@ -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 diff --git a/etc/README b/etc/README deleted file mode 100644 index 5149fc9..0000000 --- a/etc/README +++ /dev/null @@ -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. - diff --git a/etc/all.c b/etc/all.c deleted file mode 100644 index dab68fa..0000000 --- a/etc/all.c +++ /dev/null @@ -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" diff --git a/etc/lua.hpp b/etc/lua.hpp deleted file mode 100644 index ec417f5..0000000 --- a/etc/lua.hpp +++ /dev/null @@ -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" -} diff --git a/etc/lua.ico b/etc/lua.ico deleted file mode 100644 index ccbabc4..0000000 --- a/etc/lua.ico +++ /dev/null Binary files differdiff --git a/etc/lua.pc b/etc/lua.pc deleted file mode 100644 index 07e2852..0000000 --- a/etc/lua.pc +++ /dev/null @@ -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) diff --git a/etc/luavs.bat b/etc/luavs.bat deleted file mode 100644 index 08c2bed..0000000 --- a/etc/luavs.bat +++ /dev/null @@ -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 .. diff --git a/etc/min.c b/etc/min.c deleted file mode 100644 index 6a85a4d..0000000 --- a/etc/min.c +++ /dev/null @@ -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; -} diff --git a/etc/noparser.c b/etc/noparser.c deleted file mode 100644 index 13ba546..0000000 --- a/etc/noparser.c +++ /dev/null @@ -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 diff --git a/etc/strict.lua b/etc/strict.lua deleted file mode 100644 index 604619d..0000000 --- a/etc/strict.lua +++ /dev/null @@ -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 - diff --git a/test/README b/test/README deleted file mode 100644 index 0c7f38b..0000000 --- a/test/README +++ /dev/null @@ -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 - diff --git a/test/bisect.lua b/test/bisect.lua deleted file mode 100644 index f91e69b..0000000 --- a/test/bisect.lua +++ /dev/null @@ -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) diff --git a/test/cf.lua b/test/cf.lua deleted file mode 100644 index 8cda54b..0000000 --- a/test/cf.lua +++ /dev/null @@ -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 diff --git a/test/echo.lua b/test/echo.lua deleted file mode 100644 index 4313439..0000000 --- a/test/echo.lua +++ /dev/null @@ -1,5 +0,0 @@ --- echo command line arguments - -for i=0,table.getn(arg) do - print(i,arg[i]) -end diff --git a/test/env.lua b/test/env.lua deleted file mode 100644 index 9e62a57..0000000 --- a/test/env.lua +++ /dev/null @@ -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) diff --git a/test/factorial.lua b/test/factorial.lua deleted file mode 100644 index 7c4cf0f..0000000 --- a/test/factorial.lua +++ /dev/null @@ -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 diff --git a/test/fib.lua b/test/fib.lua deleted file mode 100644 index 97a921b..0000000 --- a/test/fib.lua +++ /dev/null @@ -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) diff --git a/test/fibfor.lua b/test/fibfor.lua deleted file mode 100644 index 8bbba39..0000000 --- a/test/fibfor.lua +++ /dev/null @@ -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 diff --git a/test/globals.lua b/test/globals.lua deleted file mode 100644 index d4c20e1..0000000 --- a/test/globals.lua +++ /dev/null @@ -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 diff --git a/test/hello.lua b/test/hello.lua deleted file mode 100644 index 0925498..0000000 --- a/test/hello.lua +++ /dev/null @@ -1,3 +0,0 @@ --- the first program in every language - -io.write("Hello world, from ",_VERSION,"!\n") diff --git a/test/life.lua b/test/life.lua deleted file mode 100644 index 911d9fe..0000000 --- a/test/life.lua +++ /dev/null @@ -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) diff --git a/test/luac.lua b/test/luac.lua deleted file mode 100644 index 96a0a97..0000000 --- a/test/luac.lua +++ /dev/null @@ -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()) diff --git a/test/printf.lua b/test/printf.lua deleted file mode 100644 index 58c63ff..0000000 --- a/test/printf.lua +++ /dev/null @@ -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()) diff --git a/test/readonly.lua b/test/readonly.lua deleted file mode 100644 index 85c0b4e..0000000 --- a/test/readonly.lua +++ /dev/null @@ -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' diff --git a/test/sieve.lua b/test/sieve.lua deleted file mode 100644 index 0871bb2..0000000 --- a/test/sieve.lua +++ /dev/null @@ -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 diff --git a/test/sort.lua b/test/sort.lua deleted file mode 100644 index 0bcb15f..0000000 --- a/test/sort.lua +++ /dev/null @@ -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) diff --git a/test/table.lua b/test/table.lua deleted file mode 100644 index 235089c..0000000 --- a/test/table.lua +++ /dev/null @@ -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") diff --git a/test/trace-calls.lua b/test/trace-calls.lua deleted file mode 100644 index 6d7a7b3..0000000 --- a/test/trace-calls.lua +++ /dev/null @@ -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 diff --git a/test/trace-globals.lua b/test/trace-globals.lua deleted file mode 100644 index 295e670..0000000 --- a/test/trace-globals.lua +++ /dev/null @@ -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) diff --git a/test/xd.lua b/test/xd.lua deleted file mode 100644 index ebc3eff..0000000 --- a/test/xd.lua +++ /dev/null @@ -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 |