diff options
author | Lua Team <team@lua.org> | 2004-12-30 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2004-12-30 12:00:00 +0000 |
commit | e2493a40ee611d5a718fd2a81fe67e24c04c91a0 (patch) | |
tree | 0dca96133b3cd52d262dfa2592ad076fc0ea7852 | |
parent | 226f7859b5392b6680b7e703f9cc7f7f101fd365 (diff) | |
download | lua-github-e2493a40ee611d5a718fd2a81fe67e24c04c91a0.tar.gz |
Lua 5.1-work45.1-work4
-rw-r--r-- | INSTALL | 93 | ||||
-rw-r--r-- | MANIFEST | 218 | ||||
-rw-r--r-- | Makefile | 98 | ||||
-rw-r--r-- | README | 14 | ||||
-rwxr-xr-x | build | 36 | ||||
-rw-r--r-- | config | 136 | ||||
-rw-r--r-- | doc/contents.html | 123 | ||||
-rw-r--r-- | doc/logo.gif | bin | 0 -> 4232 bytes | |||
-rw-r--r-- | doc/lua.1 | 167 | ||||
-rw-r--r-- | doc/lua.html | 175 | ||||
-rw-r--r-- | doc/luac.1 | 136 | ||||
-rw-r--r-- | doc/luac.html | 144 | ||||
-rw-r--r-- | doc/readme.html | 31 | ||||
-rw-r--r-- | etc/Makefile | 44 | ||||
-rw-r--r-- | etc/README | 7 | ||||
-rw-r--r-- | etc/lua.hpp | 1 | ||||
-rw-r--r-- | etc/noparser.c | 17 | ||||
-rw-r--r-- | etc/saconfig.c | 30 | ||||
-rw-r--r-- | include/Makefile | 17 | ||||
-rw-r--r-- | src/Makefile | 208 | ||||
-rw-r--r-- | src/README | 5 | ||||
-rw-r--r-- | src/lapi.c | 8 | ||||
-rw-r--r-- | src/lauxlib.c (renamed from src/lib/lauxlib.c) | 25 | ||||
-rw-r--r-- | src/lauxlib.h (renamed from include/lauxlib.h) | 0 | ||||
-rw-r--r-- | src/lbaselib.c (renamed from src/lib/lbaselib.c) | 20 | ||||
-rw-r--r-- | src/ldblib.c (renamed from src/lib/ldblib.c) | 0 | ||||
-rw-r--r-- | src/ldebug.c | 4 | ||||
-rw-r--r-- | src/lgc.c | 10 | ||||
-rw-r--r-- | src/lib/Makefile | 27 | ||||
-rw-r--r-- | src/lib/README | 8 | ||||
-rw-r--r-- | src/lib/loadlib.c | 429 | ||||
-rw-r--r-- | src/linit.c (renamed from src/lib/linit.c) | 0 | ||||
-rw-r--r-- | src/liolib.c (renamed from src/lib/liolib.c) | 0 | ||||
-rw-r--r-- | src/llimits.h | 4 | ||||
-rw-r--r-- | src/lmathlib.c (renamed from src/lib/lmathlib.c) | 0 | ||||
-rw-r--r-- | src/loadlib.c | 464 | ||||
-rw-r--r-- | src/loslib.c (renamed from src/lib/loslib.c) | 0 | ||||
-rw-r--r-- | src/lparser.c | 37 | ||||
-rw-r--r-- | src/lstate.c | 4 | ||||
-rw-r--r-- | src/lstate.h | 4 | ||||
-rw-r--r-- | src/lstrlib.c (renamed from src/lib/lstrlib.c) | 0 | ||||
-rw-r--r-- | src/ltablib.c (renamed from src/lib/ltablib.c) | 30 | ||||
-rw-r--r-- | src/lua.c (renamed from src/lua/lua.c) | 0 | ||||
-rw-r--r-- | src/lua.h (renamed from include/lua.h) | 6 | ||||
-rw-r--r-- | src/lua/Makefile | 31 | ||||
-rw-r--r-- | src/lua/README | 41 | ||||
-rw-r--r-- | src/luac.c (renamed from src/luac/luac.c) | 0 | ||||
-rw-r--r-- | src/luac/Makefile | 31 | ||||
-rw-r--r-- | src/luac/README | 18 | ||||
-rw-r--r-- | src/luaconf.h (renamed from include/luaconf.h) | 74 | ||||
-rw-r--r-- | src/lualib.h (renamed from include/lualib.h) | 0 | ||||
-rw-r--r-- | src/print.c (renamed from src/luac/print.c) | 0 | ||||
l--------- | test/lua | 1 | ||||
l--------- | test/luac | 1 | ||||
-rw-r--r-- | test/printf.lua | 2 | ||||
-rw-r--r-- | test/xd.lua | 6 |
56 files changed, 1739 insertions, 1246 deletions
@@ -2,82 +2,69 @@ This is Lua 5.1 (work). * Installation ------------ - Building Lua on a Unix system should be very easy: + Building Lua on a Unix system should be very easy: simply doing "make" + should work. This will build Lua in the src directory. - 1. Read "config" and edit it to suit your platform and needs. - We strongly recommend that you enable support for dynamic loading, - if your platform allows it. - 2. Do the same for include/luaconf.h. - 3. Do "make". - 4. If you want to install Lua in an "official" place in your system, - then do "make install". The official place and the way to install - files are defined in "config". You may have to be root to do this. + If you want to install Lua in an official place in your system, then + 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. - See below for instructions for Windows and other systems. - -* What you get - ------------ - If "make" succeeds, you get: - * an interpreter in ./bin/lua and a compiler in ./bin/luac; - * libraries in ./lib; - * include files in ./include. - These are the only directories you need for development. + 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: - There are man pages for lua and luac, in both nroff and html; 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. + bin: lua luac + include: lua.h luaconf.h lualib.h lauxlib.h + lib: liblua.a liblualib.a + man/man1: lua.1 luac.1 - See also the README files in the various subdirectories. - A convenient starting point is ./doc/readme.html. - -* If you have problems (and solutions!) - ------------------------------------- - If "make" fails, please let us know. - If you make changes to "config" or to the Makefiles, please send them to us. + These are the only directories you need for development. -* Shared libraries - ---------------- - If you are running Linux, do "make so" after "make" succeeds. - This will create shared libraries in ./lib. - To install those shared libraries in an official place, do "make soinstall". + 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 the interpreter and the compiler to use shared libraries, - then do "make sobin" too. You may want to do this before "make install". + See below for instructions for Windows and other systems. - If you only want the shared libraries, you may want to add -fPIC to MYCFLAGS - in "config". Also, you may need to run "ldconfig" as root. +* 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 may need to include ./lib in the LD_LIBRARY_PATH environment variable - to link programs that use the shared libraries if you don't put them in the - official places with "make install". (You may need to use the full path.) - Note also that by default these official places live under /usr/local but - /usr/local/lib may not be a place that is checked for shared libraries. - In Linux, the places checked are in /etc/ld.so.conf. Try also "man ld.so". + You don't actually need to edit the Makefiles because you may set the + relevant variables when invoking make. - Building shared libraries on other systems is similar but details differ; - you may need to fix a few details in the top-level Makefile. + 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 + will be used by any Lua clients that you build, to ensure consistency. * Installation on Windows and other systems ----------------------------------------- - The instructions for building Lua on other systems depend on the particular - compiler you are using. The simplest way is to create a folder with all .c - and .h files, and then create projects for the core library, the standard - library, the interpreter, and the compiler, as follows: + The instructions for building Lua on other systems depend on the compiler + you use. You'll need to create projects (or whatever your compiler uses) + for building the core library, the standard library, the interpreter, and + the compiler, as follows: core lib: 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 standard lib: lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c - ltablib.c lstrlib.c loadlib.c + ltablib.c lstrlib.c loadlib.c linit.c interpreter: core lib, standard lib, lua.c compiler: core lib, lauxlib.c luac.c print.c - Of course, to use Lua as a library, you'll have to know how to create - and use libraries with your compiler. + 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. + + To use Lua as a library in your own programs, you'll need to know how to + create and use libraries with your compiler. - Also, read "config" to see what can be customized at compilation time. + As mentioned above, you may edit luaconf.h to select some features before + building Lua. (end of INSTALL) @@ -1,115 +1,105 @@ -MANIFEST contents of Lua 5.1 (work3) distribution on Mon Dec 6 23:00:22 BRST 2004 -lua-5.1-work3 -lua-5.1-work3/COPYRIGHT -lua-5.1-work3/HISTORY -lua-5.1-work3/INSTALL -lua-5.1-work3/MANIFEST -lua-5.1-work3/Makefile -lua-5.1-work3/README -lua-5.1-work3/bin -lua-5.1-work3/build -lua-5.1-work3/config -lua-5.1-work3/etc -lua-5.1-work3/etc/Makefile -lua-5.1-work3/etc/README -lua-5.1-work3/etc/all.c -lua-5.1-work3/etc/lua.hpp -lua-5.1-work3/etc/lua.ico -lua-5.1-work3/etc/min.c -lua-5.1-work3/etc/noparser.c -lua-5.1-work3/etc/saconfig.c -lua-5.1-work3/include -lua-5.1-work3/include/Makefile -lua-5.1-work3/include/lauxlib.h -lua-5.1-work3/include/lua.h -lua-5.1-work3/include/luaconf.h -lua-5.1-work3/include/lualib.h -lua-5.1-work3/lib -lua-5.1-work3/src -lua-5.1-work3/src/Makefile -lua-5.1-work3/src/README -lua-5.1-work3/src/lapi.c -lua-5.1-work3/src/lapi.h -lua-5.1-work3/src/lcode.c -lua-5.1-work3/src/lcode.h -lua-5.1-work3/src/ldebug.c -lua-5.1-work3/src/ldebug.h -lua-5.1-work3/src/ldo.c -lua-5.1-work3/src/ldo.h -lua-5.1-work3/src/ldump.c -lua-5.1-work3/src/lfunc.c -lua-5.1-work3/src/lfunc.h -lua-5.1-work3/src/lgc.c -lua-5.1-work3/src/lgc.h -lua-5.1-work3/src/lib -lua-5.1-work3/src/lib/Makefile -lua-5.1-work3/src/lib/README -lua-5.1-work3/src/lib/lauxlib.c -lua-5.1-work3/src/lib/lbaselib.c -lua-5.1-work3/src/lib/ldblib.c -lua-5.1-work3/src/lib/linit.c -lua-5.1-work3/src/lib/liolib.c -lua-5.1-work3/src/lib/lmathlib.c -lua-5.1-work3/src/lib/loadlib.c -lua-5.1-work3/src/lib/loslib.c -lua-5.1-work3/src/lib/lstrlib.c -lua-5.1-work3/src/lib/ltablib.c -lua-5.1-work3/src/llex.c -lua-5.1-work3/src/llex.h -lua-5.1-work3/src/llimits.h -lua-5.1-work3/src/lmem.c -lua-5.1-work3/src/lmem.h -lua-5.1-work3/src/lobject.c -lua-5.1-work3/src/lobject.h -lua-5.1-work3/src/lopcodes.c -lua-5.1-work3/src/lopcodes.h -lua-5.1-work3/src/lparser.c -lua-5.1-work3/src/lparser.h -lua-5.1-work3/src/lstate.c -lua-5.1-work3/src/lstate.h -lua-5.1-work3/src/lstring.c -lua-5.1-work3/src/lstring.h -lua-5.1-work3/src/ltable.c -lua-5.1-work3/src/ltable.h -lua-5.1-work3/src/ltm.c -lua-5.1-work3/src/ltm.h -lua-5.1-work3/src/lua -lua-5.1-work3/src/lua/Makefile -lua-5.1-work3/src/lua/README -lua-5.1-work3/src/lua/lua.c -lua-5.1-work3/src/luac -lua-5.1-work3/src/luac/Makefile -lua-5.1-work3/src/luac/README -lua-5.1-work3/src/luac/luac.c -lua-5.1-work3/src/luac/print.c -lua-5.1-work3/src/lundump.c -lua-5.1-work3/src/lundump.h -lua-5.1-work3/src/lvm.c -lua-5.1-work3/src/lvm.h -lua-5.1-work3/src/lzio.c -lua-5.1-work3/src/lzio.h -lua-5.1-work3/test -lua-5.1-work3/test/README -lua-5.1-work3/test/bisect.lua -lua-5.1-work3/test/cf.lua -lua-5.1-work3/test/echo.lua -lua-5.1-work3/test/env.lua -lua-5.1-work3/test/factorial.lua -lua-5.1-work3/test/fib.lua -lua-5.1-work3/test/fibfor.lua -lua-5.1-work3/test/globals.lua -lua-5.1-work3/test/hello.lua -lua-5.1-work3/test/life.lua -lua-5.1-work3/test/lua -lua-5.1-work3/test/luac -lua-5.1-work3/test/luac.lua -lua-5.1-work3/test/printf.lua -lua-5.1-work3/test/readonly.lua -lua-5.1-work3/test/sieve.lua -lua-5.1-work3/test/sort.lua -lua-5.1-work3/test/table.lua -lua-5.1-work3/test/trace-calls.lua -lua-5.1-work3/test/trace-globals.lua -lua-5.1-work3/test/undefined.lua -lua-5.1-work3/test/xd.lua +MANIFEST contents of Lua 5.1 (work4) distribution on Thu Dec 30 12:00:49 BRST 2004 +lua-5.1-work4 +lua-5.1-work4/COPYRIGHT +lua-5.1-work4/HISTORY +lua-5.1-work4/INSTALL +lua-5.1-work4/MANIFEST +lua-5.1-work4/Makefile +lua-5.1-work4/README +lua-5.1-work4/doc +lua-5.1-work4/doc/contents.html +lua-5.1-work4/doc/logo.gif +lua-5.1-work4/doc/lua.1 +lua-5.1-work4/doc/lua.html +lua-5.1-work4/doc/luac.1 +lua-5.1-work4/doc/luac.html +lua-5.1-work4/doc/readme.html +lua-5.1-work4/etc +lua-5.1-work4/etc/Makefile +lua-5.1-work4/etc/README +lua-5.1-work4/etc/all.c +lua-5.1-work4/etc/lua.hpp +lua-5.1-work4/etc/lua.ico +lua-5.1-work4/etc/min.c +lua-5.1-work4/etc/noparser.c +lua-5.1-work4/etc/saconfig.c +lua-5.1-work4/src +lua-5.1-work4/src/Makefile +lua-5.1-work4/src/lapi.c +lua-5.1-work4/src/lapi.h +lua-5.1-work4/src/lauxlib.c +lua-5.1-work4/src/lauxlib.h +lua-5.1-work4/src/lbaselib.c +lua-5.1-work4/src/lcode.c +lua-5.1-work4/src/lcode.h +lua-5.1-work4/src/ldblib.c +lua-5.1-work4/src/ldebug.c +lua-5.1-work4/src/ldebug.h +lua-5.1-work4/src/ldo.c +lua-5.1-work4/src/ldo.h +lua-5.1-work4/src/ldump.c +lua-5.1-work4/src/lfunc.c +lua-5.1-work4/src/lfunc.h +lua-5.1-work4/src/lgc.c +lua-5.1-work4/src/lgc.h +lua-5.1-work4/src/linit.c +lua-5.1-work4/src/liolib.c +lua-5.1-work4/src/llex.c +lua-5.1-work4/src/llex.h +lua-5.1-work4/src/llimits.h +lua-5.1-work4/src/lmathlib.c +lua-5.1-work4/src/lmem.c +lua-5.1-work4/src/lmem.h +lua-5.1-work4/src/loadlib.c +lua-5.1-work4/src/lobject.c +lua-5.1-work4/src/lobject.h +lua-5.1-work4/src/lopcodes.c +lua-5.1-work4/src/lopcodes.h +lua-5.1-work4/src/loslib.c +lua-5.1-work4/src/lparser.c +lua-5.1-work4/src/lparser.h +lua-5.1-work4/src/lstate.c +lua-5.1-work4/src/lstate.h +lua-5.1-work4/src/lstring.c +lua-5.1-work4/src/lstring.h +lua-5.1-work4/src/lstrlib.c +lua-5.1-work4/src/ltable.c +lua-5.1-work4/src/ltable.h +lua-5.1-work4/src/ltablib.c +lua-5.1-work4/src/ltm.c +lua-5.1-work4/src/ltm.h +lua-5.1-work4/src/lua.c +lua-5.1-work4/src/lua.h +lua-5.1-work4/src/luac.c +lua-5.1-work4/src/luaconf.h +lua-5.1-work4/src/lualib.h +lua-5.1-work4/src/lundump.c +lua-5.1-work4/src/lundump.h +lua-5.1-work4/src/lvm.c +lua-5.1-work4/src/lvm.h +lua-5.1-work4/src/lzio.c +lua-5.1-work4/src/lzio.h +lua-5.1-work4/src/print.c +lua-5.1-work4/test +lua-5.1-work4/test/README +lua-5.1-work4/test/bisect.lua +lua-5.1-work4/test/cf.lua +lua-5.1-work4/test/echo.lua +lua-5.1-work4/test/env.lua +lua-5.1-work4/test/factorial.lua +lua-5.1-work4/test/fib.lua +lua-5.1-work4/test/fibfor.lua +lua-5.1-work4/test/globals.lua +lua-5.1-work4/test/hello.lua +lua-5.1-work4/test/life.lua +lua-5.1-work4/test/luac.lua +lua-5.1-work4/test/printf.lua +lua-5.1-work4/test/readonly.lua +lua-5.1-work4/test/sieve.lua +lua-5.1-work4/test/sort.lua +lua-5.1-work4/test/table.lua +lua-5.1-work4/test/trace-calls.lua +lua-5.1-work4/test/trace-globals.lua +lua-5.1-work4/test/undefined.lua +lua-5.1-work4/test/xd.lua END OF MANIFEST @@ -1,62 +1,61 @@ -# makefile for Lua hierarchy +# makefile for installing Lua # see INSTALL for installation instructions -# see config for customization instructions +# see src/Makefile and src/luaconf.h for further customization -LUA= . +# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= -include $(LUA)/config +# Where to install. The installation starts in the src directory, so take +# care if INSTALL_TOP is not an absolute path. +# +INSTALL_TOP= /usr/local +INSTALL_BIN= $(INSTALL_TOP)/bin +INSTALL_INC= $(INSTALL_TOP)/include +INSTALL_LIB= $(INSTALL_TOP)/lib +INSTALL_MAN= $(INSTALL_TOP)/man/man1 -# primary targets ("co" and "klean" are used for making the distribution) -all clean co klean: - cd include; $(MAKE) $@ - cd src; $(MAKE) $@ - cd src/lib; $(MAKE) $@ - cd src/luac; $(MAKE) $@ - cd src/lua; $(MAKE) $@ +# How to install. You may prefer "install" instead of "cp" if you have it. +# To remove debug information from binaries, use "install -s" in INSTALL_EXEC. +# +INSTALL_EXEC= cp +INSTALL_DATA= cp +#INSTALL_EXEC= install -m 0755 +#INSTALL_DATA= install -m 0644 + +# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= + +V= 5.1 -# in case they were not created during unpacking -all: bin lib +TO_BIN= lua luac +TO_INC= lua.h luaconf.h lualib.h lauxlib.h +TO_LIB= liblua.a liblualib.a +TO_MAN= lua.1 luac.1 -bin lib: - mkdir -p $@ +all clean: + cd src; $(MAKE) $@ -# simple test to see Lua working test: all - bin/lua test/hello.lua + src/lua test/hello.lua -# remove debug information from binaries -strip: - $(STRIP) bin/* +install: all + cd src; mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) + cd src; $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) + cd src; $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) + cd src; $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) + cd doc; $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) -# official installation -install: all strip - mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) - $(INSTALL_EXEC) bin/* $(INSTALL_BIN) - $(INSTALL_DATA) include/*.h $(INSTALL_INC) - $(INSTALL_DATA) lib/*.a $(INSTALL_LIB) - $(INSTALL_DATA) doc/*.1 $(INSTALL_MAN) +local: + $(MAKE) install INSTALL_TOP=.. INSTALL_EXEC="cp -up" INSTALL_DATA="cp -up" # echo config parameters echo: @echo "" - @echo "These are the parameters currently set in $(LUA)/config to build Lua $V:" + @echo "These are the parameters currently set in src/Makefile to build Lua $V:" + @echo "" + @cd src; $(MAKE) -s echo + @echo "" + @echo "These are the parameters currently set in Makefile to install Lua $V:" @echo "" - @echo "LOADLIB = $(LOADLIB)" - @echo "DLLIB = $(DLLIB)" - @echo "NUMBER = $(NUMBER)" - @echo "POPEN = $(POPEN)" - @echo "TMPNAM = $(TMPNAM)" - @echo "DEGREES = $(DEGREES)" - @echo "USERCONF = $(USERCONF)" - @echo "CC = $(CC)" - @echo "WARN = $(WARN)" - @echo "MYCFLAGS = $(MYCFLAGS)" - @echo "MYLDFLAGS = $(MYLDFLAGS)" - @echo "EXTRA_LIBS = $(EXTRA_LIBS)" - @echo "AR = $(AR)" - @echo "RANLIB = $(RANLIB)" - @echo "STRIP = $(STRIP)" - @echo "INSTALL_ROOT = $(INSTALL_ROOT)" + @echo "INSTALL_TOP = $(INSTALL_TOP)" @echo "INSTALL_BIN = $(INSTALL_BIN)" @echo "INSTALL_INC = $(INSTALL_INC)" @echo "INSTALL_LIB = $(INSTALL_LIB)" @@ -64,17 +63,18 @@ echo: @echo "INSTALL_EXEC = $(INSTALL_EXEC)" @echo "INSTALL_DATA = $(INSTALL_DATA)" @echo "" - @echo "Edit $(LUA)/config if needed to suit your platform and then run make." + @echo "See also src/luaconf.h ." @echo "" -# turn config into Lua code +# echo config parameters as Lua code # uncomment the last sed expression if you want nil instead of empty strings lecho: - @echo "-- $(LUA)/config for Lua $V" - @echo "VERSION = '$(V)'" - @make echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' + @echo "-- installation parameters for Lua $V" + @echo "VERSION = '$V'" + @$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' @echo "-- EOF" +# show what has changed since we unpacked newer: @find . -newer MANIFEST -type f @@ -17,9 +17,7 @@ See HISTORY for a summary of changes since the last released version. ------------ Lua is freely available for both academic and commercial purposes. See COPYRIGHT and http://www.lua.org/license.html for details. - Lua can be downloaded from its official site http://www.lua.org/ and - several other sites aroung the world. For a complete list of mirror sites, - see http://www.lua.org/mirrors.html . + Lua can be downloaded at http://www.lua.org/download.html . * Installation ------------ @@ -27,19 +25,11 @@ See HISTORY for a summary of changes since the last released version. platforms that have an ANSI C compiler. Under Unix, simply typing "make" should work. See INSTALL for detailed instructions. -* Contacting the authors - ---------------------- - Send your comments, questions, and bug reports to - lua-team AT tecgraf.puc-rio.br. - For more information about the authors, see http://www.lua.org/authors.html . - For reporting bugs, try also the mailing list: lua@bazar2.conectiva.com.br . - For more information about this list, including instructions on how to - subscribe and access the archives, see http://www.lua.org/lua-l.html . - * Origin ------ Lua is developed at Tecgraf, the Computer Graphics Technology Group of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro in Brazil). Tecgraf is a laboratory of the Department of Computer Science. + For more information about the authors, see http://www.lua.org/authors.html . (end of README) @@ -1,36 +0,0 @@ -#!/bin/sh -# -# If you don't want to use make, run this script to build Lua. -# Read config and include/luaconf.h to see what can be customized. - - -# Easiest way to build bin/lua: -# cc -O2 -o bin/lua -Iinclude -Isrc src/*.c src/lib/*.c src/lua/*.c -lm -ldl -# bin/lua test/hello.lua - - -# Easiest way to build Lua libraries and executables: -echo -n 'building core library... ' -cd src -cc -O2 -c -I../include *.c -ar rc ../lib/liblua.a *.o -rm -f *.o - -echo -n 'standard library... ' -cd lib -cc -O2 -c -I../../include *.c -ar rc ../../lib/liblualib.a *.o -rm -f *.o - -echo -n 'lua... ' -cd ../lua -cc -O2 -o ../../bin/lua -I../../include *.c ../../lib/*.a -lm -ldl - -echo -n 'luac... ' -cd ../luac -cc -O2 -o ../../bin/luac -I../../include -I.. *.c ../../lib/*.a - -echo 'done' - -cd ../.. -bin/lua test/hello.lua diff --git a/config b/config deleted file mode 100644 index 75ae76f1..00000000 --- a/config +++ /dev/null @@ -1,136 +0,0 @@ -# configuration file for making Lua 5.1 (work) -# see INSTALL for installation instructions - -# These are default values. Skip this section and see the explanations below. - -LOADLIB= -DLLIB= -USERCONF= - -# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= - -# ------------------------------------------------------------- dynamic loading - -# Support for dynamically loading C libraries for Lua is a very important -# feature, which we strongly recommend be enabled. By default, this support is -# enabled on Windows systems (see below) but disabled on other systems because -# it relies on system-dependent code that is not part of ANSI C. For more -# information on dynamic loading, read the comments in src/lib/loadlib.c . -# -# To enable support for dynamic loading on Unix systems that support the dlfcn -# interface (e.g., Linux, Solaris, IRIX, BSD, AIX, HPUX, and probably others), -# uncomment the next two lines. Also read the next paragraph. -# -LOADLIB= -DUSE_DLOPEN=1 -DLLIB= -ldl -# -# In Linux with gcc, you should also uncomment the next definition for -# MYLDFLAGS, which passes -E (= -export-dynamic) to the linker. This option -# allows dynamic libraries to link back to the `lua' program, so that they do -# not need the Lua libraries. (Other systems may have an equivalent facility.) -# -MYLDFLAGS= -Wl,-E -# -# On Windows systems. support for dynamic loading is enabled by default. -# To disable this support, uncomment the next line. -# -#LOADLIB= -DUSE_DLL=0 - -# --------------------------------------------------------------- Lua libraries - -# See include/luaconf.h. - -# ------------------------------------------------------------------ Lua core - -# See include/luaconf.h. - -# ------------------------------------------------------------- Lua interpreter - -# The stand-alone Lua interpreter needs the math functions, which are usually -# in libm.a (-lm). If your C library already includes the math functions, -# or if you are using a modified interpreter that does not need them, -# then comment the following line or add the appropriates libraries. -# -EXTRA_LIBS= -lm - -# If you want to customize the stand-alone Lua interpreter, uncomment and -# edit the following two lines; also edit etc/saconfig.c to suit your needs. -# -DUSE_READLINE adds line editing and history to the interpreter. You need -# to add -lreadline (and perhaps also -lhistory and -ltermcap) to EXTRA_LIBS. -# -#USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE -#EXTRA_LIBS= -lm $(DLLIB) -lreadline # -lhistory -ltermcap -lcurses -lncurses - -# ------------------------------------------------------------------ C compiler - -# You need an ANSI C compiler. gcc is a popular one. We do not use -ansi in -# WARN because it disables POSIX features used in the libraries. -# -CC= gcc -WARN= -Wall - -# ------------------------------------------------------------------ C options - -# Write here any options you may need for your C compiler. -# If you are using gcc, -O3 will get you a faster but larger code. You can -# also add -fomit-frame-pointer to get even faster code at the cost of losing -# debug information. If you only want the shared libraries, you may want to -# add -fPIC to MYCFLAGS. -# -MYCFLAGS= -O2 -#MYCFLAGS= -O3 -fomit-frame-pointer # -fPIC - -# Write here any options you may need for your C linker. -#MYLDFLAGS= - -# ------------------------------------------------------------------ librarian - -# This should work on all Unix systems. -# -AR= ar rcu - -# If your system doesn't have (or need) ranlib, use RANLIB=true. -# On some systems, "ar s" does what ranlib would do. -# -RANLIB= ranlib -#RANLIB= ar s -#RANLIB= true - -# ------------------------------------------------------------------ stripper - -# This should work on all Unix systems, but you may want to add options. -# -STRIP= strip - -# ------------------------------------------------------------------ install - -# Locations for "make install". You may need to be root do "make install". -# -INSTALL_ROOT= /usr/local -INSTALL_BIN= $(INSTALL_ROOT)/bin -INSTALL_INC= $(INSTALL_ROOT)/include -INSTALL_LIB= $(INSTALL_ROOT)/lib -INSTALL_MAN= $(INSTALL_ROOT)/man/man1 - -# You may prefer to use "install" instead of "cp" if you have it. -# If you use "install", you may also want to change the permissions after -m. -# -INSTALL_EXEC= cp -INSTALL_DATA= cp -#INSTALL_EXEC= install -m 0755 -#INSTALL_DATA= install -m 0644 - -# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= - -V= 5.1 - -BIN= $(LUA)/bin -INC= $(LUA)/include -LIB= $(LUA)/lib - -INCS= -I$(INC) $(EXTRA_INCS) -DEFS= $(EXTRA_DEFS) - -CFLAGS= $(MYCFLAGS) $(WARN) $(INCS) $(DEFS) - -# (end of config) diff --git a/doc/contents.html b/doc/contents.html new file mode 100644 index 00000000..06bd6fb4 --- /dev/null +++ b/doc/contents.html @@ -0,0 +1,123 @@ +<HTML> +<HEAD> +<TITLE>Lua: 5.0 reference manual - contents</TITLE> +</HEAD> + +<BODY BGCOLOR="#FFFFFF"> + +<HR> +<H1> +<A HREF="http://www.lua.org/home.html"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> +Reference manual for Lua 5.0 +</H1> + +<A HREF="manual.html">Lua 5.0 Reference Manual</A> +[ +<A HREF="manual.html">top</A> +| +<A HREF="http://www.lua.org/ftp/refman-5.0.ps.gz">ps</A> +| +<A HREF="http://www.lua.org/ftp/refman-5.0.pdf">pdf</A> +] +<P> + +<SMALL> +<A HREF="http://www.lua.org/copyright.html">Copyright</A> +© 2003 Tecgraf, PUC-Rio. All rights reserved.</SMALL> +<HR> + +<UL> +<LI><A HREF="manual.html#1">1 - Introduction</A> +<LI><A HREF="manual.html#2">2 - The Language</A> +<UL> +<LI><A HREF="manual.html#2.1">2.1 - Lexical Conventions</A> +<LI><A HREF="manual.html#2.2">2.2 - Values and Types</A> +<UL> +<LI><A HREF="manual.html#2.2.1">2.2.1 - Coercion</A> +</UL> +<LI><A HREF="manual.html#2.3">2.3 - Variables</A> +<LI><A HREF="manual.html#2.4">2.4 - Statements</A> +<UL> +<LI><A HREF="manual.html#2.4.1">2.4.1 - Chunks</A> +<LI><A HREF="manual.html#2.4.2">2.4.2 - Blocks</A> +<LI><A HREF="manual.html#2.4.3">2.4.3 - Assignment</A> +<LI><A HREF="manual.html#2.4.4">2.4.4 - Control Structures</A> +<LI><A HREF="manual.html#2.4.5">2.4.5 - For Statement</A> +<LI><A HREF="manual.html#2.4.6">2.4.6 - Function Calls as Statements</A> +<LI><A HREF="manual.html#2.4.7">2.4.7 - Local Declarations</A> +</UL> +<LI><A HREF="manual.html#2.5">2.5 - Expressions</A> +<UL> +<LI><A HREF="manual.html#2.5.1">2.5.1 - Arithmetic Operators</A> +<LI><A HREF="manual.html#2.5.2">2.5.2 - Relational Operators</A> +<LI><A HREF="manual.html#2.5.3">2.5.3 - Logical Operators</A> +<LI><A HREF="manual.html#2.5.4">2.5.4 - Concatenation</A> +<LI><A HREF="manual.html#2.5.5">2.5.5 - Precedence</A> +<LI><A HREF="manual.html#2.5.6">2.5.6 - Table Constructors</A> +<LI><A HREF="manual.html#2.5.7">2.5.7 - Function Calls</A> +<LI><A HREF="manual.html#2.5.8">2.5.8 - Function Definitions</A> +</UL> +</UL> +<UL> +<LI><A HREF="manual.html#2.6">2.6 - Visibility Rules</A> +<LI><A HREF="manual.html#2.7">2.7 - Error Handling</A> +<LI><A HREF="manual.html#2.8">2.8 - Metatables</A> +<LI><A HREF="manual.html#2.9">2.9 - Garbage Collection</A> +<UL> +<LI><A HREF="manual.html#2.9.1">2.9.1 - Garbage-Collection Metamethods</A> +<LI><A HREF="manual.html#2.9.2">2.9.2 - Weak Tables</A> +</UL> +<LI><A HREF="manual.html#2.10">2.10 - Coroutines</A> +</UL> +<LI><A HREF="manual.html#3">3 - The Application Program Interface</A> +<UL> +<LI><A HREF="manual.html#3.1">3.1 - States</A> +<LI><A HREF="manual.html#3.2">3.2 - The Stack and Indices</A> +<LI><A HREF="manual.html#3.3">3.3 - Stack Manipulation</A> +<LI><A HREF="manual.html#3.4">3.4 - Querying the Stack</A> +<LI><A HREF="manual.html#3.5">3.5 - Getting Values from the Stack</A> +<LI><A HREF="manual.html#3.6">3.6 - Pushing Values onto the Stack</A> +<LI><A HREF="manual.html#3.7">3.7 - Controlling Garbage Collection</A> +<LI><A HREF="manual.html#3.8">3.8 - Userdata</A> +<LI><A HREF="manual.html#3.9">3.9 - Metatables</A> +<LI><A HREF="manual.html#3.10">3.10 - Loading Lua Chunks</A> +<LI><A HREF="manual.html#3.11">3.11 - Manipulating Tables</A> +<LI><A HREF="manual.html#3.12">3.12 - Manipulating Environments</A> +<LI><A HREF="manual.html#3.13">3.13 - Using Tables as Arrays</A> +<LI><A HREF="manual.html#3.14">3.14 - Calling Functions</A> +<LI><A HREF="manual.html#3.15">3.15 - Protected Calls</A> +<LI><A HREF="manual.html#3.16">3.16 - Defining C Functions</A> +<LI><A HREF="manual.html#3.17">3.17 - Defining C Closures</A> +<LI><A HREF="manual.html#3.18">3.18 - Registry</A> +<LI><A HREF="manual.html#3.19">3.19 - Error Handling in C</A> +<LI><A HREF="manual.html#3.20">3.20 - Threads</A> +</UL> +<LI><A HREF="manual.html#4">4 - The Debug Interface</A> +<UL> +<LI><A HREF="manual.html#4.1">4.1 - Stack and Function Information</A> +<LI><A HREF="manual.html#4.2">4.2 - Manipulating Local Variables and Upvalues</A> +<LI><A HREF="manual.html#4.3">4.3 - Hooks</A> +</UL> +<LI><A HREF="manual.html#5">5 - Standard Libraries</A> +<UL> +<LI><A HREF="manual.html#5.1">5.1 - Basic Functions</A> +<LI><A HREF="manual.html#5.2">5.2 - Coroutine Manipulation</A> +<LI><A HREF="manual.html#5.3">5.3 - String Manipulation</A> +<LI><A HREF="manual.html#5.4">5.4 - Table Manipulation</A> +<LI><A HREF="manual.html#5.5">5.5 - Mathematical Functions</A> +<LI><A HREF="manual.html#5.6">5.6 - Input and Output Facilities</A> +<LI><A HREF="manual.html#5.7">5.7 - Operating System Facilities</A> +<LI><A HREF="manual.html#5.8">5.8 - The Reflexive Debug Interface</A> +</UL> +<LI><A HREF="manual.html#6">6 - Lua Stand-alone</A> +<LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A> +</UL> + +<HR> +<SMALL> +Last update: +Wed May 7 18:34:34 EST 2003 +</SMALL> + +</BODY> +</HTML> diff --git a/doc/logo.gif b/doc/logo.gif Binary files differnew file mode 100644 index 00000000..2f5e4ac2 --- /dev/null +++ b/doc/logo.gif diff --git a/doc/lua.1 b/doc/lua.1 new file mode 100644 index 00000000..c9bba7d7 --- /dev/null +++ b/doc/lua.1 @@ -0,0 +1,167 @@ +.\" lua.man,v 1.8 2003/04/02 00:05:20 lhf Exp +.TH LUA 1 "2003/04/02 00:05:20" +.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 with +.BR "_PROMPT" "=\'lua: \'" , +for example. +(Note the need for quotes, because the string contains a space.) +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 " file" +call +.BI require( file ) +before executing +.IR script. +Typically used to load libraries +(hence the letter +.IR l ). +.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 +(lua@tecgraf.puc-rio.br) +.\" EOF diff --git a/doc/lua.html b/doc/lua.html new file mode 100644 index 00000000..073d4b52 --- /dev/null +++ b/doc/lua.html @@ -0,0 +1,175 @@ +<!-- lua.man,v 1.8 2003/04/02 00:05:20 lhf Exp --> +<HTML> +<HEAD> +<TITLE>LUA man page</TITLE> +</HEAD> + +<BODY BGCOLOR="#FFFFFF"> + +<H1>NAME</H1> +lua - Lua interpreter +<H1>SYNOPSIS</H1> +<B>lua</B> +[ +<I>options</I> +] +[ +<I>script</I> +[ +<I>args</I> +] +] +<H1>DESCRIPTION</H1> +<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 with +<B>"_PROMPT" "=\'lua: \'"</B>, +for example. +(Note the need for quotes, because the string contains a space.) +The default prompts are ``> '' and ``>> ''. +<H1>OPTIONS</H1> +<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>file"</I> +call +<B>require( file</B><I>)</I> +before executing +<I></I>script. +Typically used to load libraries +(hence the letter +<I>l</I>). +<P> +<B>-v</B> +show version information. +<H1>SEE ALSO</H1> +<B>luac</B>(1) +<BR> +<A HREF="http://www.lua.org/">http://www.lua.org/</A> +<H1>DIAGNOSTICS</H1> +Error messages should be self explanatory. +<H1>AUTHORS</H1> +R. Ierusalimschy, +L. H. de Figueiredo, +and +W. Celes +(<A HREF="mailto:lua-NO-SPAM-THANKS@tecgraf.puc-rio.br">lua AT tecgraf.puc-rio.br</A>) +<!-- EOF --> +</BODY> +</HTML> diff --git a/doc/luac.1 b/doc/luac.1 new file mode 100644 index 00000000..c6523060 --- /dev/null +++ b/doc/luac.1 @@ -0,0 +1,136 @@ +.\" luac.man,v 1.25 2002/12/13 11:45:12 lhf Exp +.TH LUAC 1 "2002/12/13 11:45:12" +.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 latter loaded and executed. +.LP +The main advantages of precompiling chunks are: +faster loading, +protecting source code from 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 +.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 +The binary files created by +.B luac +are portable to all architectures with the same word size. +This means that +binary files created on a 32-bit platform (such as Intel) +can be read without change in another 32-bit platform (such as Sparc), +even if the byte order (``endianness'') is different. +On the other hand, +binary files created on a 16-bit platform cannot be read in a 32-bit platform, +nor vice-versa. +.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 . +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 these chunks, +then the error messages may not contain the full information they usually do +(line numbers and names of locals 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 +(lua@tecgraf.puc-rio.br) +.\" EOF diff --git a/doc/luac.html b/doc/luac.html new file mode 100644 index 00000000..3a71622e --- /dev/null +++ b/doc/luac.html @@ -0,0 +1,144 @@ +<!-- luac.man,v 1.25 2002/12/13 11:45:12 lhf Exp --> +<HTML> +<HEAD> +<TITLE>LUAC man page</TITLE> +</HEAD> + +<BODY BGCOLOR="#FFFFFF"> + +<H1>NAME</H1> +luac - Lua compiler +<H1>SYNOPSIS</H1> +<B>luac</B> +[ +<I>options</I> +] [ +<I>filenames</I> +] +<H1>DESCRIPTION</H1> +<B>luac</B> +is the Lua compiler. +It translates programs written in the Lua programming language +into binary files that can be latter loaded and executed. +<P> +The main advantages of precompiling chunks are: +faster loading, +protecting source code from user changes, +and +off-line syntax checking. +<P> +Pre-compiling 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> +<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> +The binary files created by +<B>luac</B> +are portable to all architectures with the same word size. +This means that +binary files created on a 32-bit platform (such as Intel) +can be read without change in another 32-bit platform (such as Sparc), +even if the byte order (``endianness'') is different. +On the other hand, +binary files created on a 16-bit platform cannot be read in a 32-bit platform, +nor vice-versa. +<P> +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. +<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> +<H1>OPTIONS</H1> +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>. +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 these chunks, +then the error messages may not contain the full information they usually do +(line numbers and names of locals are lost). +<P> +<B>-v</B> +show version information. +<H1>FILES</H1> +<P> +<B>luac.out</B> +default output file +<H1>SEE ALSO</H1> +<B>lua</B>(1) +<BR> +<A HREF="http://www.lua.org/">http://www.lua.org/</A> +<H1>DIAGNOSTICS</H1> +Error messages should be self explanatory. +<H1>AUTHORS</H1> +L. H. de Figueiredo, +R. Ierusalimschy and +W. Celes +(<A HREF="mailto:lua-NO-SPAM-THANKS@tecgraf.puc-rio.br">lua AT tecgraf.puc-rio.br</A>) +<!-- EOF --> +</BODY> +</HTML> diff --git a/doc/readme.html b/doc/readme.html new file mode 100644 index 00000000..2eab9202 --- /dev/null +++ b/doc/readme.html @@ -0,0 +1,31 @@ +<HTML> +<HEAD> +<TITLE>Lua documentation</TITLE> +</HEAD> + +<BODY BGCOLOR="#FFFFFF"> + +<HR> +<H1> +<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> +Documentation +</H1> + +<UL> +<LI><A HREF="http://www.lua.org/">Official web site</A> +<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> + +<HR> +<SMALL> +Last update: +Wed Dec 22 13:55:42 BRST 2004 +</SMALL> + +</BODY> +</HTML> diff --git a/etc/Makefile b/etc/Makefile index 805df1d2..51bbb407 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -1,32 +1,36 @@ # makefile for Lua etc -LUA= .. - -include $(LUA)/config - -ALL= min noparser luab 1 +TOP= .. +LIB= $(TOP)/src +INC= $(TOP)/src +BIN= $(TOP)/src +SRC= $(TOP)/src +TST= $(TOP)/test + +CC= gcc +CFLAGS= -O2 -Wall $(MYCFLAGS) +MYCFLAGS= -ansi -I$(INC) +MYLDFLAGS= -Wl,-E +MYLIBS= -lm -ldl +RM= rm -f + +ALL= min noparser.o 1 all: @echo 'choose a target:' $(ALL) -min: min.c $(LIBLUA) +min: min.c $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib -noparser: noparser.c - $(CC) $(CFLAGS) -I$(LUA)/src -o $@.o -c $@.c - -luab: noparser - $(CC) -o $@ noparser.o $(LUA)/src/lua/lua.o -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) - $(BIN)/luac $(LUA)/test/hello.lua - $@ luac.out - -$@ -e'a=1' +noparser: noparser.o + $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua -llualib $(MYLIBS) + $(BIN)/luac $(TST)/hello.lua + -./a.out luac.out + -./a.out -e'a=1' 1: - $(CC) $(CFLAGS) -I../src -I../src/lib -I../src/lua all.c $(EXTRA_LIBS) $(DLLIB) - ./a.out $(LUA)/test/hello.lua - -flat: - cd ..; mkdir flat; mv include/*.h src/*.[ch] src/*/*.[ch] flat + $(CC) $(CFLAGS) all.c $(MYLIBS) + ./a.out $(TST)/hello.lua clean: - rm -f $(ALL) a.out core *.o luac.out + $(RM) $(ALL) a.out core core.* *.o luac.out @@ -5,6 +5,10 @@ all.c Full Lua interpreter in a single file. Do "make 1". +lua.hpp + Lua header files for C++. + This keeps the C interface to Lua. But Lua also compiles as clean C++. + lua.ico A Lua icon for Windows (and web sites, as favicon.ico). Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>. @@ -15,8 +19,7 @@ min.c noparser.c Linking with noparser.o avoids loading the parsing modules in lualib.a. - Do "make luab" to build a sample Lua intepreter that does not parse - Lua programs, only loads precompiled programs. + Do "make noparser" to see a demo. saconfig.c Configuration for Lua interpreter. diff --git a/etc/lua.hpp b/etc/lua.hpp index 273ec44c..ec417f59 100644 --- a/etc/lua.hpp +++ b/etc/lua.hpp @@ -1,5 +1,6 @@ // lua.hpp // Lua header files for C++ +// <<extern "C">> not supplied automatically because Lua also compiles as C++ extern "C" { #include "lua.h" diff --git a/etc/noparser.c b/etc/noparser.c index dc58faff..9396ad60 100644 --- a/etc/noparser.c +++ b/etc/noparser.c @@ -4,9 +4,12 @@ * 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". +* 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 @@ -22,22 +25,18 @@ void luaX_init (lua_State *L) { Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { UNUSED(z); UNUSED(buff); - lua_pushstring(L,"parser not loaded"); + lua_pushliteral(L,"parser not loaded"); lua_error(L); return NULL; } -/* -* If you also want to avoid the dump module, ldump.o, enable the code below. -*/ -#define NODUMP #ifdef NODUMP #include "lundump.h" int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip) { return 0; - lua_pushstring(L,"dumper not loaded"); + lua_pushliteral(L,"dumper not loaded"); lua_error(L); } #endif diff --git a/etc/saconfig.c b/etc/saconfig.c index 6c07cce1..676b38e1 100644 --- a/etc/saconfig.c +++ b/etc/saconfig.c @@ -6,39 +6,17 @@ * *** Line editing and history: * #define USE_READLINE to use the GNU readline library. +* Add "-lreadline -ltermcap" to MYLIBS. * * To use another library for this, use the code below as a start. * Make sure you #define lua_readline and lua_saveline accordingly. +* * If you do not #define lua_readline, you'll get a version based on fgets * that uses a static buffer of size MAXINPUT. -* -* -*** Static Lua libraries to be loaded at startup: -* #define lua_userinit(L) to a Lua function that loads libraries; typically -* #define lua_userinit(L) openstdlibs(L);myinit(L) -* or -* #define lua_userinit(L) myinit(L) -* -* Another way is to add the prototypes of the init functions here and -* #define LUA_EXTRALIBS accordingly. For example, -* #define LUA_EXTRALIBS {"mylib","luaopen_mylib"}, -* Note the ending comma! -* -* -*** Prompts: -* The stand-alone Lua interpreter uses two prompts: PROMPT and PROMPT2. -* PROMPT is the primary prompt, shown when the intepreter is ready to receive -* a new statement. PROMPT2 is the secondary prompt, shown while a statement -* is being entered but is still incomplete. -* -* -*** Program name: -* Error messages usually show argv[0] as a program name. In systems that do -* not give a valid string as argv[0], error messages show PROGNAME instead. -* -* */ +#define USE_READLINE + #ifdef USE_READLINE /* * This section implements of lua_readline and lua_saveline for lua.c using diff --git a/include/Makefile b/include/Makefile deleted file mode 100644 index 687cf383..00000000 --- a/include/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# makefile for Lua distribution (includes) - -LUA= .. - -include $(LUA)/config - -SRCS= lua.h lualib.h lauxlib.h luaconf.h - -all: - -clean: - -co: - co -q -f -M $(SRCS) - -klean: clean - rm -f $(SRCS) diff --git a/src/Makefile b/src/Makefile index 7812b918..cf7ff181 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,83 +1,135 @@ -# makefile for Lua core library - -LUA= .. - -include $(LUA)/config - -OBJS= \ - lapi.o \ - lcode.o \ - ldebug.o \ - ldo.o \ - ldump.o \ - lfunc.o \ - lgc.o \ - llex.o \ - lmem.o \ - lobject.o \ - lopcodes.o \ - lparser.o \ - lstate.o \ - lstring.o \ - ltable.o \ - ltm.o \ - lundump.o \ - lvm.o \ - lzio.o - -SRCS= \ - 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 \ - lapi.h \ - lcode.h \ - ldebug.h \ - ldo.h \ - lfunc.h \ - lgc.h \ - llex.h \ - llimits.h \ - lmem.h \ - lobject.h \ - lopcodes.h \ - lparser.h \ - lstate.h \ - lstring.h \ - ltable.h \ - ltm.h \ - lundump.h \ - lvm.h \ - lzio.h - -T= $(LIB)/liblua.a - -all: $T - -$T: $(OBJS) - $(AR) $@ $(OBJS) +# makefile for building Lua +# see INSTALL for installation instructions +# see ../Makefile and luaconf.h for further customization + +# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= + +CC= gcc +CFLAGS= -O2 -Wall $(MYCFLAGS) +MYCFLAGS= +MYLDFLAGS= -Wl,-E # enable dynamic loading in Linux +MYLIBS= -lm -ldl # enable dynamic loading in Linux +AR= ar rcu +RANLIB= ranlib +RM= rm -f + +# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= + +CORE_T= liblua.a +CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ + lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ + lundump.o lvm.o lzio.o + +LIB_T= liblualib.a +LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \ + lstrlib.o loadlib.o linit.o + +LUA_T= lua +LUA_O= lua.o + +LUAC_T= luac +LUAC_O= luac.o print.o lauxlib.o + +ALL_T= $(CORE_T) $(LIB_T) $(LUA_T) $(LUAC_T) +ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) +ALL_A= $(CORE_T) $(LIB_T) + +all: $(ALL_T) + +o: $(ALL_O) + +a: $(ALL_A) + +$(CORE_T): $(CORE_O) + $(AR) $@ $? $(RANLIB) $@ +$(LIB_T): $(LIB_O) + $(AR) $@ $? + $(RANLIB) $@ + +$(LUA_T): $(LUA_O) $(CORE_T) $(LIB_T) + $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) -L. -llua -llualib $(MYLIBS) + +$(LUAC_T): $(LUAC_O) $(CORE_T) + $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) -L. -llua + clean: - rm -f $(OBJS) $T + $(RM) $(ALL_T) $(ALL_O) + +depend: + @$(CC) $(CFLAGS) -MM *.c + +echo: + @echo "CC = $(CC)" + @echo "CFLAGS = $(CFLAGS)" + @echo "MYCFLAGS = $(MYCFLAGS)" + @echo "MYLDFLAGS = $(MYLDFLAGS)" + @echo "MYLIBS = $(MYLIBS)" + @echo "AR = $(AR)" + @echo "RANLIB = $(RANLIB)" + @echo "RM = $(RM)" + +# DO NOT DELETE -co: - co -q -f -M $(SRCS) +lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \ + lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \ + lundump.h lvm.h +lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h +lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h +lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ + lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ + ldo.h lgc.h +ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h +ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ + llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \ + ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h +ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ + lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \ + lstring.h lundump.h lvm.h +ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \ + ltm.h lzio.h lmem.h lundump.h +lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \ + lstate.h ltm.h lzio.h +lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ + lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h +linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h +liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h +llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ + lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h +lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h +lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h ldo.h +loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h +lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ + ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h +lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h +loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h +lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ + lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ + ldo.h lfunc.h lstring.h lgc.h +lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h +lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \ + ltm.h lzio.h lstring.h lgc.h +lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h +ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h +ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h +ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \ + lmem.h lstring.h lgc.h ltable.h +lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h +luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \ + lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \ + lundump.h +lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ + llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \ + lundump.h +lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ + lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h +lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \ + lzio.h +print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \ + ltm.h lzio.h lmem.h lopcodes.h lundump.h -klean: clean - rm -f $(SRCS) +# (end of Makefile) diff --git a/src/README b/src/README deleted file mode 100644 index 915f30b4..00000000 --- a/src/README +++ /dev/null @@ -1,5 +0,0 @@ -This is the Lua core. - -The standard Lua library are in lib/. -The standalone interpreter is in lua/. -The standalone compiler is in luac/. @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.22 2004/12/06 17:53:42 roberto Exp $ +** $Id: lapi.c,v 2.23 2004/12/13 12:15:11 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -867,9 +867,9 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { luaC_step(L); break; } - case LUA_GCSETSTEPMUL: { - res = g->stepmul; - g->stepmul = data; + case LUA_GCSETPACE: { + res = g->gcpace; + g->gcpace = data; break; } case LUA_GCSETINCMODE: { diff --git a/src/lib/lauxlib.c b/src/lauxlib.c index 615be8f2..5bbe918b 100644 --- a/src/lib/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.126 2004/09/29 21:03:14 roberto Exp $ +** $Id: lauxlib.c,v 1.127 2004/12/20 13:47:29 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -375,9 +375,19 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, } +static int readable (const char *fname) { + int err; + FILE *f = fopen(fname, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + getc(f); /* try to read it */ + err = ferror(f); + fclose(f); + return (err == 0); +} + + LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, const char *path) { - FILE *f; const char *p = path; for (;;) { const char *fname; @@ -387,15 +397,8 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, } fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); lua_remove(L, -2); /* remove path template */ - f = fopen(fname, "r"); /* try to open it */ - if (f) { - int err; - getc(f); /* try to read file */ - err = ferror(f); - fclose(f); - if (err == 0) /* open and read sucessful? */ - return fname; /* return that file name */ - } + if (readable(fname)) /* does file exist and is readable? */ + return fname; /* return that file name */ lua_pop(L, 1); /* remove file name */ } } diff --git a/include/lauxlib.h b/src/lauxlib.h index b47663ce..b47663ce 100644 --- a/include/lauxlib.h +++ b/src/lauxlib.h diff --git a/src/lib/lbaselib.c b/src/lbaselib.c index 8c628097..3b034bbc 100644 --- a/src/lib/lbaselib.c +++ b/src/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.161 2004/12/06 17:53:42 roberto Exp $ +** $Id: lbaselib.c,v 1.163 2004/12/13 12:15:11 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -182,9 +182,9 @@ static int luaB_gcinfo (lua_State *L) { static int luaB_collectgarbage (lua_State *L) { static const char *const opts[] = {"stop", "restart", "collect", - "count", "step", "setstepmul", "setincmode", NULL}; + "count", "step", "setpace", "setincmode", NULL}; static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, - LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETSTEPMUL, LUA_GCSETINCMODE}; + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPACE, LUA_GCSETINCMODE}; int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); int ex = luaL_optint(L, 2, 0); luaL_argcheck(L, o >= 0, 1, "invalid option"); @@ -396,18 +396,8 @@ static int luaB_tostring (lua_State *L) { case LUA_TNIL: lua_pushliteral(L, "nil"); break; - case LUA_TTABLE: - lua_pushfstring(L, "table: %p", lua_topointer(L, 1)); - break; - case LUA_TFUNCTION: - lua_pushfstring(L, "function: %p", lua_topointer(L, 1)); - break; - case LUA_TUSERDATA: - case LUA_TLIGHTUSERDATA: - lua_pushfstring(L, "userdata: %p", lua_topointer(L, 1)); - break; - case LUA_TTHREAD: - lua_pushfstring(L, "thread: %p", lua_topointer(L, 1)); + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); break; } return 1; diff --git a/src/lib/ldblib.c b/src/ldblib.c index 36d647aa..36d647aa 100644 --- a/src/lib/ldblib.c +++ b/src/ldblib.c diff --git a/src/ldebug.c b/src/ldebug.c index 17727d37..0456669f 100644 --- a/src/ldebug.c +++ b/src/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp $ +** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 roberto Exp $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -477,7 +477,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { } case OP_GETUPVAL: { int u = GETARG_B(i); /* upvalue index */ - *name = getstr(p->upvalues[u]); + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; return "upvalue"; } case OP_SELF: { @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.18 2004/12/06 17:53:42 roberto Exp $ +** $Id: lgc.c,v 2.19 2004/12/13 12:15:11 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -27,6 +27,7 @@ #define GCSWEEPMAX 10 #define GCSWEEPCOST 30 #define GCFINALIZECOST 100 +#define GCSTEPMUL 8 #define FIXEDMASK bitmask(FIXEDBIT) @@ -621,18 +622,17 @@ static l_mem singlestep (lua_State *L) { void luaC_step (lua_State *L) { global_State *g = G(L); - l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * g->stepmul; + l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * GCSTEPMUL; do { lim -= singlestep(L); if (g->gcstate == GCSpause) break; } while (lim > 0 || !g->incgc); - if (g->incgc) + if (g->gcstate != GCSpause) g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */ else { lua_assert(g->totalbytes >= g->estimate); - lua_assert(g->gcstate == GCSpause); - g->GCthreshold = 2*g->estimate; + g->GCthreshold = g->estimate + ((g->estimate/GCDIV) * g->gcpace); } } diff --git a/src/lib/Makefile b/src/lib/Makefile deleted file mode 100644 index 74f65215..00000000 --- a/src/lib/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# makefile for Lua standard library - -LUA= ../.. - -include $(LUA)/config - -EXTRA_DEFS= $(POPEN) $(TMPNAM) $(DEGREES) $(LOADLIB) - -OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o -SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c ltablib.c lstrlib.c loadlib.c linit.c - -T= $(LIB)/liblualib.a - -all: $T - -$T: $(OBJS) - $(AR) $@ $(OBJS) - $(RANLIB) $@ - -clean: - rm -f $(OBJS) $T - -co: - co -q -f -M $(SRCS) - -klean: clean - rm -f $(SRCS) diff --git a/src/lib/README b/src/lib/README deleted file mode 100644 index c5600b8e..00000000 --- a/src/lib/README +++ /dev/null @@ -1,8 +0,0 @@ -This is the standard Lua library. - -The code of the standard library can be read as an example of how to export -C functions to Lua. The easiest library to read is lmathlib.c. - -The library is implemented entirely on top of the official Lua API as declared -in lua.h, using lauxlib.c, which contains several useful functions for writing -libraries. We encourage developers to use lauxlib.c in their own libraries. diff --git a/src/lib/loadlib.c b/src/lib/loadlib.c deleted file mode 100644 index 63bc0bcc..00000000 --- a/src/lib/loadlib.c +++ /dev/null @@ -1,429 +0,0 @@ -/* -** $Id: loadlib.c,v 1.11 2004/11/19 15:52:12 roberto Exp $ -** Dynamic library loader for Lua -** See Copyright Notice in lua.h -* -* This Lua library exports a single function, called loadlib, which -* is called from Lua as loadlib(lib,init), where lib is the full -* name of the library to be loaded (including the complete path) and -* init is the name of a function to be called after the library is -* loaded. Typically, this function will register other functions, thus -* making the complete library available to Lua. The init function is -* *not* automatically called by loadlib. Instead, loadlib returns the -* init function as a Lua function that the client can call when it -* thinks is appropriate. In the case of errors, loadlib returns nil and -* two strings describing the error. The first string is supplied by -* the operating system; it should be informative and useful for error -* messages. The second string is "open", "init", or "absent" to identify -* the error and is meant to be used for making decisions without having -* to look into the first string (whose format is system-dependent). -* This module contains an implementation of loadlib for Unix systems -* that have dlfcn, an implementation for Darwin (Mac OS X), an -* implementation for Windows, and a stub for other systems. See -* the list at the end of this file for some links to available -* implementations of dlfcn and interfaces to other native dynamic -* loaders on top of which loadlib could be implemented. -*/ - - -#include <stdlib.h> -#include <string.h> - - -#define loadlib_c -#define LUA_LIB - -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" - - -#define ERR_OPEN 1 -#define ERR_FUNCTION 2 - - -static void registerlib (lua_State *L, const void *lib); - - -#if defined(USE_DLOPEN) -/* -* This is an implementation of loadlib based on the dlfcn interface. -* The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, -* NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least -* as an emulation layer on top of native functions. -*/ - -#include <dlfcn.h> - -#define freelib dlclose - -static int loadlib(lua_State *L, const char *path, const char *init) -{ - void *lib=dlopen(path,RTLD_NOW); - if (lib!=NULL) - { - lua_CFunction f=(lua_CFunction) dlsym(lib,init); - if (f!=NULL) - { - registerlib(L, lib); - lua_pushcfunction(L,f); - return 0; - } - } - /* else return appropriate error message */ - lua_pushstring(L,dlerror()); - if (lib!=NULL) { - dlclose(lib); - return ERR_FUNCTION; /* error loading function */ - } - else return ERR_OPEN; /* error loading library */ -} - - - -#elif defined(USE_DLL) -/* -* This is an implementation of loadlib for Windows using native functions. -*/ - -#include <windows.h> - -#define freelib(lib) FreeLibrary((HINSTANCE)lib) - -static void pusherror(lua_State *L) -{ - int error=GetLastError(); - char buffer[128]; - if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, - 0, error, 0, buffer, sizeof(buffer), 0)) - lua_pushstring(L,buffer); - else - lua_pushfstring(L,"system error %d\n",error); -} - -static int loadlib(lua_State *L, const char *path, const char *init) -{ - HINSTANCE lib=LoadLibrary(path); - if (lib!=NULL) - { - lua_CFunction f=(lua_CFunction) GetProcAddress(lib,init); - if (f!=NULL) - { - registerlib(L, lib); - lua_pushcfunction(L,f); - return 1; - } - } - pusherror(L); - if (lib!=NULL) { - FreeLibrary(lib); - return ERR_OPEN; - } - else return ERR_FUNCTION; -} - - - -/* Native Mac OS X / Darwin Implementation */ -#elif defined(USE_DYLD) - -#include <mach-o/dyld.h> - - -/* Mach cannot unload images (?) */ -#define freelib(lib) ((void)lib) - -static void pusherror (lua_State *L) -{ - const char *err_str; - const char *err_file; - NSLinkEditErrors err; - int err_num; - NSLinkEditError(&err, &err_num, &err_file, &err_str); - lua_pushstring(L, err_str); -} - -static int loadlib (lua_State *L, const char *path, const char *init) { - const struct mach_header *lib; - /* this would be a rare case, but prevents crashing if it happens */ - if(!_dyld_present()) { - lua_pushstring(L,"dyld not present."); - return ERR_OPEN; - } - lib = NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); - if(lib != NULL) { - NSSymbol init_sym = NSLookupSymbolInImage(lib, init, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | - NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - if(init_sym != NULL) { - lua_CFunction f = (lua_CFunction)NSAddressOfSymbol(init_sym); - registerlib(L, lib); - lua_pushcfunction(L,f); - return 0; - } - } - /* else an error ocurred */ - pusherror(L); - /* Can't unload image */ - return (lib != NULL) ? ERR_FUNCTION : ERR_OPEN; -} - - - -#else -/* Fallback for other systems */ - - -#define freelib(lib) ((void)lib) - -static int loadlib(lua_State *L) -{ - registerlib(L, NULL); /* to avoid warnings */ - lua_pushnil(L); - lua_pushliteral(L,"`loadlib' not supported"); - lua_pushliteral(L,"absent"); - return 3; -} - -#endif - - -/* -** common code for all implementations: put a library into the registry -** so that, when Lua closes its state, the library's __gc metamethod -** will be called to unload the library. -*/ -static void registerlib (lua_State *L, const void *lib) -{ - const void **plib = (const void **)lua_newuserdata(L, sizeof(const void *)); - *plib = lib; - luaL_getmetatable(L, "_LOADLIB"); - lua_setmetatable(L, -2); - lua_pushboolean(L, 1); - lua_settable(L, LUA_REGISTRYINDEX); /* registry[lib] = true */ -} - -/* -** __gc tag method: calls library's `freelib' function with the lib -** handle -*/ -static int gctm (lua_State *L) -{ - void *lib = *(void **)luaL_checkudata(L, 1, "_LOADLIB"); - freelib(lib); - return 0; -} - - -static int loadlib1 (lua_State *L) { - const char *path=luaL_checkstring(L,1); - const char *init=luaL_checkstring(L,2); - int res = loadlib(L,path,init); - if (res == 0) /* no error? */ - return 1; /* function is at stack top */ - else { /* error */ - lua_pushnil(L); - lua_insert(L,-2); /* insert nil before error message */ - lua_pushstring(L, (res==ERR_OPEN)?"open":"init"); - return 3; - } -} - - - -/* -** {====================================================== -** `require' and `module' functions -** ======================================================= -*/ - - -static const char *loadLua (lua_State *L, const char *fname, const char *name) { - const char *path; - /* try first `LUA_PATH' for compatibility */ - lua_getglobal(L, "LUA_PATH"); - path = lua_tostring(L, -1); - if (!path) { - lua_pop(L, 1); - luaL_getfield(L, LUA_GLOBALSINDEX, "package.path"); - path = lua_tostring(L, -1); - } - if (path == NULL) - luaL_error(L, "`package.path' must be a string"); - fname = luaL_searchpath(L, fname, path); - if (fname == NULL) return path; /* library not found in this path */ - if (luaL_loadfile(L, fname) != 0) - luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); - return NULL; /* library loaded successfully */ -} - - -static const char *loadC (lua_State *L, const char *fname, const char *name) { - const char *path; - const char *funcname; - luaL_getfield(L, LUA_GLOBALSINDEX, "package.cpath"); - path = lua_tostring(L, -1); - if (path == NULL) - luaL_error(L, "global _CPATH must be a string"); - fname = luaL_searchpath(L, fname, path); - if (fname == NULL) return path; /* library not found in this path */ - funcname = luaL_gsub(L, name, ".", ""); - funcname = lua_pushfstring(L, "%s%s", LUA_POF, funcname); - if (loadlib(L, fname, funcname) != 0) - luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); - return NULL; /* library loaded successfully */ -} - - -static int ll_require (lua_State *L) { - const char *name = luaL_checkstring(L, 1); - lua_settop(L, 1); - lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_getfield(L, 2, name); - if (lua_toboolean(L, -1)) /* is it there? */ - return 1; /* package is already loaded; return its result */ - /* else must load it; first mark it as loaded */ - lua_pushboolean(L, 1); - lua_setfield(L, 2, name); /* _LOADED[name] = true */ - /* check whether it is preloaded */ - lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); - lua_getfield(L, -1, name); - if (lua_isnil(L, -1)) { /* no preload function for that module? */ - const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP); - const char *cpath = loadC(L, fname, name); /* try a C module */ - if (cpath) { /* not found? */ - const char *path = loadLua(L, fname, name); /* try a Lua module */ - if (path) { /* yet not found? */ - lua_pushnil(L); - lua_setfield(L, 2, name); /* unmark _LOADED[name] */ - return luaL_error(L, "package `%s' not found\n" - " cpath: %s\n path: %s", - name, cpath, path); - } - } - } - lua_pushvalue(L, 1); /* pass name as argument to module */ - lua_call(L, 1, 1); /* run loaded module */ - if (!lua_isnil(L, -1)) /* non-nil return? */ - lua_setfield(L, 2, name); /* update _LOADED[name] with returned value */ - lua_getfield(L, 2, name); /* return _LOADED[name] */ - return 1; -} - - -static void setfenv (lua_State *L) { - lua_Debug ar; - lua_getstack(L, 1, &ar); - lua_getinfo(L, "f", &ar); - lua_pushvalue(L, -2); - lua_setfenv(L, -2); -} - - -static int ll_module (lua_State *L) { - const char *modname = luaL_checkstring(L, 1); - const char *dot; - lua_settop(L, 1); - lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); - /* try to find given table */ - luaL_getfield(L, LUA_GLOBALSINDEX, modname); - if (lua_isnil(L, -1)) { /* not found? */ - lua_pop(L, 1); /* remove previous result */ - lua_newtable(L); /* create it */ - /* register it with given name */ - lua_pushvalue(L, -1); - luaL_setfield(L, LUA_GLOBALSINDEX, modname); - } - else if (!lua_istable(L, -1)) - return luaL_error(L, "name conflict for module `%s'", modname); - /* check whether table already has a _NAME field */ - lua_getfield(L, -1, "_NAME"); - if (!lua_isnil(L, -1)) /* is table an initialized module? */ - lua_pop(L, 1); - else { /* no; initialize it */ - lua_pop(L, 1); - lua_newtable(L); /* create new metatable */ - lua_pushvalue(L, LUA_GLOBALSINDEX); - lua_setfield(L, -2, "__index"); /* mt.__index = _G */ - lua_setmetatable(L, -2); - lua_pushstring(L, modname); - lua_setfield(L, -2, "_NAME"); - dot = strrchr(modname, '.'); /* look for last dot in module name */ - if (dot == NULL) dot = modname; - else dot++; - /* set _PACKAGE as package name (full module name minus last part) */ - lua_pushlstring(L, modname, dot - modname); - lua_setfield(L, -2, "_PACKAGE"); - } - lua_pushvalue(L, -1); - lua_setfield(L, 2, modname); /* _LOADED[modname] = new table */ - setfenv(L); - return 0; -} - - -/* }====================================================== */ - - -static const luaL_reg ll_funcs[] = { - {"loadlib", loadlib1}, - {"require", ll_require}, - {"module", ll_module}, - {NULL, NULL} -}; - - - -LUALIB_API int luaopen_loadlib (lua_State *L) { - const char *path; - /* create new type _LOADLIB */ - luaL_newmetatable(L, "_LOADLIB"); - lua_pushcfunction(L, gctm); - lua_setfield(L, -2, "__gc"); - /* create `package' table */ - lua_newtable(L); - lua_pushvalue(L, -1); - lua_setglobal(L, "package"); - /* set field `path' */ - path = getenv(LUA_PATH); - if (path == NULL) path = LUA_PATH_DEFAULT; - lua_pushstring(L, path); - lua_setfield(L, -2, "path"); - /* set field `cpath' */ - path = getenv(LUA_CPATH); - if (path == NULL) path = LUA_CPATH_DEFAULT; - lua_pushstring(L, path); - lua_setfield(L, -2, "cpath"); - /* set field `loaded' */ - lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_setfield(L, -2, "loaded"); - /* set field `preload' */ - lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); - lua_setfield(L, -2, "preload"); - lua_pushvalue(L, LUA_GLOBALSINDEX); - luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */ - return 1; -} - -/* -* Here are some links to available implementations of dlfcn and -* interfaces to other native dynamic loaders on top of which loadlib -* could be implemented. Please send contributions and corrections to us. -* -* AIX -* Starting with AIX 4.2, dlfcn is included in the base OS. -* There is also an emulation package available. -* http://www.faqs.org/faqs/aix-faq/part4/section-21.html -* -* HPUX -* HPUX 11 has dlfcn. For HPUX 10 use shl_*. -* http://www.geda.seul.org/mailinglist/geda-dev37/msg00094.html -* http://www.stat.umn.edu/~luke/xls/projects/dlbasics/dlbasics.html -* -* Macintosh, Windows -* http://www.stat.umn.edu/~luke/xls/projects/dlbasics/dlbasics.html -* -* GLIB has wrapper code for BeOS, OS2, Unix and Windows -* http://cvs.gnome.org/lxr/source/glib/gmodule/ -* -*/ diff --git a/src/lib/linit.c b/src/linit.c index 0d5f9cd4..0d5f9cd4 100644 --- a/src/lib/linit.c +++ b/src/linit.c diff --git a/src/lib/liolib.c b/src/liolib.c index ca9b8025..ca9b8025 100644 --- a/src/lib/liolib.c +++ b/src/liolib.c diff --git a/src/llimits.h b/src/llimits.h index 6be658f0..c3d5d532 100644 --- a/src/llimits.h +++ b/src/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.61 2004/11/24 18:55:56 roberto Exp $ +** $Id: llimits.h,v 1.62 2004/12/13 12:15:11 roberto Exp $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ @@ -73,6 +73,8 @@ typedef LUA_UACNUMBER l_uacNumber; typedef lu_int32 Instruction; +/* divisor for GC pace */ +#define GCDIV 8 /* maximum stack for a Lua function */ #define MAXSTACK 250 diff --git a/src/lib/lmathlib.c b/src/lmathlib.c index fcd2eefb..fcd2eefb 100644 --- a/src/lib/lmathlib.c +++ b/src/lmathlib.c diff --git a/src/loadlib.c b/src/loadlib.c new file mode 100644 index 00000000..4adcbdc0 --- /dev/null +++ b/src/loadlib.c @@ -0,0 +1,464 @@ +/* +** $Id: loadlib.c,v 1.15 2004/12/29 18:56:34 roberto Exp $ +** Dynamic library loader for Lua +** See Copyright Notice in lua.h +* +* This module contains an implementation of loadlib for Unix systems +* that have dlfcn, an implementation for Darwin (Mac OS X), an +* implementation for Windows, and a stub for other systems. +*/ + + +#include <stdlib.h> +#include <string.h> + + +#define loadlib_c +#define LUA_LIB + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + + +#define LIBPREFIX "LOADLIB: " + +#define POF LUA_POF +#define LIB_FAIL "open" + + +static void ll_unloadlib (void *lib); +static void *ll_load (lua_State *L, const char *path); +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); + + + +#if defined(USE_DLOPEN) +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include <dlfcn.h> + +static void ll_unloadlib (void *lib) { + dlclose(lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + void *lib = dlopen(path, RTLD_NOW); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +/* }====================================================== */ + + + +#elif defined(USE_DLL) +/* +** {====================================================================== +** This is an implementation of loadlib for Windows using native functions. +** ======================================================================= +*/ + +#include <windows.h> + + +static void pusherror (lua_State *L) { + int error = GetLastError(); + char buffer[128]; + if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L,buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib (void *lib) { + FreeLibrary((HINSTANCE)lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + HINSTANCE lib = LoadLibrary(path); + if (lib == NULL) pusherror(L); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +/* }====================================================== */ + + + +#elif defined(USE_DYLD) +/* +** {====================================================================== +** Native Mac OS X / Darwin Implementation +** ======================================================================= +*/ + +#include <mach-o/dyld.h> + + +#undef POF +#define POF "_" LUA_POF + + +static void pusherror (lua_State *L) { + const char *err_str; + const char *err_file; + NSLinkEditErrors err; + int err_num; + NSLinkEditError(&err, &err_num, &err_file, &err_str); + lua_pushstring(L, err_str); +} + + +static const char *errorfromcode (NSObjectFileImageReturnCode ret) { + switch (ret) { + case NSObjectFileImageInappropriateFile: + return "file is not a bundle"; + case NSObjectFileImageArch: + return "library is for wrong CPU type"; + case NSObjectFileImageFormat: + return "bad format"; + case NSObjectFileImageAccess: + return "cannot access file"; + case NSObjectFileImageFailure: + default: + return "unable to load library"; + } +} + + +static void ll_unloadlib (void *lib) { + NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); +} + + +static void *ll_load (lua_State *L, const char *path) { + NSObjectFileImage img; + NSObjectFileImageReturnCode ret; + /* this would be a rare case, but prevents crashing if it happens */ + if(!_dyld_present()) { + lua_pushliteral(L, "dyld not present"); + return NULL; + } + ret = NSCreateObjectFileImageFromFile(path, &img); + if (ret == NSObjectFileImageSuccess) { + NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage(img); + if (mod == NULL) pusherror(L); + return mod; + } + lua_pushstring(L, errorfromcode(ret)); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); + if (nss == NULL) { + lua_pushfstring(L, "symbol `%s' not found", sym); + return NULL; + } + return (lua_CFunction)NSAddressOfSymbol(nss); +} + +/* }====================================================== */ + + + +#else +/* +** {====================================================== +** Fallback for other systems +** ======================================================= +*/ + +#undef LIB_FAIL +#define LIB_FAIL "absent" + + +static void ll_unloadlib (void *lib) { + (void)lib; /* to avoid warnings */ +} + + +static void *ll_load (lua_State *L, const char *path) { + (void)path; /* to avoid warnings */ + lua_pushliteral(L,"`loadlib' not supported"); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + (void)lib; (void)sym; /* to avoid warnings */ + lua_pushliteral(L,"`loadlib' not supported"); + return NULL; +} + +/* }====================================================== */ +#endif + + + +static void **ll_register (lua_State *L, const char *path) { + void **plib; + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(const void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + + +/* +** __gc tag method: calls library's `ll_unloadlib' function with the lib +** handle +*/ +static int gctm (lua_State *L) { + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (lib) { + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + } + return 0; +} + + +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { + const char *reason; + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path); + if (*reg == NULL) + reason = LIB_FAIL; + else { + lua_CFunction f = ll_sym(L, *reg, sym); + if (f) { + lua_pushcfunction(L, f); + return 1; /* return function */ + } + reason = "init"; + } + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, reason); + return 3; /* return nil, ll_error, reason */ +} + + +static int ll_loadlib (lua_State *L) { + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + return ll_loadfunc(L, path, init); +} + + + +/* +** {====================================================== +** `require' and `module' functions +** ======================================================= +*/ + + +static const char *loadLua (lua_State *L, const char *fname, const char *name) { + const char *path; + /* try first `LUA_PATH' for compatibility */ + lua_getglobal(L, "LUA_PATH"); + path = lua_tostring(L, -1); + if (!path) { + lua_pop(L, 1); + luaL_getfield(L, LUA_GLOBALSINDEX, "package.path"); + path = lua_tostring(L, -1); + } + if (path == NULL) + luaL_error(L, "`package.path' must be a string"); + fname = luaL_searchpath(L, fname, path); + if (fname == NULL) return path; /* library not found in this path */ + if (luaL_loadfile(L, fname) != 0) + luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); + return NULL; /* library loaded successfully */ +} + + +static const char *loadC (lua_State *L, const char *fname, const char *name) { + const char *path; + const char *funcname; + luaL_getfield(L, LUA_GLOBALSINDEX, "package.cpath"); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, "`package.cpath' must be a string"); + fname = luaL_searchpath(L, fname, path); + if (fname == NULL) return path; /* library not found in this path */ + funcname = luaL_gsub(L, name, ".", LUA_OFSEP); + funcname = lua_pushfstring(L, "%s%s", POF, funcname); + if (ll_loadfunc(L, fname, funcname) != 1) + luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -2)); + return NULL; /* library loaded successfully */ +} + + +static int ll_require (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + lua_settop(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) /* is it there? */ + return 1; /* package is already loaded; return its result */ + /* else must load it; first mark it as loaded */ + lua_pushboolean(L, 1); + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + /* check whether it is preloaded */ + lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) { /* no preload function for that module? */ + const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP); + const char *cpath = loadC(L, fname, name); /* try a C module */ + if (cpath) { /* not found? */ + const char *path = loadLua(L, fname, name); /* try a Lua module */ + if (path) { /* yet not found? */ + lua_pushnil(L); + lua_setfield(L, 2, name); /* unmark _LOADED[name] */ + return luaL_error(L, "package `%s' not found\n" + " cpath: %s\n path: %s", + name, cpath, path); + } + } + } + lua_pushvalue(L, 1); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* update _LOADED[name] with returned value */ + lua_getfield(L, 2, name); /* return _LOADED[name] */ + return 1; +} + + +static void setfenv (lua_State *L) { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "f", &ar); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); +} + + +static int ll_module (lua_State *L) { + const char *modname = luaL_checkstring(L, 1); + const char *dot; + lua_settop(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + /* try to find given table */ + luaL_getfield(L, LUA_GLOBALSINDEX, modname); + if (lua_isnil(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + lua_newtable(L); /* create it */ + /* register it with given name */ + lua_pushvalue(L, -1); + luaL_setfield(L, LUA_GLOBALSINDEX, modname); + } + else if (!lua_istable(L, -1)) + return luaL_error(L, "name conflict for module `%s'", modname); + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) /* is table an initialized module? */ + lua_pop(L, 1); + else { /* no; initialize it */ + lua_pop(L, 1); + lua_newtable(L); /* create new metatable */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + lua_setmetatable(L, -2); + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; + else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, dot - modname); + lua_setfield(L, -2, "_PACKAGE"); + } + lua_pushvalue(L, -1); + lua_setfield(L, 2, modname); /* _LOADED[modname] = new table */ + setfenv(L); + return 0; +} + + +/* }====================================================== */ + + +static const luaL_reg ll_funcs[] = { + {"loadlib", ll_loadlib}, + {"require", ll_require}, + {"module", ll_module}, + {NULL, NULL} +}; + + + +LUALIB_API int luaopen_loadlib (lua_State *L) { + const char *path; + /* create new type _LOADLIB */ + luaL_newmetatable(L, "_LOADLIB"); + lua_pushcfunction(L, gctm); + lua_setfield(L, -2, "__gc"); + /* create `package' table */ + lua_newtable(L); + lua_pushvalue(L, -1); + lua_setglobal(L, "package"); + /* set field `path' */ + path = getenv(LUA_PATH); + if (path == NULL) path = LUA_PATH_DEFAULT; + lua_pushstring(L, path); + lua_setfield(L, -2, "path"); + /* set field `cpath' */ + path = getenv(LUA_CPATH); + if (path == NULL) path = LUA_CPATH_DEFAULT; + lua_pushstring(L, path); + lua_setfield(L, -2, "cpath"); + /* set field `loaded' */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_setfield(L, -2, "loaded"); + /* set field `preload' */ + lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */ + return 1; +} + diff --git a/src/lib/loslib.c b/src/loslib.c index 4f1d2d03..4f1d2d03 100644 --- a/src/lib/loslib.c +++ b/src/loslib.c diff --git a/src/lparser.c b/src/lparser.c index b40cf7c7..b6b3c0a0 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.10 2004/12/03 20:50:25 roberto Exp $ +** $Id: lparser.c,v 2.11 2004/12/07 18:31:16 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -109,10 +109,15 @@ static int testnext (LexState *ls, int c) { static void check (LexState *ls, int c) { - if (!testnext(ls, c)) + if (ls->t.token != c) error_expected(ls, c); } +static void checknext (LexState *ls, int c) { + check(ls, c); + next(ls); +} + #define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } @@ -133,7 +138,7 @@ static void check_match (LexState *ls, int what, int who, int where) { static TString *str_checkname (LexState *ls) { TString *ts; - if (ls->t.token != TK_NAME) error_expected(ls, TK_NAME); + check(ls, TK_NAME); ts = ls->t.seminfo.ts; next(ls); return ts; @@ -396,7 +401,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { funcstate.f->is_vararg = NEWSTYLEVARARG; next(&lexstate); /* read first token */ chunk(&lexstate); - check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); + check(&lexstate, TK_EOS); close_func(&lexstate); lua_assert(funcstate.prev == NULL); lua_assert(funcstate.f->nups == 0); @@ -428,7 +433,7 @@ static void yindex (LexState *ls, expdesc *v) { next(ls); /* skip the '[' */ expr(ls, v); luaK_exp2val(ls->fs, v); - check(ls, ']'); + checknext(ls, ']'); } @@ -460,7 +465,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) { } else /* ls->t.token == '[' */ yindex(ls, &key); - check(ls, '='); + checknext(ls, '='); luaK_exp2RK(fs, &key); expr(ls, &val); luaK_codeABC(fs, OP_SETTABLE, cc->t->info, luaK_exp2RK(fs, &key), @@ -514,7 +519,7 @@ static void constructor (LexState *ls, expdesc *t) { init_exp(t, VRELOCABLE, pc); init_exp(&cc.v, VVOID, 0); /* no value (yet) */ luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ - check(ls, '{'); + checknext(ls, '{'); do { lua_assert(cc.v.k == VVOID || cc.tostore > 0); testnext(ls, ';'); /* compatibility only */ @@ -584,13 +589,13 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { FuncState new_fs; open_func(ls, &new_fs); new_fs.f->lineDefined = line; - check(ls, '('); + checknext(ls, '('); if (needself) { new_localvarliteral(ls, "self", 0); adjustlocalvars(ls, 1); } parlist(ls); - check(ls, ')'); + checknext(ls, ')'); chunk(ls); check_match(ls, TK_END, TK_FUNCTION, line); close_func(ls); @@ -944,7 +949,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { } else { /* assignment -> `=' explist1 */ int nexps; - check(ls, '='); + checknext(ls, '='); nexps = explist1(ls, &e); if (nexps != nvars) { adjust_assign(ls, nvars, nexps, &e); @@ -1011,7 +1016,7 @@ static void whilestat (LexState *ls, int line) { codeexp[i] = fs->f->code[expinit + i]; fs->pc = expinit; /* remove `exp' code */ enterblock(fs, &bl, 1); - check(ls, TK_DO); + checknext(ls, TK_DO); blockinit = luaK_getlabel(fs); block(ls); luaK_patchtohere(fs, whileinit); /* initial jump jumps to here */ @@ -1059,7 +1064,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { FuncState *fs = ls->fs; int prep, endfor; adjustlocalvars(ls, 3); /* control variables */ - check(ls, TK_DO); + checknext(ls, TK_DO); prep = luaK_codeAsBx(fs, (isnum ? OP_FORPREP : OP_TFORPREP), base, NO_JUMP); enterblock(fs, &bl, 0); /* scope for declared variables */ adjustlocalvars(ls, nvars); @@ -1082,9 +1087,9 @@ static void fornum (LexState *ls, TString *varname, int line) { new_localvarliteral(ls, "(for limit)", 1); new_localvarliteral(ls, "(for step)", 2); new_localvar(ls, varname, 3); - check(ls, '='); + checknext(ls, '='); exp1(ls); /* initial value */ - check(ls, ','); + checknext(ls, ','); exp1(ls); /* limit */ if (testnext(ls, ',')) exp1(ls); /* optional step */ @@ -1111,7 +1116,7 @@ static void forlist (LexState *ls, TString *indexname) { new_localvar(ls, indexname, nvars++); while (testnext(ls, ',')) new_localvar(ls, str_checkname(ls), nvars++); - check(ls, TK_IN); + checknext(ls, TK_IN); line = ls->linenumber; adjust_assign(ls, 3, explist1(ls, &e), &e); luaK_checkstack(fs, 3); /* extra space to call generator */ @@ -1142,7 +1147,7 @@ static int test_then_block (LexState *ls) { int flist; next(ls); /* skip IF or ELSEIF */ flist = cond(ls); - check(ls, TK_THEN); + checknext(ls, TK_THEN); block(ls); /* `then' part */ return flist; } diff --git a/src/lstate.c b/src/lstate.c index dfd35be6..bd238c58 100644 --- a/src/lstate.c +++ b/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.18 2004/12/06 17:53:42 roberto Exp $ +** $Id: lstate.c,v 2.19 2004/12/13 12:15:11 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -193,7 +193,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { setnilvalue(gval(g->dummynode)); gnext(g->dummynode) = NULL; g->totalbytes = sizeof(LG); - g->stepmul = STEPMUL; + g->gcpace = GCDIV; g->incgc = 1; if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { /* memory allocation error: free partial state */ diff --git a/src/lstate.h b/src/lstate.h index 81fb75a0..4f29190a 100644 --- a/src/lstate.h +++ b/src/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.9 2004/12/06 17:53:42 roberto Exp $ +** $Id: lstate.h,v 2.10 2004/12/13 12:15:11 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -85,7 +85,7 @@ typedef struct global_State { lu_mem totalbytes; /* number of bytes currently allocated */ lu_mem estimate; /* an estimate of number of bytes actually in use */ lu_mem prevestimate; /* previous estimate */ - int stepmul; /* relative `speed' of the GC */ + int gcpace; /* relative `speed' of the GC */ int incgc; /* 0 if GC is done non-incrementally */ lua_CFunction panic; /* to be called in unprotected errors */ TValue _registry; diff --git a/src/lib/lstrlib.c b/src/lstrlib.c index a9c002fb..a9c002fb 100644 --- a/src/lib/lstrlib.c +++ b/src/lstrlib.c diff --git a/src/lib/ltablib.c b/src/ltablib.c index ab953c61..792bf313 100644 --- a/src/lib/ltablib.c +++ b/src/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.26 2004/06/15 13:37:21 roberto Exp $ +** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -19,7 +19,7 @@ #define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) -static int luaB_foreachi (lua_State *L) { +static int foreachi (lua_State *L) { int i; int n = aux_getn(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); @@ -36,7 +36,7 @@ static int luaB_foreachi (lua_State *L) { } -static int luaB_foreach (lua_State *L) { +static int foreach (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 2, LUA_TFUNCTION); lua_pushnil(L); /* first key */ @@ -54,13 +54,13 @@ static int luaB_foreach (lua_State *L) { } -static int luaB_getn (lua_State *L) { +static int getn (lua_State *L) { lua_pushinteger(L, aux_getn(L, 1)); return 1; } -static int luaB_setn (lua_State *L) { +static int setn (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); luaL_setn(L, 1, luaL_checkint(L, 2)); lua_pushvalue(L, 1); @@ -68,7 +68,7 @@ static int luaB_setn (lua_State *L) { } -static int luaB_tinsert (lua_State *L) { +static int tinsert (lua_State *L) { int v = lua_gettop(L); /* number of arguments */ int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ int pos; /* where to insert new element */ @@ -90,7 +90,7 @@ static int luaB_tinsert (lua_State *L) { } -static int luaB_tremove (lua_State *L) { +static int tremove (lua_State *L) { int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; int pos = luaL_optint(L, 2, e); if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ @@ -220,7 +220,7 @@ static void auxsort (lua_State *L, int l, int u) { } /* repeat the routine for the larger one */ } -static int luaB_sort (lua_State *L) { +static int sort (lua_State *L) { int n = aux_getn(L, 1); luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */ if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ @@ -235,13 +235,13 @@ static int luaB_sort (lua_State *L) { static const luaL_reg tab_funcs[] = { {"concat", str_concat}, - {"foreach", luaB_foreach}, - {"foreachi", luaB_foreachi}, - {"getn", luaB_getn}, - {"setn", luaB_setn}, - {"sort", luaB_sort}, - {"insert", luaB_tinsert}, - {"remove", luaB_tremove}, + {"foreach", foreach}, + {"foreachi", foreachi}, + {"getn", getn}, + {"setn", setn}, + {"sort", sort}, + {"insert", tinsert}, + {"remove", tremove}, {NULL, NULL} }; diff --git a/src/lua/lua.c b/src/lua.c index 6a21a6ae..6a21a6ae 100644 --- a/src/lua/lua.c +++ b/src/lua.c diff --git a/include/lua.h b/src/lua.h index aa4401c7..25fc8405 100644 --- a/include/lua.h +++ b/src/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.196 2004/12/06 17:53:42 roberto Exp $ +** $Id: lua.h,v 1.197 2004/12/13 12:15:11 roberto Exp $ ** Lua - An Extensible Extension Language ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** http://www.lua.org mailto:info@lua.org @@ -17,7 +17,7 @@ #include "luaconf.h" -#define LUA_VERSION "Lua 5.1 (work3)" +#define LUA_VERSION "Lua 5.1 (work4)" #define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" @@ -225,7 +225,7 @@ LUA_API int lua_threadstatus (lua_State *L); #define LUA_GCCOLLECT 2 #define LUA_GCCOUNT 3 #define LUA_GCSTEP 4 -#define LUA_GCSETSTEPMUL 5 +#define LUA_GCSETPACE 5 #define LUA_GCSETINCMODE 6 LUA_API int lua_gc (lua_State *L, int what, int data); diff --git a/src/lua/Makefile b/src/lua/Makefile deleted file mode 100644 index aa52832f..00000000 --- a/src/lua/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# makefile for Lua interpreter - -LUA= ../.. - -include $(LUA)/config - -EXTRA_DEFS= $(USERCONF) -OBJS= lua.o -SRCS= lua.c - -T= $(BIN)/lua - -all: $T - -$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a - $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) - -$(LIB)/liblua.a: - cd ..; $(MAKE) - -$(LIB)/liblualib.a: - cd ../lib; $(MAKE) - -clean: - rm -f $(OBJS) $T - -co: - co -q -f -M $(SRCS) - -klean: clean - rm -f $(SRCS) diff --git a/src/lua/README b/src/lua/README deleted file mode 100644 index 525f6c15..00000000 --- a/src/lua/README +++ /dev/null @@ -1,41 +0,0 @@ -This is lua, the stand-alone Lua interpreter. -It can be used as a batch interpreter and also interactively. -There are man pages for it in both nroff and html in ../../doc. - -Usage: lua [options] [script [args]]. Available options are: - - execute stdin as a file - -e stat execute string `stat' - -i enter interactive mode after executing `script' - -l name load and run library `name' - -v show version information - -w catch use of undefined global variables - -- stop handling options - -This interpreter is suitable for using Lua as a stand-alone language; it loads -all standard libraries. For a minimal interpreter, see ../../etc/min.c. - -If your application simply exports new functions to Lua (which is common), -then you can use this interpreter unmodified by putting your functions into -a library and loading it dynamically (if you have built support for dynamic -libraries). - -If you need to add your library statically, then you can use this interpreter -almost unmodified, as follows: - -* First, define a function - void myinit (lua_State *L) - in your own code. In this function, you should do whatever initializations - are needed by your application, typically exporting your functions to Lua. - (Of course, you can use any name instead of "myinit".) - -* Then, #define lua_userinit(L) in luaconf.h to call luaopen_stdlibs and - possibly luaopen_stdlibs, which opens all standard libraries. If you don't - need them, just don't call openstdlibs and open any standard libraries that - you do need in myinit. - -* Alternatively, write your own luaopen_stdlibs; the linker will use your - version (if you ask politely). - -Just remember to link your C code when building lua! - -For other customizations, see ../../include/luaconf.h . diff --git a/src/luac/luac.c b/src/luac.c index dfbcab05..dfbcab05 100644 --- a/src/luac/luac.c +++ b/src/luac.c diff --git a/src/luac/Makefile b/src/luac/Makefile deleted file mode 100644 index 509577bb..00000000 --- a/src/luac/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# makefile for Lua compiler - -LUA= ../.. - -include $(LUA)/config - -INCS= -I$(INC) -I.. $(EXTRA_INCS) -OBJS= luac.o print.o -SRCS= luac.c print.c - -T= $(BIN)/luac - -all: $T - -$T: $(OBJS) $(LIB)/liblua.a ../lib/lauxlib.o - $(CC) -o $@ $(MYLDFLAGS) $(OBJS) ../lib/lauxlib.o -L$(LIB) -llua $(EXTRA_LIBS) - -$(LIB)/liblua.a: - cd ..; $(MAKE) - -../lib/lauxlib.o: - cd ../lib; $(MAKE) lauxlib.o - -clean: - rm -f $(OBJS) $T - -co: - co -q -f -M $(SRCS) - -klean: clean - rm -f $(SRCS) diff --git a/src/luac/README b/src/luac/README deleted file mode 100644 index 00dd1cd4..00000000 --- a/src/luac/README +++ /dev/null @@ -1,18 +0,0 @@ -This is luac, the Lua compiler. -There are man pages for it in both nroff and html in ../../doc. - -luac translates Lua programs into binary files that can be loaded later. -The main advantages of pre-compiling chunks are: faster loading, protecting -source code from user changes, and off-line syntax error detection. -luac can also be used to learn about the Lua virtual machine. - -Usage: luac [options] [filenames]. Available options are: - - process stdin - -l list - -o name output to file `name' (default is "luac.out") - -p parse only - -s strip debug information - -v show version information - -- stop handling options - -luac is also an example of how to use the internals of Lua (politely). diff --git a/include/luaconf.h b/src/luaconf.h index f00bbd05..7ea477e2 100644 --- a/include/luaconf.h +++ b/src/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.20 2004/12/06 17:53:42 roberto Exp $ +** $Id: luaconf.h,v 1.22 2004/12/27 15:58:15 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -31,10 +31,22 @@ */ /* default path */ -#define LUA_PATH_DEFAULT \ - "./?.lua;/usr/local/share/lua/5.0/?.lua;/usr/local/share/lua/5.0/?/init.lua" -#define LUA_CPATH_DEFAULT \ - "./?.so;/usr/local/lib/lua/5.0/?.so;/usr/local/lib/lua/5.0/lib?.so" +#if defined(_WIN32) +#define LUA_ROOT "C:\\Program Files\\Lua51" +#define LUA_LDIR LUA_ROOT "\\lua" +#define LUA_CDIR LUA_ROOT "\\dll" +#define LUA_PATH_DEFAULT \ + "?.lua;" LUA_LDIR "\\?.lua;" LUA_LDIR "\\?\\init.lua" +#define LUA_CPATH_DEFAULT "?.dll;" LUA_CDIR "\\?.dll" + +#else +#define LUA_ROOT "/usr/local" +#define LUA_LDIR LUA_ROOT "/share/lua/5.1" +#define LUA_CDIR LUA_ROOT "/lib/lua/5.1" +#define LUA_PATH_DEFAULT \ + "./?.lua;" LUA_LDIR "/?.lua;" LUA_LDIR "/?/init.lua" +#define LUA_CPATH_DEFAULT "./?.so;" LUA_CDIR "/?.so" +#endif @@ -57,10 +69,10 @@ #define LUA_API extern /* mark for auxlib functions */ -#define LUALIB_API extern +#define LUALIB_API extern /* buffer size used by lauxlib buffer system */ -#define LUAL_BUFFERSIZE BUFSIZ +#define LUAL_BUFFERSIZE BUFSIZ /* assertions in Lua (mainly for internal debugging) */ @@ -82,6 +94,10 @@ #ifdef _POSIX_C_SOURCE #include <unistd.h> #define stdin_is_tty() isatty(0) +#elif defined(_WIN32) +#include <io.h> +#include <fcntl.h> +#define stdin_is_tty() _isatty(_fileno(stdin)) #else #define stdin_is_tty() 1 /* assume stdin is a tty */ #endif @@ -200,14 +216,31 @@ /* function to convert a lua_Number to int (with any rounding method) */ #if defined(__GNUC__) && defined(__i386) #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st") + +#elif defined(_WIN32) && defined(_M_IX86) +#include <math.h> +#pragma warning(disable: 4514) +__inline int l_lrint (double flt) +{ int i; + _asm { + fld flt + fistp i + }; + return i; +} +#define lua_number2int(i,d) ((i)=l_lrint((d))) + #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L) /* on machines compliant with C99, you can try `lrint' */ #include <math.h> #define lua_number2int(i,d) ((i)=lrint(d)) + #else #define lua_number2int(i,d) ((i)=(int)(d)) + #endif + /* function to convert a lua_Number to lua_Integer (with any rounding method) */ #define lua_number2integer(i,n) lua_number2int((i), (n)) @@ -258,8 +291,8 @@ ** or when reading immutable fields from global objects ** (such as string values and udata values). */ -#define lua_lock(L) ((void) 0) -#define lua_unlock(L) ((void) 0) +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) /* ** this macro allows a thread switch in appropriate places in the Lua @@ -273,9 +306,6 @@ #define lua_userstateopen(L) /* empty */ -/* initial GC parameters */ -#define STEPMUL 4 - #endif /* }====================================================== */ @@ -299,14 +329,17 @@ #define LUA_CPATH "LUA_CPATH" /* prefix for open functions in C libraries */ -#if defined(__APPLE__) && defined(__MACH__) -#define LUA_POF "_luaopen_" -#else #define LUA_POF "luaopen_" -#endif + +/* separator for open functions in C libraries */ +#define LUA_OFSEP "" /* directory separator (for submodules) */ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else #define LUA_DIRSEP "/" +#endif /* separator of templates in a path */ #define LUA_PATH_SEP ';' @@ -332,12 +365,12 @@ /* ** Configuration for loadlib */ -#if defined(__linux) || defined(sun) || defined(sgi) || defined(BSD) -#define USE_DLOPEN -#elif defined(_WIN32) +#if defined(_WIN32) #define USE_DLL #elif defined(__APPLE__) && defined(__MACH__) #define USE_DYLD +#elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD) +#define USE_DLOPEN #endif @@ -350,7 +383,4 @@ /* Local configuration */ -#undef USE_TMPNAME -#define USE_TMPNAME 1 - #endif diff --git a/include/lualib.h b/src/lualib.h index c8114ed2..c8114ed2 100644 --- a/include/lualib.h +++ b/src/lualib.h diff --git a/src/luac/print.c b/src/print.c index f273ebfc..f273ebfc 100644 --- a/src/luac/print.c +++ b/src/print.c diff --git a/test/lua b/test/lua deleted file mode 120000 index 3b0b1a28..00000000 --- a/test/lua +++ /dev/null @@ -1 +0,0 @@ -../bin/lua
\ No newline at end of file diff --git a/test/luac b/test/luac deleted file mode 120000 index 694bc0dc..00000000 --- a/test/luac +++ /dev/null @@ -1 +0,0 @@ -../bin/luac
\ No newline at end of file diff --git a/test/printf.lua b/test/printf.lua index 66dfda65..58c63ff5 100644 --- a/test/printf.lua +++ b/test/printf.lua @@ -1,7 +1,7 @@ -- an implementation of printf function printf(...) - io.write(string.format(unpack(arg))) + 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/xd.lua b/test/xd.lua index 32331dc1..ebc3effc 100644 --- a/test/xd.lua +++ b/test/xd.lua @@ -2,12 +2,12 @@ -- usage: lua xd.lua < file local offset=0 - -while 1 do +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) + 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 |