Unified · Split
| @@ -8,6 +8,9 @@ This is Lua 5.1 (work). · 7 unmodified lines | ||
| 8 | 8 | + new semantics for setn/getn. |
| 9 | 9 | + new syntax/semantics for varargs. |
| 10 | 10 | + new long strings. |
| 11 | + + new `mod' (`%') operator | |
| 12 | + + new operation *t (for size of t) | |
| 13 | + + metatables for all types | |
| 11 | 14 | API: |
| 12 | 15 | + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer. |
| 13 | 16 | + user supplies memory allocator (lua_open becomes lua_newstate). |
| @@ -18,6 +21,7 @@ This is Lua 5.1 (work). · 4 unmodified lines | ||
| 18 | 21 | + fully reentrant parser (new Lua function `load') |
| 19 | 22 | + better support for 64-bit machines (special thanks to Mike Pall). |
| 20 | 23 | + native loadlib support for Mac OS X (thanks to Matthew Cox). |
| 24 | + + standard distribution in only one library (lualib.a merged into lua.a) | |
| 21 | 25 | |
| 22 | 26 | * Changes from version 4.0 to 5.0 |
| 23 | 27 | ------------------------------- |
| @@ -5,17 +5,20 @@ This is Lua 5.1 (work). · 4 unmodified lines | ||
| 5 | 5 | Building Lua on a Unix system should be very easy: simply doing "make" |
| 6 | 6 | should work. This will build Lua in the src directory. |
| 7 | 7 | |
| 8 | + See below for customization instructions. We strongly recommend that | |
| 9 | + you enable dynamic loading. | |
| 10 | + | |
| 8 | 11 | If you want to install Lua in an official place in your system, then |
| 9 | 12 | do "make install". The official place and the way to install files are |
| 10 | 13 | defined in Makefile. You must have the right permissions to install files. |
| 11 | 14 | |
| 12 | 15 | If you want to install Lua locally, then do "make local". This will |
| 13 | − create directories bin, include, lib, man and install Lua there as | |
| 16 | + create directories bin, include, lib, man, and install Lua there as | |
| 14 | 17 | follows: |
| 15 | 18 | |
| 16 | 19 | bin: lua luac |
| 17 | 20 | include: lua.h luaconf.h lualib.h lauxlib.h |
| 18 | − lib: liblua.a liblualib.a | |
| 21 | + lib: liblua.a | |
| 19 | 22 | man/man1: lua.1 luac.1 |
| 20 | 23 | |
| 21 | 24 | These are the only directories you need for development. |
| @@ -38,25 +41,23 @@ This is Lua 5.1 (work). · 16 unmodified lines | ||
| 38 | 41 | |
| 39 | 42 | On the other hand, if you need to select some Lua features, you'll need |
| 40 | 43 | to edit src/luaconf.h. The edited file will be the one installed, and |
| 41 | − will be used by any Lua clients that you build, to ensure consistency. | |
| 44 | + it will be used by any Lua clients that you build, to ensure consistency. | |
| 42 | 45 | |
| 43 | 46 | * Installation on Windows and other systems |
| 44 | 47 | ----------------------------------------- |
| 45 | 48 | The instructions for building Lua on other systems depend on the compiler |
| 46 | 49 | you use. You'll need to create projects (or whatever your compiler uses) |
| 47 | − for building the core library, the standard library, the interpreter, and | |
| 48 | − the compiler, as follows: | |
| 50 | + for building the library, the interpreter, and the compiler, as follows: | |
| 49 | 51 | |
| 50 | − core lib: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c | |
| 51 | − lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c | |
| 52 | + library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c | |
| 53 | + lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c | |
| 52 | 54 | ltable.c ltm.c lundump.c lvm.c lzio.c |
| 55 | + lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c | |
| 56 | + ltablib.c lstrlib.c loadlib.c linit.c | |
| 53 | 57 | |
| 54 | − standard lib: lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c | |
| 55 | − ltablib.c lstrlib.c loadlib.c linit.c | |
| 56 | − | |
| 57 | − interpreter: core lib, standard lib, lua.c | |
| 58 | + interpreter: library, lua.c | |
| 58 | 59 | |
| 59 | − compiler: core lib, lauxlib.c luac.c print.c | |
| 60 | + compiler: library, luac.c print.c | |
| 60 | 61 | |
| 61 | 62 | If all you want is to build the Lua interpreter, you may put all .c files |
| 62 | 63 | in a single project, except for luac.c and print.c. |
| @@ -1,105 +1,104 @@ | ||
| 1 | −MANIFEST contents of Lua 5.1 (work5) distribution on Fri Mar 4 13:32:55 BRST 2005 | |
| 2 | −lua-5.1-work5 | |
| 3 | −lua-5.1-work5/COPYRIGHT | |
| 4 | −lua-5.1-work5/HISTORY | |
| 5 | −lua-5.1-work5/INSTALL | |
| 6 | −lua-5.1-work5/MANIFEST | |
| 7 | −lua-5.1-work5/Makefile | |
| 8 | −lua-5.1-work5/README | |
| 9 | −lua-5.1-work5/doc | |
| 10 | −lua-5.1-work5/doc/contents.html | |
| 11 | −lua-5.1-work5/doc/logo.gif | |
| 12 | −lua-5.1-work5/doc/lua.1 | |
| 13 | −lua-5.1-work5/doc/lua.html | |
| 14 | −lua-5.1-work5/doc/luac.1 | |
| 15 | −lua-5.1-work5/doc/luac.html | |
| 16 | −lua-5.1-work5/doc/readme.html | |
| 17 | −lua-5.1-work5/etc | |
| 18 | −lua-5.1-work5/etc/Makefile | |
| 19 | −lua-5.1-work5/etc/README | |
| 20 | −lua-5.1-work5/etc/all.c | |
| 21 | −lua-5.1-work5/etc/lua.hpp | |
| 22 | −lua-5.1-work5/etc/lua.ico | |
| 23 | −lua-5.1-work5/etc/min.c | |
| 24 | −lua-5.1-work5/etc/noparser.c | |
| 25 | −lua-5.1-work5/etc/saconfig.c | |
| 26 | −lua-5.1-work5/src | |
| 27 | −lua-5.1-work5/src/Makefile | |
| 28 | −lua-5.1-work5/src/lapi.c | |
| 29 | −lua-5.1-work5/src/lapi.h | |
| 30 | −lua-5.1-work5/src/lauxlib.c | |
| 31 | −lua-5.1-work5/src/lauxlib.h | |
| 32 | −lua-5.1-work5/src/lbaselib.c | |
| 33 | −lua-5.1-work5/src/lcode.c | |
| 34 | −lua-5.1-work5/src/lcode.h | |
| 35 | −lua-5.1-work5/src/ldblib.c | |
| 36 | −lua-5.1-work5/src/ldebug.c | |
| 37 | −lua-5.1-work5/src/ldebug.h | |
| 38 | −lua-5.1-work5/src/ldo.c | |
| 39 | −lua-5.1-work5/src/ldo.h | |
| 40 | −lua-5.1-work5/src/ldump.c | |
| 41 | −lua-5.1-work5/src/lfunc.c | |
| 42 | −lua-5.1-work5/src/lfunc.h | |
| 43 | −lua-5.1-work5/src/lgc.c | |
| 44 | −lua-5.1-work5/src/lgc.h | |
| 45 | −lua-5.1-work5/src/linit.c | |
| 46 | −lua-5.1-work5/src/liolib.c | |
| 47 | −lua-5.1-work5/src/llex.c | |
| 48 | −lua-5.1-work5/src/llex.h | |
| 49 | −lua-5.1-work5/src/llimits.h | |
| 50 | −lua-5.1-work5/src/lmathlib.c | |
| 51 | −lua-5.1-work5/src/lmem.c | |
| 52 | −lua-5.1-work5/src/lmem.h | |
| 53 | −lua-5.1-work5/src/loadlib.c | |
| 54 | −lua-5.1-work5/src/lobject.c | |
| 55 | −lua-5.1-work5/src/lobject.h | |
| 56 | −lua-5.1-work5/src/lopcodes.c | |
| 57 | −lua-5.1-work5/src/lopcodes.h | |
| 58 | −lua-5.1-work5/src/loslib.c | |
| 59 | −lua-5.1-work5/src/lparser.c | |
| 60 | −lua-5.1-work5/src/lparser.h | |
| 61 | −lua-5.1-work5/src/lstate.c | |
| 62 | −lua-5.1-work5/src/lstate.h | |
| 63 | −lua-5.1-work5/src/lstring.c | |
| 64 | −lua-5.1-work5/src/lstring.h | |
| 65 | −lua-5.1-work5/src/lstrlib.c | |
| 66 | −lua-5.1-work5/src/ltable.c | |
| 67 | −lua-5.1-work5/src/ltable.h | |
| 68 | −lua-5.1-work5/src/ltablib.c | |
| 69 | −lua-5.1-work5/src/ltm.c | |
| 70 | −lua-5.1-work5/src/ltm.h | |
| 71 | −lua-5.1-work5/src/lua.c | |
| 72 | −lua-5.1-work5/src/lua.h | |
| 73 | −lua-5.1-work5/src/luac.c | |
| 74 | −lua-5.1-work5/src/luaconf.h | |
| 75 | −lua-5.1-work5/src/lualib.h | |
| 76 | −lua-5.1-work5/src/lundump.c | |
| 77 | −lua-5.1-work5/src/lundump.h | |
| 78 | −lua-5.1-work5/src/lvm.c | |
| 79 | −lua-5.1-work5/src/lvm.h | |
| 80 | −lua-5.1-work5/src/lzio.c | |
| 81 | −lua-5.1-work5/src/lzio.h | |
| 82 | −lua-5.1-work5/src/print.c | |
| 83 | −lua-5.1-work5/test | |
| 84 | −lua-5.1-work5/test/README | |
| 85 | −lua-5.1-work5/test/bisect.lua | |
| 86 | −lua-5.1-work5/test/cf.lua | |
| 87 | −lua-5.1-work5/test/echo.lua | |
| 88 | −lua-5.1-work5/test/env.lua | |
| 89 | −lua-5.1-work5/test/factorial.lua | |
| 90 | −lua-5.1-work5/test/fib.lua | |
| 91 | −lua-5.1-work5/test/fibfor.lua | |
| 92 | −lua-5.1-work5/test/globals.lua | |
| 93 | −lua-5.1-work5/test/hello.lua | |
| 94 | −lua-5.1-work5/test/life.lua | |
| 95 | −lua-5.1-work5/test/luac.lua | |
| 96 | −lua-5.1-work5/test/printf.lua | |
| 97 | −lua-5.1-work5/test/readonly.lua | |
| 98 | −lua-5.1-work5/test/sieve.lua | |
| 99 | −lua-5.1-work5/test/sort.lua | |
| 100 | −lua-5.1-work5/test/table.lua | |
| 101 | −lua-5.1-work5/test/trace-calls.lua | |
| 102 | −lua-5.1-work5/test/trace-globals.lua | |
| 103 | −lua-5.1-work5/test/undefined.lua | |
| 104 | −lua-5.1-work5/test/xd.lua | |
| 1 | +MANIFEST contents of Lua 5.1 (work6) distribution on Wed May 18 10:13:40 BRST 2005 | |
| 2 | +lua-5.1-work6 | |
| 3 | +lua-5.1-work6/COPYRIGHT | |
| 4 | +lua-5.1-work6/HISTORY | |
| 5 | +lua-5.1-work6/INSTALL | |
| 6 | +lua-5.1-work6/MANIFEST | |
| 7 | +lua-5.1-work6/Makefile | |
| 8 | +lua-5.1-work6/README | |
| 9 | +lua-5.1-work6/doc | |
| 10 | +lua-5.1-work6/doc/contents.html | |
| 11 | +lua-5.1-work6/doc/logo.gif | |
| 12 | +lua-5.1-work6/doc/lua.1 | |
| 13 | +lua-5.1-work6/doc/lua.html | |
| 14 | +lua-5.1-work6/doc/luac.1 | |
| 15 | +lua-5.1-work6/doc/luac.html | |
| 16 | +lua-5.1-work6/doc/readme.html | |
| 17 | +lua-5.1-work6/etc | |
| 18 | +lua-5.1-work6/etc/Makefile | |
| 19 | +lua-5.1-work6/etc/README | |
| 20 | +lua-5.1-work6/etc/all.c | |
| 21 | +lua-5.1-work6/etc/lua.hpp | |
| 22 | +lua-5.1-work6/etc/lua.ico | |
| 23 | +lua-5.1-work6/etc/lua.pc | |
| 24 | +lua-5.1-work6/etc/min.c | |
| 25 | +lua-5.1-work6/etc/noparser.c | |
| 26 | +lua-5.1-work6/src | |
| 27 | +lua-5.1-work6/src/Makefile | |
| 28 | +lua-5.1-work6/src/lapi.c | |
| 29 | +lua-5.1-work6/src/lapi.h | |
| 30 | +lua-5.1-work6/src/lauxlib.c | |
| 31 | +lua-5.1-work6/src/lauxlib.h | |
| 32 | +lua-5.1-work6/src/lbaselib.c | |
| 33 | +lua-5.1-work6/src/lcode.c | |
| 34 | +lua-5.1-work6/src/lcode.h | |
| 35 | +lua-5.1-work6/src/ldblib.c | |
| 36 | +lua-5.1-work6/src/ldebug.c | |
| 37 | +lua-5.1-work6/src/ldebug.h | |
| 38 | +lua-5.1-work6/src/ldo.c | |
| 39 | +lua-5.1-work6/src/ldo.h | |
| 40 | +lua-5.1-work6/src/ldump.c | |
| 41 | +lua-5.1-work6/src/lfunc.c | |
| 42 | +lua-5.1-work6/src/lfunc.h | |
| 43 | +lua-5.1-work6/src/lgc.c | |
| 44 | +lua-5.1-work6/src/lgc.h | |
| 45 | +lua-5.1-work6/src/linit.c | |
| 46 | +lua-5.1-work6/src/liolib.c | |
| 47 | +lua-5.1-work6/src/llex.c | |
| 48 | +lua-5.1-work6/src/llex.h | |
| 49 | +lua-5.1-work6/src/llimits.h | |
| 50 | +lua-5.1-work6/src/lmathlib.c | |
| 51 | +lua-5.1-work6/src/lmem.c | |
| 52 | +lua-5.1-work6/src/lmem.h | |
| 53 | +lua-5.1-work6/src/loadlib.c | |
| 54 | +lua-5.1-work6/src/lobject.c | |
| 55 | +lua-5.1-work6/src/lobject.h | |
| 56 | +lua-5.1-work6/src/lopcodes.c | |
| 57 | +lua-5.1-work6/src/lopcodes.h | |
| 58 | +lua-5.1-work6/src/loslib.c | |
| 59 | +lua-5.1-work6/src/lparser.c | |
| 60 | +lua-5.1-work6/src/lparser.h | |
| 61 | +lua-5.1-work6/src/lstate.c | |
| 62 | +lua-5.1-work6/src/lstate.h | |
| 63 | +lua-5.1-work6/src/lstring.c | |
| 64 | +lua-5.1-work6/src/lstring.h | |
| 65 | +lua-5.1-work6/src/lstrlib.c | |
| 66 | +lua-5.1-work6/src/ltable.c | |
| 67 | +lua-5.1-work6/src/ltable.h | |
| 68 | +lua-5.1-work6/src/ltablib.c | |
| 69 | +lua-5.1-work6/src/ltm.c | |
| 70 | +lua-5.1-work6/src/ltm.h | |
| 71 | +lua-5.1-work6/src/lua.c | |
| 72 | +lua-5.1-work6/src/lua.h | |
| 73 | +lua-5.1-work6/src/luac.c | |
| 74 | +lua-5.1-work6/src/luaconf.h | |
| 75 | +lua-5.1-work6/src/lualib.h | |
| 76 | +lua-5.1-work6/src/lundump.c | |
| 77 | +lua-5.1-work6/src/lundump.h | |
| 78 | +lua-5.1-work6/src/lvm.c | |
| 79 | +lua-5.1-work6/src/lvm.h | |
| 80 | +lua-5.1-work6/src/lzio.c | |
| 81 | +lua-5.1-work6/src/lzio.h | |
| 82 | +lua-5.1-work6/src/print.c | |
| 83 | +lua-5.1-work6/test | |
| 84 | +lua-5.1-work6/test/README | |
| 85 | +lua-5.1-work6/test/bisect.lua | |
| 86 | +lua-5.1-work6/test/cf.lua | |
| 87 | +lua-5.1-work6/test/echo.lua | |
| 88 | +lua-5.1-work6/test/env.lua | |
| 89 | +lua-5.1-work6/test/factorial.lua | |
| 90 | +lua-5.1-work6/test/fib.lua | |
| 91 | +lua-5.1-work6/test/fibfor.lua | |
| 92 | +lua-5.1-work6/test/globals.lua | |
| 93 | +lua-5.1-work6/test/hello.lua | |
| 94 | +lua-5.1-work6/test/life.lua | |
| 95 | +lua-5.1-work6/test/luac.lua | |
| 96 | +lua-5.1-work6/test/printf.lua | |
| 97 | +lua-5.1-work6/test/readonly.lua | |
| 98 | +lua-5.1-work6/test/sieve.lua | |
| 99 | +lua-5.1-work6/test/sort.lua | |
| 100 | +lua-5.1-work6/test/table.lua | |
| 101 | +lua-5.1-work6/test/trace-calls.lua | |
| 102 | +lua-5.1-work6/test/trace-globals.lua | |
| 103 | +lua-5.1-work6/test/xd.lua | |
| 105 | 104 | END OF MANIFEST |
| @@ -4,8 +4,9 @@ · 3 unmodified lines | ||
| 4 | 4 | |
| 5 | 5 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= |
| 6 | 6 | |
| 7 | −# Where to install. The installation starts in the src directory, so take | |
| 8 | −# care if INSTALL_TOP is not an absolute path. | |
| 7 | +# Where to install. The installation starts in the src directory, so take care | |
| 8 | +# if INSTALL_TOP is not an absolute path. (Man pages are installed from the | |
| 9 | +# doc directory.) | |
| 9 | 10 | # |
| 10 | 11 | INSTALL_TOP= /usr/local |
| 11 | 12 | INSTALL_BIN= $(INSTALL_TOP)/bin |
| @@ -23,13 +24,15 @@ INSTALL_DATA= cp · 11 unmodified lines | ||
| 23 | 24 | |
| 24 | 25 | # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= |
| 25 | 26 | |
| 26 | −V= 5.1 | |
| 27 | − | |
| 27 | +# What to install. | |
| 28 | 28 | TO_BIN= lua luac |
| 29 | 29 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h |
| 30 | −TO_LIB= liblua.a liblualib.a | |
| 30 | +TO_LIB= liblua.a | |
| 31 | 31 | TO_MAN= lua.1 luac.1 |
| 32 | 32 | |
| 33 | +# Lua version. Currently used only for messages. | |
| 34 | +V= 5.1 | |
| 35 | + | |
| 33 | 36 | all clean: |
| 34 | 37 | cd src; $(MAKE) $@ |
| 35 | 38 | |
| @@ -66,6 +69,14 @@ echo: · 30 unmodified lines | ||
| 66 | 69 | @echo "See also src/luaconf.h ." |
| 67 | 70 | @echo "" |
| 68 | 71 | |
| 72 | +# echo private config parameters | |
| 73 | +pecho: | |
| 74 | + @echo "V = $(V)" | |
| 75 | + @echo "TO_BIN = $(TO_BIN)" | |
| 76 | + @echo "TO_INC = $(TO_INC)" | |
| 77 | + @echo "TO_LIB = $(TO_LIB)" | |
| 78 | + @echo "TO_MAN = $(TO_MAN)" | |
| 79 | + | |
| 69 | 80 | # echo config parameters as Lua code |
| 70 | 81 | # uncomment the last sed expression if you want nil instead of empty strings |
| 71 | 82 | lecho: |
| @@ -20,10 +20,10 @@ all: · 19 unmodified lines | ||
| 20 | 20 | @echo 'choose a target:' $(ALL) |
| 21 | 21 | |
| 22 | 22 | min: min.c |
| 23 | − $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib | |
| 23 | + $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua $(MYLIBS) | |
| 24 | 24 | |
| 25 | 25 | noparser: noparser.o |
| 26 | − $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua -llualib $(MYLIBS) | |
| 26 | + $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS) | |
| 27 | 27 | $(BIN)/luac $(TST)/hello.lua |
| 28 | 28 | -./a.out luac.out |
| 29 | 29 | -./a.out -e'a=1' |
| @@ -13,6 +13,9 @@ lua.ico · 12 unmodified lines | ||
| 13 | 13 | A Lua icon for Windows (and web sites, as favicon.ico). |
| 14 | 14 | Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>. |
| 15 | 15 | |
| 16 | +lua.pc | |
| 17 | + pkg-config data for Lua | |
| 18 | + | |
| 16 | 19 | min.c |
| 17 | 20 | A minimal Lua interpreter. |
| 18 | 21 | Good for learning and for starting your own. |
| @@ -20,6 +23,3 @@ min.c · 1 unmodified line | ||
| 20 | 23 | noparser.c |
| 21 | 24 | Linking with noparser.o avoids loading the parsing modules in lualib.a. |
| 22 | 25 | Do "make noparser" to see a demo. |
| 23 | − | |
| 24 | −saconfig.c | |
| 25 | − Configuration for Lua interpreter. | |
| @@ -2,9 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | * all.c -- Lua core, libraries and interpreter in a single file |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | −#define LUA_CORE | |
| 6 | −#define LUA_LIB | |
| 7 | −#define lua_c | |
| 5 | +#define luaall_c | |
| 8 | 6 | |
| 9 | 7 | #include "lapi.c" |
| 10 | 8 | #include "lcode.c" |
| @@ -0,0 +1,24 @@ | ||
| 1 | +# lua.pc -- pkg-config data for Lua | |
| 2 | + | |
| 3 | +# vars from install Makefile | |
| 4 | +# grep ^INSTALL_...= ../Makefile | |
| 5 | +INSTALL_TOP= /usr/local | |
| 6 | +INSTALL_BIN= $(INSTALL_TOP)/bin | |
| 7 | +INSTALL_INC= $(INSTALL_TOP)/include | |
| 8 | +INSTALL_LIB= $(INSTALL_TOP)/lib | |
| 9 | +INSTALL_MAN= $(INSTALL_TOP)/man/man1 | |
| 10 | +# grep ^V= ../Makefile | |
| 11 | +V= 5.1 | |
| 12 | + | |
| 13 | +prefix=${INSTALL_TOP} | |
| 14 | +exec_prefix=${prefix} | |
| 15 | +libdir=${exec_prefix}/lib | |
| 16 | +includedir=${prefix}/include | |
| 17 | + | |
| 18 | +Name: Lua | |
| 19 | +Description: An Extensible Extension Language | |
| 20 | +Version: ${V} | |
| 21 | +Requires: | |
| 22 | +Libs: -L${libdir} -llua -lm | |
| 23 | +Cflags: -I${includedir} | |
| 24 | + | |
| @@ -1,65 +0,0 @@ | ||
| 1 | −/* saconfig.c -- configuration for stand-alone Lua interpreter | |
| 2 | −* | |
| 3 | −* #define LUA_USERCONFIG to this file | |
| 4 | −* | |
| 5 | −* Here are the features that can be customized using #define: | |
| 6 | −* | |
| 7 | −*** Line editing and history: | |
| 8 | −* #define USE_READLINE to use the GNU readline library. | |
| 9 | −* Add "-lreadline -ltermcap" to MYLIBS. | |
| 10 | −* | |
| 11 | −* To use another library for this, use the code below as a start. | |
| 12 | −* Make sure you #define lua_readline and lua_saveline accordingly. | |
| 13 | −* | |
| 14 | −* If you do not #define lua_readline, you'll get a version based on fgets | |
| 15 | −* that uses a static buffer of size MAXINPUT. | |
| 16 | −*/ | |
| 17 | − | |
| 18 | −#define USE_READLINE | |
| 19 | − | |
| 20 | −#ifdef USE_READLINE | |
| 21 | −/* | |
| 22 | −* This section implements of lua_readline and lua_saveline for lua.c using | |
| 23 | −* the GNU readline and history libraries. It should also work with drop-in | |
| 24 | −* replacements such as editline and libedit (you may have to include | |
| 25 | −* different headers, though). | |
| 26 | −* | |
| 27 | −*/ | |
| 28 | − | |
| 29 | −#define lua_readline myreadline | |
| 30 | −#define lua_saveline mysaveline | |
| 31 | − | |
| 32 | −#include <ctype.h> | |
| 33 | −#include <readline/readline.h> | |
| 34 | −#include <readline/history.h> | |
| 35 | − | |
| 36 | −static int myreadline (lua_State *L, const char *prompt) { | |
| 37 | − char *s=readline(prompt); | |
| 38 | − if (s==NULL) | |
| 39 | − return 0; | |
| 40 | − else { | |
| 41 | − lua_pushstring(L,s); | |
| 42 | − lua_pushliteral(L,"\n"); | |
| 43 | − lua_concat(L,2); | |
| 44 | − free(s); | |
| 45 | − return 1; | |
| 46 | − } | |
| 47 | −} | |
| 48 | − | |
| 49 | −static void mysaveline (lua_State *L, const char *s) { | |
| 50 | − const char *p; | |
| 51 | − for (p=s; isspace(*p); p++) | |
| 52 | − ; | |
| 53 | − if (*p!=0) { | |
| 54 | − size_t n=strlen(s)-1; | |
| 55 | − if (s[n]!='\n') | |
| 56 | − add_history(s); | |
| 57 | − else { | |
| 58 | − lua_pushlstring(L,s,n); | |
| 59 | − s=lua_tostring(L,-1); | |
| 60 | − add_history(s); | |
| 61 | − lua_remove(L,-1); | |
| 62 | − } | |
| 63 | − } | |
| 64 | −} | |
| 65 | −#endif | |
| @@ -9,20 +9,21 @@ CFLAGS= -O2 -Wall $(MYCFLAGS) · 8 unmodified lines | ||
| 9 | 9 | AR= ar rcu |
| 10 | 10 | RANLIB= ranlib |
| 11 | 11 | RM= rm -f |
| 12 | +LIBS= -lm $(MYLIBS) | |
| 12 | 13 | |
| 13 | 14 | MYCFLAGS= |
| 14 | 15 | MYLDFLAGS= |
| 15 | −MYLIBS= -lm | |
| 16 | −DL= -ldl -Wl,-E # enable dynamic loading in Linux | |
| 16 | +MYLIBS= | |
| 17 | +# enable dynamic loading and line editing in Linux | |
| 18 | +# MYCFLAGS= -DLUA_USE_DLOPEN -DLUA_USE_READLINE | |
| 19 | +# MYLIBS= -Wl,-E -ldl -lreadline -lhistory -lncurses | |
| 17 | 20 | |
| 18 | 21 | # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= |
| 19 | 22 | |
| 20 | −CORE_T= liblua.a | |
| 23 | +LUA_A= liblua.a | |
| 21 | 24 | CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ |
| 22 | 25 | lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ |
| 23 | 26 | lundump.o lvm.o lzio.o |
| 24 | − | |
| 25 | −LIB_T= liblualib.a | |
| 26 | 27 | LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \ |
| 27 | 28 | lstrlib.o loadlib.o linit.o |
| 28 | 29 | |
| @@ -30,11 +31,11 @@ LUA_T= lua · 1 unmodified line | ||
| 30 | 31 | LUA_O= lua.o |
| 31 | 32 | |
| 32 | 33 | LUAC_T= luac |
| 33 | −LUAC_O= luac.o print.o lauxlib.o | |
| 34 | +LUAC_O= luac.o print.o | |
| 34 | 35 | |
| 35 | −ALL_T= $(CORE_T) $(LIB_T) $(LUA_T) $(LUAC_T) | |
| 36 | 36 | ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) |
| 37 | −ALL_A= $(CORE_T) $(LIB_T) | |
| 37 | +ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) | |
| 38 | +ALL_A= $(LUA_A) | |
| 38 | 39 | |
| 39 | 40 | all: $(ALL_T) |
| 40 | 41 | |
| @@ -42,25 +43,21 @@ o: $(ALL_O) · 1 unmodified line | ||
| 42 | 43 | |
| 43 | 44 | a: $(ALL_A) |
| 44 | 45 | |
| 45 | −$(CORE_T): $(CORE_O) | |
| 46 | − $(AR) $@ $? | |
| 47 | − $(RANLIB) $@ | |
| 48 | − | |
| 49 | −$(LIB_T): $(LIB_O) | |
| 46 | +$(LUA_A): $(CORE_O) $(LIB_O) | |
| 50 | 47 | $(AR) $@ $? |
| 51 | 48 | $(RANLIB) $@ |
| 52 | 49 | |
| 53 | −$(LUA_T): $(LUA_O) $(CORE_T) $(LIB_T) | |
| 54 | − $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) -L. -llua -llualib $(MYLIBS) $(DL) | |
| 50 | +$(LUA_T): $(LUA_O) $(LUA_A) | |
| 51 | + $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) | |
| 55 | 52 | |
| 56 | −$(LUAC_T): $(LUAC_O) $(CORE_T) | |
| 57 | − $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) -L. -llua $(MYLIBS) | |
| 53 | +$(LUAC_T): $(LUAC_O) $(LUA_A) | |
| 54 | + $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) | |
| 58 | 55 | |
| 59 | 56 | clean: |
| 60 | 57 | $(RM) $(ALL_T) $(ALL_O) |
| 61 | 58 | |
| 62 | 59 | depend: |
| 63 | − @$(CC) $(CFLAGS) -MM *.c | |
| 60 | + @$(CC) $(CFLAGS) -MM l*.c print.c | |
| 64 | 61 | |
| 65 | 62 | echo: |
| 66 | 63 | @echo "CC = $(CC)" |
| @@ -71,7 +68,6 @@ echo: · 4 unmodified lines | ||
| 71 | 68 | @echo "MYCFLAGS = $(MYCFLAGS)" |
| 72 | 69 | @echo "MYLDFLAGS = $(MYLDFLAGS)" |
| 73 | 70 | @echo "MYLIBS = $(MYLIBS)" |
| 74 | − @echo "DL = $(DL)" | |
| 75 | 71 | |
| 76 | 72 | # DO NOT DELETE |
| 77 | 73 | |
| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lapi.c,v 2.28 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lapi.c,v 2.41 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lua API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | #include <assert.h> |
| 9 | +#include <math.h> | |
| 9 | 10 | #include <stdarg.h> |
| 10 | 11 | #include <string.h> |
| 11 | 12 | |
| @@ -87,14 +88,14 @@ static Table *getcurrenv (lua_State *L) { · 75 unmodified lines | ||
| 87 | 88 | |
| 88 | 89 | void luaA_pushobject (lua_State *L, const TValue *o) { |
| 89 | 90 | setobj2s(L, L->top, o); |
| 90 | − incr_top(L); | |
| 91 | + api_incr_top(L); | |
| 91 | 92 | } |
| 92 | 93 | |
| 93 | 94 | |
| 94 | 95 | LUA_API int lua_checkstack (lua_State *L, int size) { |
| 95 | 96 | int res; |
| 96 | 97 | lua_lock(L); |
| 97 | − if ((L->top - L->base + size) > MAXCSTACK) | |
| 98 | + if ((L->top - L->base + size) > LUAI_MAXCSTACK) | |
| 98 | 99 | res = 0; /* stack overflow */ |
| 99 | 100 | else { |
| 100 | 101 | luaD_checkstack(L, size); |
| @@ -140,7 +141,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 39 unmodified lines | ||
| 140 | 141 | setthvalue(L, L->top, L1); |
| 141 | 142 | api_incr_top(L); |
| 142 | 143 | lua_unlock(L); |
| 143 | − lua_userstateopen(L1); | |
| 144 | + luai_userstateopen(L1); | |
| 144 | 145 | return L1; |
| 145 | 146 | } |
| 146 | 147 | |
| @@ -318,7 +319,8 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { · 171 unmodified lines | ||
| 318 | 319 | const TValue *o = index2adr(L, idx); |
| 319 | 320 | if (tonumber(o, &n)) { |
| 320 | 321 | lua_Integer res; |
| 321 | − lua_number2integer(res, nvalue(o)); | |
| 322 | + lua_Number num = nvalue(o); | |
| 323 | + lua_number2integer(res, num); | |
| 322 | 324 | return res; |
| 323 | 325 | } |
| 324 | 326 | else |
| @@ -332,33 +334,37 @@ LUA_API int lua_toboolean (lua_State *L, int idx) { · 7 unmodified lines | ||
| 332 | 334 | } |
| 333 | 335 | |
| 334 | 336 | |
| 335 | −LUA_API const char *lua_tostring (lua_State *L, int idx) { | |
| 337 | +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |
| 336 | 338 | StkId o = index2adr(L, idx); |
| 337 | − if (ttisstring(o)) | |
| 338 | − return svalue(o); | |
| 339 | − else { | |
| 340 | − const char *s; | |
| 339 | + if (!ttisstring(o)) { | |
| 341 | 340 | lua_lock(L); /* `luaV_tostring' may create a new string */ |
| 342 | − s = (luaV_tostring(L, o) ? svalue(o) : NULL); | |
| 341 | + if (!luaV_tostring(L, o)) { /* conversion failed? */ | |
| 342 | + if (len != NULL) *len = 0; | |
| 343 | + lua_unlock(L); | |
| 344 | + return NULL; | |
| 345 | + } | |
| 343 | 346 | luaC_checkGC(L); |
| 344 | 347 | lua_unlock(L); |
| 345 | − return s; | |
| 346 | 348 | } |
| 349 | + if (len != NULL) *len = tsvalue(o)->len; | |
| 350 | + return svalue(o); | |
| 347 | 351 | } |
| 348 | 352 | |
| 349 | 353 | |
| 350 | 354 | LUA_API size_t lua_objsize (lua_State *L, int idx) { |
| 351 | 355 | StkId o = index2adr(L, idx); |
| 352 | − if (ttisstring(o)) | |
| 353 | − return tsvalue(o)->len; | |
| 354 | − else if (ttisuserdata(o)) | |
| 355 | − return uvalue(o)->len; | |
| 356 | − else { | |
| 357 | − size_t l; | |
| 358 | − lua_lock(L); /* `luaV_tostring' may create a new string */ | |
| 359 | − l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); | |
| 360 | − lua_unlock(L); | |
| 361 | − return l; | |
| 356 | + switch (ttype(o)) { | |
| 357 | + case LUA_TSTRING: return tsvalue(o)->len; | |
| 358 | + case LUA_TUSERDATA: return uvalue(o)->len; | |
| 359 | + case LUA_TTABLE: return luaH_getn(hvalue(o)); | |
| 360 | + case LUA_TNUMBER: { | |
| 361 | + size_t l; | |
| 362 | + lua_lock(L); /* `luaV_tostring' may create a new string */ | |
| 363 | + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); | |
| 364 | + lua_unlock(L); | |
| 365 | + return l; | |
| 366 | + } | |
| 367 | + default: return 0; | |
| 362 | 368 | } |
| 363 | 369 | } |
| 364 | 370 | |
| @@ -523,7 +529,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) { · 158 unmodified lines | ||
| 523 | 529 | lua_lock(L); |
| 524 | 530 | t = index2adr(L, idx); |
| 525 | 531 | api_checkvalidindex(L, t); |
| 526 | − luaV_gettable(L, t, L->top - 1, L->top - 1, NULL); | |
| 532 | + luaV_gettable(L, t, L->top - 1, L->top - 1); | |
| 527 | 533 | lua_unlock(L); |
| 528 | 534 | } |
| 529 | 535 | |
| @@ -535,7 +541,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { · 5 unmodified lines | ||
| 535 | 541 | t = index2adr(L, idx); |
| 536 | 542 | api_checkvalidindex(L, t); |
| 537 | 543 | setsvalue(L, &key, luaS_new(L, k)); |
| 538 | − luaV_gettable(L, t, &key, L->top, NULL); | |
| 544 | + luaV_gettable(L, t, &key, L->top); | |
| 539 | 545 | api_incr_top(L); |
| 540 | 546 | lua_unlock(L); |
| 541 | 547 | } |
| @@ -584,6 +590,9 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { · 42 unmodified lines | ||
| 584 | 590 | case LUA_TUSERDATA: |
| 585 | 591 | mt = uvalue(obj)->metatable; |
| 586 | 592 | break; |
| 593 | + default: | |
| 594 | + mt = G(L)->mt[ttype(obj)]; | |
| 595 | + break; | |
| 587 | 596 | } |
| 588 | 597 | if (mt == NULL) |
| 589 | 598 | res = 0; |
| @@ -629,7 +638,7 @@ LUA_API void lua_settable (lua_State *L, int idx) { · 39 unmodified lines | ||
| 629 | 638 | api_checknelems(L, 2); |
| 630 | 639 | t = index2adr(L, idx); |
| 631 | 640 | api_checkvalidindex(L, t); |
| 632 | − luaV_settable(L, t, L->top - 2, L->top - 1, NULL); | |
| 641 | + luaV_settable(L, t, L->top - 2, L->top - 1); | |
| 633 | 642 | L->top -= 2; /* pop index and value */ |
| 634 | 643 | lua_unlock(L); |
| 635 | 644 | } |
| @@ -643,7 +652,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { · 7 unmodified lines | ||
| 643 | 652 | t = index2adr(L, idx); |
| 644 | 653 | api_checkvalidindex(L, t); |
| 645 | 654 | setsvalue(L, &key, luaS_new(L, k)); |
| 646 | − luaV_settable(L, t, &key, L->top - 1, NULL); | |
| 655 | + luaV_settable(L, t, &key, L->top - 1); | |
| 647 | 656 | L->top--; /* pop value */ |
| 648 | 657 | lua_unlock(L); |
| 649 | 658 | } |
| @@ -678,7 +687,6 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { · 28 unmodified lines | ||
| 678 | 687 | LUA_API int lua_setmetatable (lua_State *L, int objindex) { |
| 679 | 688 | TValue *obj; |
| 680 | 689 | Table *mt; |
| 681 | − int res = 1; | |
| 682 | 690 | lua_lock(L); |
| 683 | 691 | api_checknelems(L, 1); |
| 684 | 692 | obj = index2adr(L, objindex); |
| @@ -703,13 +711,13 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { · 18 unmodified lines | ||
| 703 | 711 | break; |
| 704 | 712 | } |
| 705 | 713 | default: { |
| 706 | − res = 0; /* cannot set */ | |
| 714 | + G(L)->mt[ttype(obj)] = mt; | |
| 707 | 715 | break; |
| 708 | 716 | } |
| 709 | 717 | } |
| 710 | 718 | L->top--; |
| 711 | 719 | lua_unlock(L); |
| 712 | − return res; | |
| 720 | + return 1; | |
| 713 | 721 | } |
| 714 | 722 | |
| 715 | 723 | |
| @@ -819,9 +827,9 @@ static void f_Ccall (lua_State *L, void *ud) { · 103 unmodified lines | ||
| 819 | 827 | cl = luaF_newCclosure(L, 0, getcurrenv(L)); |
| 820 | 828 | cl->c.f = c->func; |
| 821 | 829 | setclvalue(L, L->top, cl); /* push function */ |
| 822 | − incr_top(L); | |
| 830 | + api_incr_top(L); | |
| 823 | 831 | setpvalue(L->top, c->ud); /* push only argument */ |
| 824 | − incr_top(L); | |
| 832 | + api_incr_top(L); | |
| 825 | 833 | luaD_call(L, L->top - 2, 0); |
| 826 | 834 | } |
| 827 | 835 | |
| @@ -838,7 +846,7 @@ LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { · 10 unmodified lines | ||
| 838 | 846 | } |
| 839 | 847 | |
| 840 | 848 | |
| 841 | −LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data, | |
| 849 | +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |
| 842 | 850 | const char *chunkname) { |
| 843 | 851 | ZIO z; |
| 844 | 852 | int status; |
| @@ -851,7 +859,7 @@ LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data, · 6 unmodified lines | ||
| 851 | 859 | } |
| 852 | 860 | |
| 853 | 861 | |
| 854 | −LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) { | |
| 862 | +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { | |
| 855 | 863 | int status; |
| 856 | 864 | TValue *o; |
| 857 | 865 | lua_lock(L); |
| @@ -904,12 +912,15 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 46 unmodified lines | ||
| 904 | 912 | g->GCthreshold = g->totalbytes - a; |
| 905 | 913 | else |
| 906 | 914 | g->GCthreshold = 0; |
| 907 | − luaC_step(L); | |
| 915 | + while (g->GCthreshold <= g->totalbytes) | |
| 916 | + luaC_step(L); | |
| 917 | + if (g->gcstate == GCSpause) /* end of cycle? */ | |
| 918 | + res = 1; /* signal it */ | |
| 908 | 919 | break; |
| 909 | 920 | } |
| 910 | − case LUA_GCSETPACE: { | |
| 911 | − res = g->gcpace; | |
| 912 | − g->gcpace = data; | |
| 921 | + case LUA_GCSETPAUSE: { | |
| 922 | + res = g->gcpause; | |
| 923 | + g->gcpause = data; | |
| 913 | 924 | break; |
| 914 | 925 | } |
| 915 | 926 | case LUA_GCSETSTEPMUL: { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lapi.h,v 2.1 2003/12/10 12:13:36 roberto Exp $ | |
| 2 | +** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions from Lua API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -11,6 +11,6 @@ · 5 unmodified lines | ||
| 11 | 11 | #include "lobject.h" |
| 12 | 12 | |
| 13 | 13 | |
| 14 | −void luaA_pushobject (lua_State *L, const TValue *o); | |
| 14 | +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); | |
| 15 | 15 | |
| 16 | 16 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lauxlib.c,v 1.129 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lauxlib.c,v 1.133 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -25,12 +25,7 @@ · 19 unmodified lines | ||
| 25 | 25 | #include "lauxlib.h" |
| 26 | 26 | |
| 27 | 27 | |
| 28 | −/* number of prereserved references (for internal use) */ | |
| 29 | −#define RESERVED_REFS 2 | |
| 30 | − | |
| 31 | −/* reserved references */ | |
| 32 | −#define FREELIST_REF 1 /* free list of references */ | |
| 33 | −#define ARRAYSIZE_REF 2 /* array sizes */ | |
| 28 | +#define FREELIST_REF 0 /* free list of references */ | |
| 34 | 29 | |
| 35 | 30 | |
| 36 | 31 | /* convert a stack index to positive */ |
| @@ -52,11 +47,12 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { · 15 unmodified lines | ||
| 52 | 47 | if (strcmp(ar.namewhat, "method") == 0) { |
| 53 | 48 | narg--; /* do not count `self' */ |
| 54 | 49 | if (narg == 0) /* error is in the self argument itself? */ |
| 55 | − return luaL_error(L, "calling `%s' on bad self (%s)", ar.name, extramsg); | |
| 50 | + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", | |
| 51 | + ar.name, extramsg); | |
| 56 | 52 | } |
| 57 | 53 | if (ar.name == NULL) |
| 58 | 54 | ar.name = "?"; |
| 59 | − return luaL_error(L, "bad argument #%d to `%s' (%s)", | |
| 55 | + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", | |
| 60 | 56 | narg, ar.name, extramsg); |
| 61 | 57 | } |
| 62 | 58 | |
| @@ -163,9 +159,8 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) { · 100 unmodified lines | ||
| 163 | 159 | |
| 164 | 160 | |
| 165 | 161 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { |
| 166 | − const char *s = lua_tostring(L, narg); | |
| 162 | + const char *s = lua_tolstring(L, narg, len); | |
| 167 | 163 | if (!s) tag_error(L, narg, LUA_TSTRING); |
| 168 | − if (len) *len = lua_strlen(L, narg); | |
| 169 | 164 | return s; |
| 170 | 165 | } |
| 171 | 166 | |
| @@ -250,7 +245,7 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, · 78 unmodified lines | ||
| 250 | 245 | luaL_setfield(L, LUA_GLOBALSINDEX, libname); |
| 251 | 246 | } |
| 252 | 247 | else if (!lua_istable(L, -1)) |
| 253 | − luaL_error(L, "name conflict for library `%s'", libname); | |
| 248 | + luaL_error(L, "name conflict for library " LUA_QS, libname); | |
| 254 | 249 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 255 | 250 | lua_pushvalue(L, -2); |
| 256 | 251 | lua_setfield(L, -2, libname); /* _LOADED[modname] = new table */ |
| @@ -275,6 +270,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, · 18 unmodified lines | ||
| 275 | 270 | ** ======================================================= |
| 276 | 271 | */ |
| 277 | 272 | |
| 273 | +#ifndef luaL_getn | |
| 274 | + | |
| 278 | 275 | static int checkint (lua_State *L, int topop) { |
| 279 | 276 | int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; |
| 280 | 277 | lua_pop(L, topop); |
| @@ -283,7 +280,7 @@ static int checkint (lua_State *L, int topop) { · 2 unmodified lines | ||
| 283 | 280 | |
| 284 | 281 | |
| 285 | 282 | static void getsizes (lua_State *L) { |
| 286 | − lua_rawgeti(L, LUA_REGISTRYINDEX, ARRAYSIZE_REF); | |
| 283 | + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); | |
| 287 | 284 | if (lua_isnil(L, -1)) { /* no `size' table? */ |
| 288 | 285 | lua_pop(L, 1); /* remove nil */ |
| 289 | 286 | lua_newtable(L); /* create it */ |
| @@ -292,7 +289,7 @@ static void getsizes (lua_State *L) { · 2 unmodified lines | ||
| 292 | 289 | lua_pushliteral(L, "kv"); |
| 293 | 290 | lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ |
| 294 | 291 | lua_pushvalue(L, -1); |
| 295 | − lua_rawseti(L, LUA_REGISTRYINDEX, ARRAYSIZE_REF); /* store in register */ | |
| 292 | + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ | |
| 296 | 293 | } |
| 297 | 294 | } |
| 298 | 295 | |
| @@ -307,31 +304,6 @@ LUALIB_API void luaL_setn (lua_State *L, int t, int n) { · 8 unmodified lines | ||
| 307 | 304 | } |
| 308 | 305 | |
| 309 | 306 | |
| 310 | −/* find an `n' such that t[n] ~= nil and t[n+1] == nil */ | |
| 311 | −static int countn (lua_State *L, int t) { | |
| 312 | − int i = LUA_FIRSTINDEX - 1; | |
| 313 | − int j = 2; | |
| 314 | − /* find `i' such that i <= n < i*2 (= j) */ | |
| 315 | − for (;;) { | |
| 316 | − lua_rawgeti(L, t, j); | |
| 317 | − if (lua_isnil(L, -1)) break; | |
| 318 | − lua_pop(L, 1); | |
| 319 | − i = j; | |
| 320 | − j = i*2; | |
| 321 | − } | |
| 322 | − lua_pop(L, 1); | |
| 323 | − /* i <= n < j; do a binary search */ | |
| 324 | − while (i < j-1) { | |
| 325 | − int m = (i+j)/2; | |
| 326 | − lua_rawgeti(L, t, m); | |
| 327 | − if (lua_isnil(L, -1)) j = m; | |
| 328 | − else i = m; | |
| 329 | − lua_pop(L, 1); | |
| 330 | − } | |
| 331 | − return i - LUA_FIRSTINDEX + 1; | |
| 332 | −} | |
| 333 | − | |
| 334 | − | |
| 335 | 307 | LUALIB_API int luaL_getn (lua_State *L, int t) { |
| 336 | 308 | int n; |
| 337 | 309 | t = abs_index(L, t); |
| @@ -341,9 +313,11 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { · 3 unmodified lines | ||
| 341 | 313 | if ((n = checkint(L, 2)) >= 0) return n; |
| 342 | 314 | lua_getfield(L, t, "n"); /* else try t.n */ |
| 343 | 315 | if ((n = checkint(L, 1)) >= 0) return n; |
| 344 | − return countn(L, t); | |
| 316 | + return lua_objsize(L, t); | |
| 345 | 317 | } |
| 346 | 318 | |
| 319 | +#endif | |
| 320 | + | |
| 347 | 321 | /* }====================================================== */ |
| 348 | 322 | |
| 349 | 323 | |
| @@ -392,7 +366,8 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, · 42 unmodified lines | ||
| 392 | 366 | for (;;) { |
| 393 | 367 | const char *fname; |
| 394 | 368 | if ((p = pushnexttemplate(L, p)) == NULL) { |
| 395 | − lua_pushfstring(L, "no readable `%s' in path `%s'", name, path); | |
| 369 | + lua_pushfstring(L, "no readable " LUA_QS " in path " LUA_QS "", | |
| 370 | + name, path); | |
| 396 | 371 | return NULL; |
| 397 | 372 | } |
| 398 | 373 | fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); |
| @@ -523,9 +498,10 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) { · 124 unmodified lines | ||
| 523 | 498 | |
| 524 | 499 | LUALIB_API void luaL_addvalue (luaL_Buffer *B) { |
| 525 | 500 | lua_State *L = B->L; |
| 526 | − size_t vl = lua_strlen(L, -1); | |
| 501 | + size_t vl; | |
| 502 | + const char *s = lua_tolstring(L, -1, &vl); | |
| 527 | 503 | if (vl <= bufffree(B)) { /* fit into buffer? */ |
| 528 | − memcpy(B->p, lua_tostring(L, -1), vl); /* put it there */ | |
| 504 | + memcpy(B->p, s, vl); /* put it there */ | |
| 529 | 505 | B->p += vl; |
| 530 | 506 | lua_pop(L, 1); /* remove from stack */ |
| 531 | 507 | } |
| @@ -562,11 +538,8 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { · 30 unmodified lines | ||
| 562 | 538 | lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ |
| 563 | 539 | } |
| 564 | 540 | else { /* no free elements */ |
| 565 | − ref = luaL_getn(L, t); | |
| 566 | − if (ref < RESERVED_REFS) | |
| 567 | − ref = RESERVED_REFS; /* skip reserved references */ | |
| 541 | + ref = lua_objsize(L, t); | |
| 568 | 542 | ref++; /* create new reference */ |
| 569 | − luaL_setn(L, t, ref); | |
| 570 | 543 | } |
| 571 | 544 | lua_rawseti(L, t, ref); |
| 572 | 545 | return ref; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lauxlib.h,v 1.74 2005/01/10 17:31:50 roberto Exp $ | |
| 2 | +** $Id: lauxlib.h,v 1.75 2005/03/29 16:20:48 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -15,6 +15,12 @@ · 9 unmodified lines | ||
| 15 | 15 | #include "lua.h" |
| 16 | 16 | |
| 17 | 17 | |
| 18 | +#if !LUA_COMPAT_GETN | |
| 19 | +#define luaL_getn(L,i) lua_objsize(L, i) | |
| 20 | +#define luaL_setn(L,i,j) ((void)0) /* no op! */ | |
| 21 | +#endif | |
| 22 | + | |
| 23 | + | |
| 18 | 24 | /* extra error code for `luaL_load' */ |
| 19 | 25 | #define LUA_ERRFILE (LUA_ERRERR+1) |
| 20 | 26 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lbaselib.c,v 1.169 2005/02/28 17:24:41 roberto Exp $ | |
| 2 | +** $Id: lbaselib.c,v 1.176 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Basic library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -39,7 +39,8 @@ static int luaB_print (lua_State *L) { · 33 unmodified lines | ||
| 39 | 39 | lua_call(L, 1, 1); |
| 40 | 40 | s = lua_tostring(L, -1); /* get result */ |
| 41 | 41 | if (s == NULL) |
| 42 | − return luaL_error(L, "`tostring' must return a string to `print'"); | |
| 42 | + return luaL_error(L, LUA_QL("tostring") " must return a string to " | |
| 43 | + LUA_QL("print")); | |
| 43 | 44 | if (i>1) fputs("\t", stdout); |
| 44 | 45 | fputs(s, stdout); |
| 45 | 46 | lua_pop(L, 1); /* pop result */ |
| @@ -148,7 +149,8 @@ static int luaB_setfenv (lua_State *L) { · 102 unmodified lines | ||
| 148 | 149 | return 0; |
| 149 | 150 | } |
| 150 | 151 | else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) |
| 151 | − luaL_error(L, "`setfenv' cannot change environment of given object"); | |
| 152 | + luaL_error(L, | |
| 153 | + LUA_QL("setfenv") " cannot change environment of given object"); | |
| 152 | 154 | return 1; |
| 153 | 155 | } |
| 154 | 156 | |
| @@ -164,6 +166,7 @@ static int luaB_rawequal (lua_State *L) { · 9 unmodified lines | ||
| 164 | 166 | static int luaB_rawget (lua_State *L) { |
| 165 | 167 | luaL_checktype(L, 1, LUA_TTABLE); |
| 166 | 168 | luaL_checkany(L, 2); |
| 169 | + lua_settop(L, 2); | |
| 167 | 170 | lua_rawget(L, 1); |
| 168 | 171 | return 1; |
| 169 | 172 | } |
| @@ -172,6 +175,7 @@ static int luaB_rawset (lua_State *L) { · 2 unmodified lines | ||
| 172 | 175 | luaL_checktype(L, 1, LUA_TTABLE); |
| 173 | 176 | luaL_checkany(L, 2); |
| 174 | 177 | luaL_checkany(L, 3); |
| 178 | + lua_settop(L, 3); | |
| 175 | 179 | lua_rawset(L, 1); |
| 176 | 180 | return 1; |
| 177 | 181 | } |
| @@ -185,9 +189,9 @@ static int luaB_gcinfo (lua_State *L) { · 7 unmodified lines | ||
| 185 | 189 | |
| 186 | 190 | static int luaB_collectgarbage (lua_State *L) { |
| 187 | 191 | static const char *const opts[] = {"stop", "restart", "collect", |
| 188 | − "count", "step", "setpace", "setstepmul", NULL}; | |
| 192 | + "count", "step", "setpause", "setstepmul", NULL}; | |
| 189 | 193 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, |
| 190 | − LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPACE, LUA_GCSETSTEPMUL}; | |
| 194 | + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; | |
| 191 | 195 | int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); |
| 192 | 196 | int ex = luaL_optinteger(L, 2, 0); |
| 193 | 197 | luaL_argcheck(L, o >= 0, 1, "invalid option"); |
| @@ -238,7 +242,7 @@ static int luaB_ipairs (lua_State *L) { · 44 unmodified lines | ||
| 238 | 242 | luaL_checktype(L, 1, LUA_TTABLE); |
| 239 | 243 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ |
| 240 | 244 | lua_pushvalue(L, 1); /* state, */ |
| 241 | − lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */ | |
| 245 | + lua_pushinteger(L, 0); /* and initial value */ | |
| 242 | 246 | return 3; |
| 243 | 247 | } |
| 244 | 248 | |
| @@ -292,11 +296,8 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { · 47 unmodified lines | ||
| 292 | 296 | return NULL; |
| 293 | 297 | } |
| 294 | 298 | else if (lua_isstring(L, -1)) { |
| 295 | − const char *res; | |
| 296 | 299 | lua_replace(L, 3); /* save string in a reserved stack slot */ |
| 297 | − res = lua_tostring(L, 3); | |
| 298 | − *size = lua_strlen(L, 3); | |
| 299 | − return res; | |
| 300 | + return lua_tolstring(L, 3, size); | |
| 300 | 301 | } |
| 301 | 302 | else luaL_error(L, "reader function must return a string"); |
| 302 | 303 | return NULL; /* to avoid warnings */ |
| @@ -330,13 +331,20 @@ static int luaB_assert (lua_State *L) { · 27 unmodified lines | ||
| 330 | 331 | } |
| 331 | 332 | |
| 332 | 333 | |
| 334 | +static int luaB_getn (lua_State *L) { | |
| 335 | + luaL_checktype(L, 1, LUA_TTABLE); | |
| 336 | + lua_pushinteger(L, lua_objsize(L, 1)); | |
| 337 | + return 1; | |
| 338 | +} | |
| 339 | + | |
| 340 | + | |
| 333 | 341 | static int luaB_unpack (lua_State *L) { |
| 334 | − int i = luaL_optint(L, 2, LUA_FIRSTINDEX); | |
| 342 | + int i = luaL_optint(L, 2, 1); | |
| 335 | 343 | int e = luaL_optint(L, 3, -1); |
| 336 | 344 | int n; |
| 337 | 345 | luaL_checktype(L, 1, LUA_TTABLE); |
| 338 | 346 | if (e == -1) |
| 339 | − e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | |
| 347 | + e = luaL_getn(L, 1); | |
| 340 | 348 | n = e - i + 1; /* number of elements */ |
| 341 | 349 | if (n <= 0) return 0; /* empty range */ |
| 342 | 350 | luaL_checkstack(L, n, "table too big to unpack"); |
| @@ -446,6 +454,7 @@ static const luaL_reg base_funcs[] = { · 103 unmodified lines | ||
| 446 | 454 | {"tostring", luaB_tostring}, |
| 447 | 455 | {"type", luaB_type}, |
| 448 | 456 | {"assert", luaB_assert}, |
| 457 | + {"getn", luaB_getn}, | |
| 449 | 458 | {"unpack", luaB_unpack}, |
| 450 | 459 | {"select", luaB_select}, |
| 451 | 460 | {"rawequal", luaB_rawequal}, |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.9 2005/01/10 18:17:39 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.12 2005/03/16 16:59:21 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -603,19 +603,32 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { · 597 unmodified lines | ||
| 603 | 603 | |
| 604 | 604 | |
| 605 | 605 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { |
| 606 | − if (op == OPR_MINUS) { | |
| 607 | − luaK_exp2val(fs, e); | |
| 608 | − if (e->k == VK && ttisnumber(&fs->f->k[e->info])) | |
| 609 | − e->info = luaK_numberK(fs, num_unm(nvalue(&fs->f->k[e->info]))); | |
| 610 | − else { | |
| 606 | + switch (op) { | |
| 607 | + case OPR_MINUS: { | |
| 608 | + luaK_exp2val(fs, e); | |
| 609 | + if (e->k == VK && ttisnumber(&fs->f->k[e->info])) | |
| 610 | + e->info = luaK_numberK(fs, luai_numunm(nvalue(&fs->f->k[e->info]))); | |
| 611 | + else { | |
| 612 | + luaK_exp2anyreg(fs, e); | |
| 613 | + freeexp(fs, e); | |
| 614 | + e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0); | |
| 615 | + e->k = VRELOCABLE; | |
| 616 | + } | |
| 617 | + break; | |
| 618 | + } | |
| 619 | + case OPR_NOT: { | |
| 620 | + codenot(fs, e); | |
| 621 | + break; | |
| 622 | + } | |
| 623 | + case OPR_SIZE: { | |
| 611 | 624 | luaK_exp2anyreg(fs, e); |
| 612 | 625 | freeexp(fs, e); |
| 613 | − e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0); | |
| 626 | + e->info = luaK_codeABC(fs, OP_SIZ, 0, e->info, 0); | |
| 614 | 627 | e->k = VRELOCABLE; |
| 628 | + break; | |
| 615 | 629 | } |
| 630 | + default: lua_assert(0); | |
| 616 | 631 | } |
| 617 | − else /* op == NOT */ | |
| 618 | − codenot(fs, e); | |
| 619 | 632 | } |
| 620 | 633 | |
| 621 | 634 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.h,v 1.40 2004/10/04 19:01:53 roberto Exp $ | |
| 2 | +** $Id: lcode.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -24,7 +24,7 @@ · 18 unmodified lines | ||
| 24 | 24 | ** grep "ORDER OPR" if you change these enums |
| 25 | 25 | */ |
| 26 | 26 | typedef enum BinOpr { |
| 27 | − OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW, | |
| 27 | + OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_MOD, OPR_POW, | |
| 28 | 28 | OPR_CONCAT, |
| 29 | 29 | OPR_NE, OPR_EQ, |
| 30 | 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, |
| @@ -34,7 +34,7 @@ typedef enum BinOpr { · 3 unmodified lines | ||
| 34 | 34 | |
| 35 | 35 | #define binopistest(op) ((op) >= OPR_NE) |
| 36 | 36 | |
| 37 | −typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; | |
| 37 | +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_SIZE, OPR_NOUNOPR } UnOpr; | |
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | #define getcode(fs,e) ((fs)->f->code[(e)->info]) |
| @@ -43,36 +43,36 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; · 2 unmodified lines | ||
| 43 | 43 | |
| 44 | 44 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) |
| 45 | 45 | |
| 46 | −int luaK_code (FuncState *fs, Instruction i, int line); | |
| 47 | −int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | |
| 48 | −int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | |
| 49 | −void luaK_fixline (FuncState *fs, int line); | |
| 50 | −void luaK_nil (FuncState *fs, int from, int n); | |
| 51 | −void luaK_reserveregs (FuncState *fs, int n); | |
| 52 | −void luaK_checkstack (FuncState *fs, int n); | |
| 53 | −int luaK_stringK (FuncState *fs, TString *s); | |
| 54 | −int luaK_numberK (FuncState *fs, lua_Number r); | |
| 55 | −void luaK_dischargevars (FuncState *fs, expdesc *e); | |
| 56 | −int luaK_exp2anyreg (FuncState *fs, expdesc *e); | |
| 57 | −void luaK_exp2nextreg (FuncState *fs, expdesc *e); | |
| 58 | −void luaK_exp2val (FuncState *fs, expdesc *e); | |
| 59 | −int luaK_exp2RK (FuncState *fs, expdesc *e); | |
| 60 | −void luaK_self (FuncState *fs, expdesc *e, expdesc *key); | |
| 61 | −void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); | |
| 62 | −void luaK_goiftrue (FuncState *fs, expdesc *e); | |
| 63 | −void luaK_goiffalse (FuncState *fs, expdesc *e); | |
| 64 | −void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); | |
| 65 | −void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); | |
| 66 | −void luaK_setoneret (FuncState *fs, expdesc *e); | |
| 67 | −int luaK_jump (FuncState *fs); | |
| 68 | −void luaK_patchlist (FuncState *fs, int list, int target); | |
| 69 | −void luaK_patchtohere (FuncState *fs, int list); | |
| 70 | −void luaK_concat (FuncState *fs, int *l1, int l2); | |
| 71 | −int luaK_getlabel (FuncState *fs); | |
| 72 | −void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); | |
| 73 | −void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); | |
| 74 | −void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); | |
| 75 | −void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); | |
| 46 | +LUAI_FUNC int luaK_code (FuncState *fs, Instruction i, int line); | |
| 47 | +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | |
| 48 | +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | |
| 49 | +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); | |
| 50 | +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); | |
| 51 | +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); | |
| 52 | +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); | |
| 53 | +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); | |
| 54 | +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); | |
| 55 | +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); | |
| 56 | +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); | |
| 57 | +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); | |
| 58 | +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); | |
| 59 | +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); | |
| 60 | +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); | |
| 61 | +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); | |
| 62 | +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); | |
| 63 | +LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); | |
| 64 | +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); | |
| 65 | +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); | |
| 66 | +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); | |
| 67 | +LUAI_FUNC int luaK_jump (FuncState *fs); | |
| 68 | +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); | |
| 69 | +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); | |
| 70 | +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); | |
| 71 | +LUAI_FUNC int luaK_getlabel (FuncState *fs); | |
| 72 | +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); | |
| 73 | +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); | |
| 74 | +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); | |
| 75 | +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); | |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldblib.c,v 1.93 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: ldblib.c,v 1.98 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Interface from Lua to its debug API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -19,7 +19,7 @@ · 13 unmodified lines | ||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | −static int getmetatable (lua_State *L) { | |
| 22 | +static int db_getmetatable (lua_State *L) { | |
| 23 | 23 | luaL_checkany(L, 1); |
| 24 | 24 | if (!lua_getmetatable(L, 1)) { |
| 25 | 25 | lua_pushnil(L); /* no metatable */ |
| @@ -28,7 +28,7 @@ static int getmetatable (lua_State *L) { · 2 unmodified lines | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | |
| 31 | −static int setmetatable (lua_State *L) { | |
| 31 | +static int db_setmetatable (lua_State *L) { | |
| 32 | 32 | int t = lua_type(L, 2); |
| 33 | 33 | luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, |
| 34 | 34 | "nil or table expected"); |
| @@ -38,17 +38,18 @@ static int setmetatable (lua_State *L) { · 3 unmodified lines | ||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
| 41 | −static int getfenv (lua_State *L) { | |
| 41 | +static int db_getfenv (lua_State *L) { | |
| 42 | 42 | lua_getfenv(L, 1); |
| 43 | 43 | return 1; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
| 47 | −static int setfenv (lua_State *L) { | |
| 47 | +static int db_setfenv (lua_State *L) { | |
| 48 | 48 | luaL_checktype(L, 2, LUA_TTABLE); |
| 49 | 49 | lua_settop(L, 2); |
| 50 | 50 | if (lua_setfenv(L, 1) == 0) |
| 51 | − luaL_error(L, "`setfenv' cannot change environment of given object"); | |
| 51 | + luaL_error(L, LUA_QL("setfenv") | |
| 52 | + " cannot change environment of given object"); | |
| 52 | 53 | return 1; |
| 53 | 54 | } |
| 54 | 55 | |
| @@ -77,7 +78,18 @@ static lua_State *getthread (lua_State *L, int *arg) { · 22 unmodified lines | ||
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | |
| 80 | −static int getinfo (lua_State *L) { | |
| 81 | +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { | |
| 82 | + if (L == L1) { | |
| 83 | + lua_pushvalue(L, -2); | |
| 84 | + lua_remove(L, -3); | |
| 85 | + } | |
| 86 | + else | |
| 87 | + lua_xmove(L1, L, 1); | |
| 88 | + lua_setfield(L, -2, fname); | |
| 89 | +} | |
| 90 | + | |
| 91 | + | |
| 92 | +static int db_getinfo (lua_State *L) { | |
| 81 | 93 | lua_Debug ar; |
| 82 | 94 | int arg; |
| 83 | 95 | lua_State *L1 = getthread(L, &arg); |
| @@ -99,38 +111,30 @@ static int getinfo (lua_State *L) { · 15 unmodified lines | ||
| 99 | 111 | if (!lua_getinfo(L1, options, &ar)) |
| 100 | 112 | return luaL_argerror(L, arg+2, "invalid option"); |
| 101 | 113 | lua_newtable(L); |
| 102 | − for (; *options; options++) { | |
| 103 | − switch (*options) { | |
| 104 | − case 'S': | |
| 105 | − settabss(L, "source", ar.source); | |
| 106 | − settabss(L, "short_src", ar.short_src); | |
| 107 | − settabsi(L, "linedefined", ar.linedefined); | |
| 108 | − settabss(L, "what", ar.what); | |
| 109 | − break; | |
| 110 | − case 'l': | |
| 111 | − settabsi(L, "currentline", ar.currentline); | |
| 112 | − break; | |
| 113 | − case 'u': | |
| 114 | − settabsi(L, "nups", ar.nups); | |
| 115 | − break; | |
| 116 | − case 'n': | |
| 117 | − settabss(L, "name", ar.name); | |
| 118 | − settabss(L, "namewhat", ar.namewhat); | |
| 119 | − break; | |
| 120 | − case 'f': | |
| 121 | − if (L == L1) | |
| 122 | − lua_pushvalue(L, -2); | |
| 123 | − else | |
| 124 | − lua_xmove(L1, L, 1); | |
| 125 | − lua_setfield(L, -2, "func"); | |
| 126 | − break; | |
| 127 | − } | |
| 114 | + if (strchr(options, 'S')) { | |
| 115 | + settabss(L, "source", ar.source); | |
| 116 | + settabss(L, "short_src", ar.short_src); | |
| 117 | + settabsi(L, "linedefined", ar.linedefined); | |
| 118 | + settabsi(L, "lastlinedefined", ar.lastlinedefined); | |
| 119 | + settabss(L, "what", ar.what); | |
| 120 | + } | |
| 121 | + if (strchr(options, 'l')) | |
| 122 | + settabsi(L, "currentline", ar.currentline); | |
| 123 | + if (strchr(options, 'u')) | |
| 124 | + settabsi(L, "nups", ar.nups); | |
| 125 | + if (strchr(options, 'n')) { | |
| 126 | + settabss(L, "name", ar.name); | |
| 127 | + settabss(L, "namewhat", ar.namewhat); | |
| 128 | 128 | } |
| 129 | + if (strchr(options, 'L')) | |
| 130 | + treatstackoption(L, L1, "activelines"); | |
| 131 | + if (strchr(options, 'f')) | |
| 132 | + treatstackoption(L, L1, "func"); | |
| 129 | 133 | return 1; /* return table */ |
| 130 | 134 | } |
| 131 | 135 | |
| 132 | 136 | |
| 133 | −static int getlocal (lua_State *L) { | |
| 137 | +static int db_getlocal (lua_State *L) { | |
| 134 | 138 | int arg; |
| 135 | 139 | lua_State *L1 = getthread(L, &arg); |
| 136 | 140 | lua_Debug ar; |
| @@ -151,7 +155,7 @@ static int getlocal (lua_State *L) { · 14 unmodified lines | ||
| 151 | 155 | } |
| 152 | 156 | |
| 153 | 157 | |
| 154 | −static int setlocal (lua_State *L) { | |
| 158 | +static int db_setlocal (lua_State *L) { | |
| 155 | 159 | int arg; |
| 156 | 160 | lua_State *L1 = getthread(L, &arg); |
| 157 | 161 | lua_Debug ar; |
| @@ -178,12 +182,12 @@ static int auxupvalue (lua_State *L, int get) { · 20 unmodified lines | ||
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | |
| 181 | −static int getupvalue (lua_State *L) { | |
| 185 | +static int db_getupvalue (lua_State *L) { | |
| 182 | 186 | return auxupvalue(L, 1); |
| 183 | 187 | } |
| 184 | 188 | |
| 185 | 189 | |
| 186 | −static int setupvalue (lua_State *L) { | |
| 190 | +static int db_setupvalue (lua_State *L) { | |
| 187 | 191 | luaL_checkany(L, 3); |
| 188 | 192 | return auxupvalue(L, 0); |
| 189 | 193 | } |
| @@ -244,7 +248,7 @@ static void gethooktable (lua_State *L) { · 54 unmodified lines | ||
| 244 | 248 | } |
| 245 | 249 | |
| 246 | 250 | |
| 247 | −static int sethook (lua_State *L) { | |
| 251 | +static int db_sethook (lua_State *L) { | |
| 248 | 252 | int arg; |
| 249 | 253 | lua_State *L1 = getthread(L, &arg); |
| 250 | 254 | if (lua_isnoneornil(L, arg+1)) { |
| @@ -267,7 +271,7 @@ static int sethook (lua_State *L) { · 16 unmodified lines | ||
| 267 | 271 | } |
| 268 | 272 | |
| 269 | 273 | |
| 270 | −static int gethook (lua_State *L) { | |
| 274 | +static int db_gethook (lua_State *L) { | |
| 271 | 275 | int arg; |
| 272 | 276 | lua_State *L1 = getthread(L, &arg); |
| 273 | 277 | char buff[5]; |
| @@ -288,7 +292,7 @@ static int gethook (lua_State *L) { · 14 unmodified lines | ||
| 288 | 292 | } |
| 289 | 293 | |
| 290 | 294 | |
| 291 | −static int debug (lua_State *L) { | |
| 295 | +static int db_debug (lua_State *L) { | |
| 292 | 296 | for (;;) { |
| 293 | 297 | char buffer[250]; |
| 294 | 298 | fputs("lua_debug> ", stderr); |
| @@ -308,7 +312,7 @@ static int debug (lua_State *L) { · 13 unmodified lines | ||
| 308 | 312 | #define LEVELS1 12 /* size of the first part of the stack */ |
| 309 | 313 | #define LEVELS2 10 /* size of the second part of the stack */ |
| 310 | 314 | |
| 311 | −static int errorfb (lua_State *L) { | |
| 315 | +static int db_errorfb (lua_State *L) { | |
| 312 | 316 | int level; |
| 313 | 317 | int firstpart = 1; /* still before eventual `...' */ |
| 314 | 318 | int arg; |
| @@ -344,7 +348,7 @@ static int errorfb (lua_State *L) { · 29 unmodified lines | ||
| 344 | 348 | if (ar.currentline > 0) |
| 345 | 349 | lua_pushfstring(L, "%d:", ar.currentline); |
| 346 | 350 | if (*ar.namewhat != '\0') /* is there a name? */ |
| 347 | − lua_pushfstring(L, " in function `%s'", ar.name); | |
| 351 | + lua_pushfstring(L, " in function " LUA_QS, ar.name); | |
| 348 | 352 | else { |
| 349 | 353 | if (*ar.what == 'm') /* main? */ |
| 350 | 354 | lua_pushfstring(L, " in main chunk"); |
| @@ -362,19 +366,19 @@ static int errorfb (lua_State *L) { · 11 unmodified lines | ||
| 362 | 366 | |
| 363 | 367 | |
| 364 | 368 | static const luaL_reg dblib[] = { |
| 365 | − {"getmetatable", getmetatable}, | |
| 366 | − {"setmetatable", setmetatable}, | |
| 367 | − {"getfenv", getfenv}, | |
| 368 | − {"setfenv", setfenv}, | |
| 369 | − {"getlocal", getlocal}, | |
| 370 | − {"getinfo", getinfo}, | |
| 371 | − {"gethook", gethook}, | |
| 372 | − {"getupvalue", getupvalue}, | |
| 373 | − {"sethook", sethook}, | |
| 374 | − {"setlocal", setlocal}, | |
| 375 | − {"setupvalue", setupvalue}, | |
| 376 | − {"debug", debug}, | |
| 377 | − {"traceback", errorfb}, | |
| 369 | + {"getmetatable", db_getmetatable}, | |
| 370 | + {"setmetatable", db_setmetatable}, | |
| 371 | + {"getfenv", db_getfenv}, | |
| 372 | + {"setfenv", db_setfenv}, | |
| 373 | + {"getlocal", db_getlocal}, | |
| 374 | + {"getinfo", db_getinfo}, | |
| 375 | + {"gethook", db_gethook}, | |
| 376 | + {"getupvalue", db_getupvalue}, | |
| 377 | + {"sethook", db_sethook}, | |
| 378 | + {"setlocal", db_setlocal}, | |
| 379 | + {"setupvalue", db_setupvalue}, | |
| 380 | + {"debug", db_debug}, | |
| 381 | + {"traceback", db_errorfb}, | |
| 378 | 382 | {NULL, NULL} |
| 379 | 383 | }; |
| 380 | 384 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 roberto Exp $ | |
| 2 | +** $Id: ldebug.c,v 2.20 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Debug Interface |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -30,17 +30,19 @@ · 24 unmodified lines | ||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | −static const char *getfuncname (CallInfo *ci, const char **name); | |
| 33 | +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | −static int currentpc (CallInfo *ci) { | |
| 36 | +static int currentpc (lua_State *L, CallInfo *ci) { | |
| 37 | 37 | if (!isLua(ci)) return -1; /* function is not a Lua function? */ |
| 38 | + if (ci == L->ci) | |
| 39 | + ci->savedpc = L->savedpc; | |
| 38 | 40 | return pcRel(ci->savedpc, ci_func(ci)->l.p); |
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | |
| 42 | −static int currentline (CallInfo *ci) { | |
| 43 | − int pc = currentpc(ci); | |
| 44 | +static int currentline (lua_State *L, CallInfo *ci) { | |
| 45 | + int pc = currentpc(L, ci); | |
| 44 | 46 | if (pc < 0) |
| 45 | 47 | return -1; /* only active lua functions have current-line information */ |
| 46 | 48 | else |
| @@ -88,15 +90,15 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 41 unmodified lines | ||
| 88 | 90 | if (f_isLua(ci)) /* Lua function? */ |
| 89 | 91 | level -= ci->tailcalls; /* skip lost tail calls */ |
| 90 | 92 | } |
| 91 | − if (level > 0 || ci == L->base_ci) status = 0; /* there is no such level */ | |
| 92 | − else if (level < 0) { /* level is of a lost tail call */ | |
| 93 | + if (level == 0 && ci > L->base_ci) { /* level found? */ | |
| 93 | 94 | status = 1; |
| 94 | − ar->i_ci = 0; | |
| 95 | + ar->i_ci = ci - L->base_ci; | |
| 95 | 96 | } |
| 96 | − else { | |
| 97 | + else if (level < 0) { /* level is of a lost tail call? */ | |
| 97 | 98 | status = 1; |
| 98 | − ar->i_ci = ci - L->base_ci; | |
| 99 | + ar->i_ci = 0; | |
| 99 | 100 | } |
| 101 | + else status = 0; /* no such level */ | |
| 100 | 102 | lua_unlock(L); |
| 101 | 103 | return status; |
| 102 | 104 | } |
| @@ -116,7 +118,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { · 13 unmodified lines | ||
| 116 | 118 | ci = L->base_ci + ar->i_ci; |
| 117 | 119 | fp = getluaproto(ci); |
| 118 | 120 | if (fp) { /* is a Lua function? */ |
| 119 | − name = luaF_getlocalname(fp, n, currentpc(ci)); | |
| 121 | + name = luaF_getlocalname(fp, n, currentpc(L, ci)); | |
| 120 | 122 | if (name) |
| 121 | 123 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ |
| 122 | 124 | } |
| @@ -135,7 +137,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { · 12 unmodified lines | ||
| 135 | 137 | fp = getluaproto(ci); |
| 136 | 138 | L->top--; /* pop new value */ |
| 137 | 139 | if (fp) { /* is a Lua function? */ |
| 138 | − name = luaF_getlocalname(fp, n, currentpc(ci)); | |
| 140 | + name = luaF_getlocalname(fp, n, currentpc(L, ci)); | |
| 139 | 141 | if (!name || name[0] == '(') /* `(' starts private locals */ |
| 140 | 142 | name = NULL; |
| 141 | 143 | else |
| @@ -146,8 +148,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { · 4 unmodified lines | ||
| 146 | 148 | } |
| 147 | 149 | |
| 148 | 150 | |
| 149 | −static void funcinfo (lua_Debug *ar, StkId func) { | |
| 150 | − Closure *cl = clvalue(func); | |
| 151 | +static void funcinfo (lua_Debug *ar, Closure *cl) { | |
| 151 | 152 | if (cl->c.isC) { |
| 152 | 153 | ar->source = "=[C]"; |
| 153 | 154 | ar->linedefined = -1; |
| @@ -155,7 +156,8 @@ static void funcinfo (lua_Debug *ar, StkId func) { · 1 unmodified line | ||
| 155 | 156 | } |
| 156 | 157 | else { |
| 157 | 158 | ar->source = getstr(cl->l.p->source); |
| 158 | − ar->linedefined = cl->l.p->lineDefined; | |
| 159 | + ar->linedefined = cl->l.p->linedefined; | |
| 160 | + ar->lastlinedefined = cl->l.p->lastlinedefined; | |
| 159 | 161 | ar->what = (ar->linedefined == 0) ? "main" : "Lua"; |
| 160 | 162 | } |
| 161 | 163 | luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); |
| @@ -165,17 +167,36 @@ static void funcinfo (lua_Debug *ar, StkId func) { · 3 unmodified lines | ||
| 165 | 167 | static void info_tailcall (lua_State *L, lua_Debug *ar) { |
| 166 | 168 | ar->name = ar->namewhat = ""; |
| 167 | 169 | ar->what = "tail"; |
| 168 | − ar->linedefined = ar->currentline = -1; | |
| 170 | + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; | |
| 169 | 171 | ar->source = "=(tail call)"; |
| 170 | 172 | luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); |
| 171 | 173 | ar->nups = 0; |
| 172 | − setnilvalue(L->top); | |
| 174 | +} | |
| 175 | + | |
| 176 | + | |
| 177 | +static void collectvalidlines (lua_State *L, Closure *f) { | |
| 178 | + if (f == NULL || f->c.isC) { | |
| 179 | + setnilvalue(L->top); | |
| 180 | + } | |
| 181 | + else { | |
| 182 | + Table *t = luaH_new(L, 0, 0); | |
| 183 | + int *lineinfo = f->l.p->lineinfo; | |
| 184 | + int i; | |
| 185 | + for (i=0; i<f->l.p->sizelineinfo; i++) | |
| 186 | + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); | |
| 187 | + sethvalue(L, L->top, t); | |
| 188 | + } | |
| 189 | + incr_top(L); | |
| 173 | 190 | } |
| 174 | 191 | |
| 175 | 192 | |
| 176 | 193 | static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, |
| 177 | − StkId f, CallInfo *ci) { | |
| 194 | + Closure *f, CallInfo *ci) { | |
| 178 | 195 | int status = 1; |
| 196 | + if (f == NULL) { | |
| 197 | + info_tailcall(L, ar); | |
| 198 | + return status; | |
| 199 | + } | |
| 179 | 200 | for (; *what; what++) { |
| 180 | 201 | switch (*what) { |
| 181 | 202 | case 'S': { |
| @@ -183,25 +204,24 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, · 1 unmodified line | ||
| 183 | 204 | break; |
| 184 | 205 | } |
| 185 | 206 | case 'l': { |
| 186 | − ar->currentline = (ci) ? currentline(ci) : -1; | |
| 207 | + ar->currentline = (ci) ? currentline(L, ci) : -1; | |
| 187 | 208 | break; |
| 188 | 209 | } |
| 189 | 210 | case 'u': { |
| 190 | − ar->nups = clvalue(f)->c.nupvalues; | |
| 211 | + ar->nups = f->c.nupvalues; | |
| 191 | 212 | break; |
| 192 | 213 | } |
| 193 | 214 | case 'n': { |
| 194 | − ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; | |
| 215 | + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; | |
| 195 | 216 | if (ar->namewhat == NULL) { |
| 196 | 217 | ar->namewhat = ""; /* not found */ |
| 197 | 218 | ar->name = NULL; |
| 198 | 219 | } |
| 199 | 220 | break; |
| 200 | 221 | } |
| 201 | − case 'f': { | |
| 202 | − setobj2s(L, L->top, f); | |
| 222 | + case 'L': | |
| 223 | + case 'f': /* handled by lua_getinfo */ | |
| 203 | 224 | break; |
| 204 | − } | |
| 205 | 225 | default: status = 0; /* invalid option */ |
| 206 | 226 | } |
| 207 | 227 | } |
| @@ -210,23 +230,30 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, · 2 unmodified lines | ||
| 210 | 230 | |
| 211 | 231 | |
| 212 | 232 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { |
| 213 | − int status = 1; | |
| 233 | + int status; | |
| 234 | + Closure *f = NULL; | |
| 235 | + CallInfo *ci = NULL; | |
| 214 | 236 | lua_lock(L); |
| 215 | 237 | if (*what == '>') { |
| 216 | − StkId f = L->top - 1; | |
| 217 | − if (!ttisfunction(f)) | |
| 218 | − luaG_runerror(L, "value for `lua_getinfo' is not a function"); | |
| 219 | − status = auxgetinfo(L, what + 1, ar, f, NULL); | |
| 238 | + StkId func = L->top - 1; | |
| 239 | + luai_apicheck(L, ttisfunction(func)); | |
| 240 | + what++; /* skip the '>' */ | |
| 241 | + f = clvalue(func); | |
| 220 | 242 | L->top--; /* pop function */ |
| 221 | 243 | } |
| 222 | 244 | else if (ar->i_ci != 0) { /* no tail call? */ |
| 223 | − CallInfo *ci = L->base_ci + ar->i_ci; | |
| 245 | + ci = L->base_ci + ar->i_ci; | |
| 224 | 246 | lua_assert(ttisfunction(ci->func)); |
| 225 | − status = auxgetinfo(L, what, ar, ci->func, ci); | |
| 247 | + f = clvalue(ci->func); | |
| 226 | 248 | } |
| 227 | − else | |
| 228 | − info_tailcall(L, ar); | |
| 229 | − if (strchr(what, 'f')) incr_top(L); | |
| 249 | + status = auxgetinfo(L, what, ar, f, ci); | |
| 250 | + if (strchr(what, 'f')) { | |
| 251 | + if (f == NULL) setnilvalue(L->top); | |
| 252 | + else setclvalue(L, L->top, f); | |
| 253 | + incr_top(L); | |
| 254 | + } | |
| 255 | + if (strchr(what, 'L')) | |
| 256 | + collectvalidlines(L, f); | |
| 230 | 257 | lua_unlock(L); |
| 231 | 258 | return status; |
| 232 | 259 | } |
| @@ -366,7 +393,6 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 133 unmodified lines | ||
| 366 | 393 | if (reg >= a+3) last = pc; /* affect all regs above its call base */ |
| 367 | 394 | break; |
| 368 | 395 | } |
| 369 | − case OP_TFORPREP: | |
| 370 | 396 | case OP_FORLOOP: |
| 371 | 397 | case OP_FORPREP: |
| 372 | 398 | checkreg(pt, a+3); |
| @@ -446,10 +472,11 @@ static const char *kname (Proto *p, int c) { · 73 unmodified lines | ||
| 446 | 472 | } |
| 447 | 473 | |
| 448 | 474 | |
| 449 | −static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { | |
| 475 | +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, | |
| 476 | + const char **name) { | |
| 450 | 477 | if (isLua(ci)) { /* a Lua function? */ |
| 451 | 478 | Proto *p = ci_func(ci)->l.p; |
| 452 | − int pc = currentpc(ci); | |
| 479 | + int pc = currentpc(L, ci); | |
| 453 | 480 | Instruction i; |
| 454 | 481 | *name = luaF_getlocalname(p, stackpos+1, pc); |
| 455 | 482 | if (*name) /* is a local? */ |
| @@ -467,7 +494,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { · 11 unmodified lines | ||
| 467 | 494 | int a = GETARG_A(i); |
| 468 | 495 | int b = GETARG_B(i); /* move from `b' to `a' */ |
| 469 | 496 | if (b < a) |
| 470 | − return getobjname(ci, b, name); /* get name for `b' */ | |
| 497 | + return getobjname(L, ci, b, name); /* get name for `b' */ | |
| 471 | 498 | break; |
| 472 | 499 | } |
| 473 | 500 | case OP_GETTABLE: { |
| @@ -492,15 +519,15 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { · 18 unmodified lines | ||
| 492 | 519 | } |
| 493 | 520 | |
| 494 | 521 | |
| 495 | −static const char *getfuncname (CallInfo *ci, const char **name) { | |
| 522 | +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |
| 496 | 523 | Instruction i; |
| 497 | 524 | if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) |
| 498 | 525 | return NULL; /* calling function is not Lua (or is unknown) */ |
| 499 | 526 | ci--; /* calling function */ |
| 500 | − i = ci_func(ci)->l.p->code[currentpc(ci)]; | |
| 527 | + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; | |
| 501 | 528 | if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || |
| 502 | 529 | GET_OPCODE(i) == OP_TFORLOOP) |
| 503 | − return getobjname(ci, GETARG_A(i), name); | |
| 530 | + return getobjname(L, ci, GETARG_A(i), name); | |
| 504 | 531 | else |
| 505 | 532 | return NULL; /* no useful name can be found */ |
| 506 | 533 | } |
| @@ -519,9 +546,9 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 12 unmodified lines | ||
| 519 | 546 | const char *name = NULL; |
| 520 | 547 | const char *t = luaT_typenames[ttype(o)]; |
| 521 | 548 | const char *kind = (isinstack(L->ci, o)) ? |
| 522 | − getobjname(L->ci, o - L->base, &name) : NULL; | |
| 549 | + getobjname(L, L->ci, o - L->base, &name) : NULL; | |
| 523 | 550 | if (kind) |
| 524 | − luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", | |
| 551 | + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", | |
| 525 | 552 | op, kind, name, t); |
| 526 | 553 | else |
| 527 | 554 | luaG_runerror(L, "attempt to %s a %s value", op, t); |
| @@ -558,7 +585,7 @@ static void addinfo (lua_State *L, const char *msg) { · 30 unmodified lines | ||
| 558 | 585 | CallInfo *ci = L->ci; |
| 559 | 586 | if (isLua(ci)) { /* is Lua code? */ |
| 560 | 587 | char buff[LUA_IDSIZE]; /* add file:line information */ |
| 561 | − int line = currentline(ci); | |
| 588 | + int line = currentline(L, ci); | |
| 562 | 589 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); |
| 563 | 590 | luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); |
| 564 | 591 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldebug.h,v 2.2 2004/06/02 19:07:55 roberto Exp $ | |
| 2 | +** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions from Debug Interface module |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -18,13 +18,16 @@ · 12 unmodified lines | ||
| 18 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) |
| 19 | 19 | |
| 20 | 20 | |
| 21 | −void luaG_typeerror (lua_State *L, const TValue *o, const char *opname); | |
| 22 | −void luaG_concaterror (lua_State *L, StkId p1, StkId p2); | |
| 23 | −void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2); | |
| 24 | −int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2); | |
| 25 | −void luaG_runerror (lua_State *L, const char *fmt, ...); | |
| 26 | −void luaG_errormsg (lua_State *L); | |
| 27 | −int luaG_checkcode (const Proto *pt); | |
| 28 | −int luaG_checkopenop (Instruction i); | |
| 21 | +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, | |
| 22 | + const char *opname); | |
| 23 | +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); | |
| 24 | +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, | |
| 25 | + const TValue *p2); | |
| 26 | +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, | |
| 27 | + const TValue *p2); | |
| 28 | +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); | |
| 29 | +LUAI_FUNC void luaG_errormsg (lua_State *L); | |
| 30 | +LUAI_FUNC int luaG_checkcode (const Proto *pt); | |
| 31 | +LUAI_FUNC int luaG_checkopenop (Instruction i); | |
| 29 | 32 | |
| 30 | 33 | #endif |
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldo.c,v 2.14 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: ldo.c,v 2.23 2005/05/03 19:01:17 roberto Exp $ | |
| 3 | 3 | ** Stack and Call structure of Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | |
| 8 | +#include <setjmp.h> | |
| 8 | 9 | #include <stdlib.h> |
| 9 | 10 | #include <string.h> |
| 10 | 11 | |
| @@ -42,7 +43,7 @@ · 31 unmodified lines | ||
| 42 | 43 | /* chain list of long jump buffers */ |
| 43 | 44 | struct lua_longjmp { |
| 44 | 45 | struct lua_longjmp *previous; |
| 45 | − l_jmpbuf b; | |
| 46 | + luai_jmpbuf b; | |
| 46 | 47 | volatile int status; /* error code */ |
| 47 | 48 | }; |
| 48 | 49 | |
| @@ -70,9 +71,10 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 21 unmodified lines | ||
| 70 | 71 | void luaD_throw (lua_State *L, int errcode) { |
| 71 | 72 | if (L->errorJmp) { |
| 72 | 73 | L->errorJmp->status = errcode; |
| 73 | − L_THROW(L, L->errorJmp); | |
| 74 | + LUAI_THROW(L, L->errorJmp); | |
| 74 | 75 | } |
| 75 | 76 | else { |
| 77 | + L->status = errcode; | |
| 76 | 78 | if (G(L)->panic) G(L)->panic(L); |
| 77 | 79 | exit(EXIT_FAILURE); |
| 78 | 80 | } |
| @@ -84,7 +86,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 5 unmodified lines | ||
| 84 | 86 | lj.status = 0; |
| 85 | 87 | lj.previous = L->errorJmp; /* chain new error handler */ |
| 86 | 88 | L->errorJmp = &lj; |
| 87 | − L_TRY(L, &lj, | |
| 89 | + LUAI_TRY(L, &lj, | |
| 88 | 90 | (*f)(L, ud); |
| 89 | 91 | ); |
| 90 | 92 | L->errorJmp = lj.previous; /* restore old error handler */ |
| @@ -94,10 +96,10 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 3 unmodified lines | ||
| 94 | 96 | |
| 95 | 97 | static void restore_stack_limit (lua_State *L) { |
| 96 | 98 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); |
| 97 | − if (L->size_ci > LUA_MAXCALLS) { /* there was an overflow? */ | |
| 99 | + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ | |
| 98 | 100 | int inuse = (L->ci - L->base_ci); |
| 99 | − if (inuse + 1 < LUA_MAXCALLS) /* can `undo' overflow? */ | |
| 100 | − luaD_reallocCI(L, LUA_MAXCALLS); | |
| 101 | + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ | |
| 102 | + luaD_reallocCI(L, LUAI_MAXCALLS); | |
| 101 | 103 | } |
| 102 | 104 | } |
| 103 | 105 | |
| @@ -114,6 +116,7 @@ static void correctstack (lua_State *L, TValue *oldstack) { · 10 unmodified lines | ||
| 114 | 116 | ci->top = (ci->top - oldstack) + L->stack; |
| 115 | 117 | ci->base = (ci->base - oldstack) + L->stack; |
| 116 | 118 | ci->func = (ci->func - oldstack) + L->stack; |
| 119 | + lua_assert(lua_checkpc(L, ci)); | |
| 117 | 120 | } |
| 118 | 121 | L->base = L->ci->base; |
| 119 | 122 | } |
| @@ -133,7 +136,7 @@ void luaD_reallocstack (lua_State *L, int newsize) { · 13 unmodified lines | ||
| 133 | 136 | void luaD_reallocCI (lua_State *L, int newsize) { |
| 134 | 137 | CallInfo *oldci = L->base_ci; |
| 135 | 138 | luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); |
| 136 | − L->size_ci = cast(unsigned short, newsize); | |
| 139 | + L->size_ci = newsize; | |
| 137 | 140 | L->ci = (L->ci - oldci) + L->base_ci; |
| 138 | 141 | L->end_ci = L->base_ci + L->size_ci - 1; |
| 139 | 142 | } |
| @@ -148,11 +151,11 @@ void luaD_growstack (lua_State *L, int n) { · 8 unmodified lines | ||
| 148 | 151 | |
| 149 | 152 | |
| 150 | 153 | static CallInfo *growCI (lua_State *L) { |
| 151 | − if (L->size_ci > LUA_MAXCALLS) /* overflow while handling overflow? */ | |
| 154 | + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ | |
| 152 | 155 | luaD_throw(L, LUA_ERRERR); |
| 153 | 156 | else { |
| 154 | 157 | luaD_reallocCI(L, 2*L->size_ci); |
| 155 | − if (L->size_ci > LUA_MAXCALLS) | |
| 158 | + if (L->size_ci > LUAI_MAXCALLS) | |
| 156 | 159 | luaG_runerror(L, "stack overflow"); |
| 157 | 160 | } |
| 158 | 161 | return ++L->ci; |
| @@ -195,16 +198,18 @@ static StkId adjust_varargs (lua_State *L, int nfixargs, int actual, · 36 unmodified lines | ||
| 195 | 198 | for (; actual < nfixargs; ++actual) |
| 196 | 199 | setnilvalue(L->top++); |
| 197 | 200 | } |
| 201 | +#if LUA_COMPAT_VARARG | |
| 198 | 202 | if (style != NEWSTYLEVARARG) { /* compatibility with old-style vararg */ |
| 199 | 203 | int nvar = actual - nfixargs; /* number of extra arguments */ |
| 200 | 204 | luaC_checkGC(L); |
| 201 | 205 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ |
| 202 | 206 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
| 203 | − setobj2n(L, luaH_setnum(L, htab, i+LUA_FIRSTINDEX), L->top - nvar + i); | |
| 207 | + setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); | |
| 204 | 208 | /* store counter in field `n' */ |
| 205 | 209 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), |
| 206 | 210 | cast(lua_Number, nvar)); |
| 207 | 211 | } |
| 212 | +#endif | |
| 208 | 213 | /* move fixed parameters to final position */ |
| 209 | 214 | fixed = L->top - actual; /* first fixed argument */ |
| 210 | 215 | base = L->top; /* final position of first argument */ |
| @@ -249,6 +254,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 38 unmodified lines | ||
| 249 | 254 | func = tryfuncTM(L, func); /* check the `function' tag method */ |
| 250 | 255 | funcr = savestack(L, func); |
| 251 | 256 | cl = &clvalue(func)->l; |
| 257 | + L->ci->savedpc = L->savedpc; | |
| 252 | 258 | if (!cl->isC) { /* Lua function? prepare its call */ |
| 253 | 259 | CallInfo *ci; |
| 254 | 260 | StkId st, base; |
| @@ -269,7 +275,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 14 unmodified lines | ||
| 269 | 275 | L->base = ci->base = base; |
| 270 | 276 | ci->top = L->base + p->maxstacksize; |
| 271 | 277 | lua_assert(ci->top <= L->stack_last); |
| 272 | − ci->savedpc = p->code; /* starting point */ | |
| 278 | + L->savedpc = p->code; /* starting point */ | |
| 273 | 279 | ci->tailcalls = 0; |
| 274 | 280 | ci->nresults = nresults; |
| 275 | 281 | for (st = L->top; st < ci->top; st++) |
| @@ -321,6 +327,7 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { · 45 unmodified lines | ||
| 321 | 327 | res = L->ci->func; /* res == final position of 1st result */ |
| 322 | 328 | L->ci--; |
| 323 | 329 | L->base = L->ci->base; /* restore base */ |
| 330 | + L->savedpc = L->ci->savedpc; /* restore savedpc */ | |
| 324 | 331 | /* move results to correct place */ |
| 325 | 332 | while (wanted != 0 && firstResult < L->top) { |
| 326 | 333 | setobjs2s(L, res++, firstResult++); |
| @@ -339,10 +346,10 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { · 12 unmodified lines | ||
| 339 | 346 | ** function position. |
| 340 | 347 | */ |
| 341 | 348 | void luaD_call (lua_State *L, StkId func, int nResults) { |
| 342 | − if (++L->nCcalls >= LUA_MAXCCALLS) { | |
| 343 | − if (L->nCcalls == LUA_MAXCCALLS) | |
| 349 | + if (++L->nCcalls >= LUAI_MAXCCALLS) { | |
| 350 | + if (L->nCcalls == LUAI_MAXCCALLS) | |
| 344 | 351 | luaG_runerror(L, "C stack overflow"); |
| 345 | − else if (L->nCcalls >= (LUA_MAXCCALLS + (LUA_MAXCCALLS>>3))) | |
| 352 | + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) | |
| 346 | 353 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ |
| 347 | 354 | } |
| 348 | 355 | if (luaD_precall(L, func, nResults) == PCRLUA) { /* is a Lua function? */ |
| @@ -434,7 +441,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { · 85 unmodified lines | ||
| 434 | 441 | int luaD_pcall (lua_State *L, Pfunc func, void *u, |
| 435 | 442 | ptrdiff_t old_top, ptrdiff_t ef) { |
| 436 | 443 | int status; |
| 437 | − unsigned short oldnCcalls = L->nCcalls; | |
| 444 | + int oldnCcalls = L->nCcalls; | |
| 438 | 445 | ptrdiff_t old_ci = saveci(L, L->ci); |
| 439 | 446 | lu_byte old_allowhooks = L->allowhook; |
| 440 | 447 | ptrdiff_t old_errfunc = L->errfunc; |
| @@ -447,6 +454,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, · 6 unmodified lines | ||
| 447 | 454 | L->nCcalls = oldnCcalls; |
| 448 | 455 | L->ci = restoreci(L, old_ci); |
| 449 | 456 | L->base = L->ci->base; |
| 457 | + L->savedpc = L->ci->savedpc; | |
| 450 | 458 | L->allowhook = old_allowhooks; |
| 451 | 459 | restore_stack_limit(L); |
| 452 | 460 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldo.h,v 2.3 2004/09/08 14:23:09 roberto Exp $ | |
| 2 | +** $Id: ldo.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Stack and Call structure of Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -47,20 +47,20 @@ · 41 unmodified lines | ||
| 47 | 47 | /* type of protected functions, to be ran by `runprotected' */ |
| 48 | 48 | typedef void (*Pfunc) (lua_State *L, void *ud); |
| 49 | 49 | |
| 50 | −void luaD_resetprotection (lua_State *L); | |
| 51 | −int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); | |
| 52 | −void luaD_callhook (lua_State *L, int event, int line); | |
| 53 | −int luaD_precall (lua_State *L, StkId func, int nresults); | |
| 54 | −void luaD_call (lua_State *L, StkId func, int nResults); | |
| 55 | −int luaD_pcall (lua_State *L, Pfunc func, void *u, | |
| 56 | − ptrdiff_t oldtop, ptrdiff_t ef); | |
| 57 | −void luaD_poscall (lua_State *L, int wanted, StkId firstResult); | |
| 58 | −void luaD_reallocCI (lua_State *L, int newsize); | |
| 59 | −void luaD_reallocstack (lua_State *L, int newsize); | |
| 60 | −void luaD_growstack (lua_State *L, int n); | |
| 50 | +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); | |
| 51 | +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); | |
| 52 | +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); | |
| 53 | +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); | |
| 54 | +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, | |
| 55 | + ptrdiff_t oldtop, ptrdiff_t ef); | |
| 56 | +LUAI_FUNC void luaD_poscall (lua_State *L, int wanted, StkId firstResult); | |
| 57 | +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); | |
| 58 | +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); | |
| 59 | +LUAI_FUNC void luaD_growstack (lua_State *L, int n); | |
| 61 | 60 | |
| 62 | −void luaD_throw (lua_State *L, int errcode); | |
| 63 | −int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); | |
| 61 | +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); | |
| 62 | +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); | |
| 64 | 63 | |
| 65 | 64 | |
| 66 | 65 | #endif |
| 66 | + | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldump.c,v 1.9 2004/11/25 09:31:41 lhf Exp $ | |
| 2 | +** $Id: ldump.c,v 1.10 2005/05/12 00:26:50 lhf Exp $ | |
| 3 | 3 | ** save pre-compiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -136,7 +136,8 @@ static void DumpConstants(const Proto* f, DumpState* D) · 130 unmodified lines | ||
| 136 | 136 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D) |
| 137 | 137 | { |
| 138 | 138 | DumpString((f->source==p) ? NULL : f->source,D); |
| 139 | − DumpInt(f->lineDefined,D); | |
| 139 | + DumpInt(f->linedefined,D); | |
| 140 | + DumpInt(f->lastlinedefined,D); | |
| 140 | 141 | DumpByte(f->nups,D); |
| 141 | 142 | DumpByte(f->numparams,D); |
| 142 | 143 | DumpByte(f->is_vararg,D); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lfunc.c,v 2.9 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -105,10 +105,6 @@ void luaF_close (lua_State *L, StkId level) { · 99 unmodified lines | ||
| 105 | 105 | else { |
| 106 | 106 | unlinkupval(uv); |
| 107 | 107 | setobj(L, &uv->u.value, uv->v); |
| 108 | − if (isgray(o)) { | |
| 109 | − gray2black(o); /* closed upvalues are never gray */ | |
| 110 | − luaC_barrier(L, uv, &uv->u.value); | |
| 111 | − } | |
| 112 | 108 | uv->v = &uv->u.value; /* now current value lives here */ |
| 113 | 109 | luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ |
| 114 | 110 | } |
| @@ -135,7 +131,8 @@ Proto *luaF_newproto (lua_State *L) { · 20 unmodified lines | ||
| 135 | 131 | f->lineinfo = NULL; |
| 136 | 132 | f->sizelocvars = 0; |
| 137 | 133 | f->locvars = NULL; |
| 138 | − f->lineDefined = 0; | |
| 134 | + f->linedefined = 0; | |
| 135 | + f->lastlinedefined = 0; | |
| 139 | 136 | f->source = NULL; |
| 140 | 137 | return f; |
| 141 | 138 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lfunc.h,v 2.3 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -18,17 +18,17 @@ · 12 unmodified lines | ||
| 18 | 18 | cast(int, sizeof(TValue *)*((n)-1))) |
| 19 | 19 | |
| 20 | 20 | |
| 21 | −Proto *luaF_newproto (lua_State *L); | |
| 22 | −Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); | |
| 23 | −Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); | |
| 24 | −UpVal *luaF_newupval (lua_State *L); | |
| 25 | −UpVal *luaF_findupval (lua_State *L, StkId level); | |
| 26 | −void luaF_close (lua_State *L, StkId level); | |
| 27 | −void luaF_freeproto (lua_State *L, Proto *f); | |
| 28 | −void luaF_freeclosure (lua_State *L, Closure *c); | |
| 29 | −void luaF_freeupval (lua_State *L, UpVal *uv); | |
| 30 | − | |
| 31 | −const char *luaF_getlocalname (const Proto *func, int local_number, int pc); | |
| 21 | +LUAI_FUNC Proto *luaF_newproto (lua_State *L); | |
| 22 | +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); | |
| 23 | +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); | |
| 24 | +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); | |
| 25 | +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); | |
| 26 | +LUAI_FUNC void luaF_close (lua_State *L, StkId level); | |
| 27 | +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); | |
| 28 | +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); | |
| 29 | +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); | |
| 30 | +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, | |
| 31 | + int pc); | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lgc.c,v 2.27 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lgc.c,v 2.32 2005/05/05 15:34:03 roberto Exp $ | |
| 3 | 3 | ** Garbage Collector |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -57,7 +57,7 @@ · 51 unmodified lines | ||
| 57 | 57 | reallymarkobject(g, obj2gco(t)); } |
| 58 | 58 | |
| 59 | 59 | |
| 60 | −#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpace) | |
| 60 | +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | static void removeentry (Node *n) { |
| @@ -242,7 +242,7 @@ static void traverseclosure (global_State *g, Closure *cl) { · 178 unmodified lines | ||
| 242 | 242 | static void checkstacksizes (lua_State *L, StkId max) { |
| 243 | 243 | int ci_used = L->ci - L->base_ci; /* number of `ci' in use */ |
| 244 | 244 | int s_used = max - L->stack; /* part of stack in use */ |
| 245 | − if (L->size_ci > LUA_MAXCALLS) /* handling overflow? */ | |
| 245 | + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ | |
| 246 | 246 | return; /* do not touch the stacks */ |
| 247 | 247 | if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) |
| 248 | 248 | luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ |
| @@ -493,6 +493,13 @@ void luaC_freeall (lua_State *L) { · 244 unmodified lines | ||
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | |
| 496 | +static void markmt (global_State *g) { | |
| 497 | + int i; | |
| 498 | + for (i=0; i<NUM_TAGS; i++) | |
| 499 | + if (g->mt[i]) markobject(g, g->mt[i]); | |
| 500 | +} | |
| 501 | + | |
| 502 | + | |
| 496 | 503 | /* mark root set */ |
| 497 | 504 | static void markroot (lua_State *L) { |
| 498 | 505 | global_State *g = G(L); |
| @@ -503,6 +510,7 @@ static void markroot (lua_State *L) { · 4 unmodified lines | ||
| 503 | 510 | /* make global table be traversed before main stack */ |
| 504 | 511 | markvalue(g, gt(g->mainthread)); |
| 505 | 512 | markvalue(g, registry(L)); |
| 513 | + markmt(g); | |
| 506 | 514 | g->gcstate = GCSpropagate; |
| 507 | 515 | } |
| 508 | 516 | |
| @@ -529,6 +537,7 @@ static void atomic (lua_State *L) { · 20 unmodified lines | ||
| 529 | 537 | g->weak = NULL; |
| 530 | 538 | lua_assert(!iswhite(obj2gco(g->mainthread))); |
| 531 | 539 | markobject(g, L); /* mark running thread */ |
| 540 | + markmt(g); /* mark basic metatables (again) */ | |
| 532 | 541 | propagateall(g); |
| 533 | 542 | /* remark gray again */ |
| 534 | 543 | g->gray = g->grayagain; |
| @@ -539,7 +548,7 @@ static void atomic (lua_State *L) { · 4 unmodified lines | ||
| 539 | 548 | propagateall(g); /* remark, to propagate `preserveness' */ |
| 540 | 549 | cleartable(g->weak); /* remove collected objects from weak tables */ |
| 541 | 550 | /* flip current white */ |
| 542 | − g->currentwhite = otherwhite(g); | |
| 551 | + g->currentwhite = cast(lu_byte, otherwhite(g)); | |
| 543 | 552 | g->sweepstrgc = 0; |
| 544 | 553 | g->sweepgc = &g->rootgc; |
| 545 | 554 | g->gcstate = GCSsweepstring; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lgc.h,v 2.12 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lgc.h,v 2.13 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Garbage Collector |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -95,15 +95,15 @@ · 89 unmodified lines | ||
| 95 | 95 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ |
| 96 | 96 | luaC_barrierback(L,obj2gco(p)); } |
| 97 | 97 | |
| 98 | −size_t luaC_separateudata (lua_State *L, int all); | |
| 99 | −void luaC_callGCTM (lua_State *L); | |
| 100 | −void luaC_freeall (lua_State *L); | |
| 101 | −void luaC_step (lua_State *L); | |
| 102 | −void luaC_fullgc (lua_State *L); | |
| 103 | −void luaC_link (lua_State *L, GCObject *o, lu_byte tt); | |
| 104 | −void luaC_linkupval (lua_State *L, UpVal *uv); | |
| 105 | −void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); | |
| 106 | −void luaC_barrierback (lua_State *L, GCObject *o); | |
| 98 | +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); | |
| 99 | +LUAI_FUNC void luaC_callGCTM (lua_State *L); | |
| 100 | +LUAI_FUNC void luaC_freeall (lua_State *L); | |
| 101 | +LUAI_FUNC void luaC_step (lua_State *L); | |
| 102 | +LUAI_FUNC void luaC_fullgc (lua_State *L); | |
| 103 | +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); | |
| 104 | +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); | |
| 105 | +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); | |
| 106 | +LUAI_FUNC void luaC_barrierback (lua_State *L, GCObject *o); | |
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: linit.c,v 1.9 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: linit.c,v 1.11 2005/04/13 17:24:20 roberto Exp $ | |
| 3 | 3 | ** Initialization of libraries for lua.c |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -22,19 +22,17 @@ static const luaL_reg lualibs[] = { · 16 unmodified lines | ||
| 22 | 22 | {LUA_STRLIBNAME, luaopen_string}, |
| 23 | 23 | {LUA_MATHLIBNAME, luaopen_math}, |
| 24 | 24 | {LUA_DBLIBNAME, luaopen_debug}, |
| 25 | − {"", luaopen_loadlib}, | |
| 25 | + {LUA_LOADLIBNAME, luaopen_loadlib}, | |
| 26 | 26 | {NULL, NULL} |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | 29 | |
| 30 | −LUALIB_API int luaopen_stdlibs (lua_State *L) { | |
| 30 | +LUALIB_API void luaL_openlibs (lua_State *L) { | |
| 31 | 31 | const luaL_reg *lib = lualibs; |
| 32 | 32 | for (; lib->func; lib++) { |
| 33 | − lib->func(L); /* open library */ | |
| 34 | − lua_settop(L, 0); /* discard any results */ | |
| 35 | − lua_pushvalue(L, LUA_GLOBALSINDEX); | |
| 36 | − lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ | |
| 33 | + lua_pushcfunction(L, lib->func); | |
| 34 | + lua_pushstring(L, lib->name); | |
| 35 | + lua_call(L, 1, 0); | |
| 37 | 36 | } |
| 38 | − return 0; | |
| 39 | 37 | } |
| 40 | 38 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: liolib.c,v 2.58 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: liolib.c,v 2.60 2005/05/16 21:19:00 roberto Exp $ | |
| 3 | 3 | ** Standard I/O (and system) library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -191,9 +191,9 @@ static int io_output (lua_State *L) { · 185 unmodified lines | ||
| 191 | 191 | static int io_readline (lua_State *L); |
| 192 | 192 | |
| 193 | 193 | |
| 194 | −static void aux_lines (lua_State *L, int idx, int close) { | |
| 194 | +static void aux_lines (lua_State *L, int idx, int toclose) { | |
| 195 | 195 | lua_pushvalue(L, idx); |
| 196 | − lua_pushboolean(L, close); /* close/not close file when finished */ | |
| 196 | + lua_pushboolean(L, toclose); /* close/not close file when finished */ | |
| 197 | 197 | lua_pushcclosure(L, io_readline, 2); |
| 198 | 198 | } |
| 199 | 199 | |
| @@ -319,8 +319,6 @@ static int g_read (lua_State *L, FILE *f, int first) { · 119 unmodified lines | ||
| 319 | 319 | read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ |
| 320 | 320 | success = 1; /* always success */ |
| 321 | 321 | break; |
| 322 | − case 'w': /* word */ | |
| 323 | − return luaL_error(L, "obsolete option `*w' to `read'"); | |
| 324 | 322 | default: |
| 325 | 323 | return luaL_argerror(L, n, "invalid format"); |
| 326 | 324 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llex.c,v 2.9 2004/12/03 20:54:12 roberto Exp $ | |
| 2 | +** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lexical Analyzer |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -102,7 +102,7 @@ void luaX_lexerror (LexState *ls, const char *msg, int token) { · 96 unmodified lines | ||
| 102 | 102 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); |
| 103 | 103 | msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); |
| 104 | 104 | if (token) |
| 105 | − luaO_pushfstring(ls->L, "%s near `%s'", msg, txtToken(ls, token)); | |
| 105 | + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); | |
| 106 | 106 | luaD_throw(ls->L, LUA_ERRSYNTAX); |
| 107 | 107 | } |
| 108 | 108 | |
| @@ -202,6 +202,7 @@ static int skip_sep (LexState *ls) { · 93 unmodified lines | ||
| 202 | 202 | |
| 203 | 203 | static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { |
| 204 | 204 | int cont = 0; |
| 205 | + (void)(cont); /* avoid warnings when `cont' is not used */ | |
| 205 | 206 | save_and_next(ls); /* skip 2nd `[' */ |
| 206 | 207 | if (currIsNewline(ls)) /* string starts with a newline? */ |
| 207 | 208 | inclinenumber(ls); /* skip it */ |
| @@ -211,27 +212,41 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { · 3 unmodified lines | ||
| 211 | 212 | luaX_lexerror(ls, (seminfo) ? "unfinished long string" : |
| 212 | 213 | "unfinished long comment", TK_EOS); |
| 213 | 214 | break; /* to avoid warnings */ |
| 214 | − case '[': | |
| 215 | +#if defined(LUA_COMPAT_LSTR) | |
| 216 | + case '[': { | |
| 215 | 217 | if (skip_sep(ls) == sep) { |
| 216 | 218 | save_and_next(ls); /* skip 2nd `[' */ |
| 217 | 219 | cont++; |
| 220 | +#if LUA_COMPAT_LSTR == 1 | |
| 221 | + if (sep == 0) | |
| 222 | + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); | |
| 223 | +#endif | |
| 218 | 224 | } |
| 219 | − continue; | |
| 220 | − case ']': | |
| 225 | + break; | |
| 226 | + } | |
| 227 | +#endif | |
| 228 | + case ']': { | |
| 221 | 229 | if (skip_sep(ls) == sep) { |
| 222 | 230 | save_and_next(ls); /* skip 2nd `]' */ |
| 223 | − if (cont-- == 0) goto endloop; | |
| 231 | +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 | |
| 232 | + cont--; | |
| 233 | + if (sep == 0 && cont >= 0) break; | |
| 234 | +#endif | |
| 235 | + goto endloop; | |
| 224 | 236 | } |
| 225 | − continue; | |
| 237 | + break; | |
| 238 | + } | |
| 226 | 239 | case '\n': |
| 227 | − case '\r': | |
| 240 | + case '\r': { | |
| 228 | 241 | save(ls, '\n'); |
| 229 | 242 | inclinenumber(ls); |
| 230 | 243 | if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ |
| 231 | − continue; | |
| 232 | − default: | |
| 244 | + break; | |
| 245 | + } | |
| 246 | + default: { | |
| 233 | 247 | if (seminfo) save_and_next(ls); |
| 234 | 248 | else next(ls); |
| 249 | + } | |
| 235 | 250 | } |
| 236 | 251 | } endloop: |
| 237 | 252 | if (seminfo) |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llex.h,v 1.52 2004/12/03 20:54:12 roberto Exp $ | |
| 2 | +** $Id: llex.h,v 1.54 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Lexical Analyzer |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -63,17 +63,17 @@ typedef struct LexState { · 57 unmodified lines | ||
| 63 | 63 | ZIO *z; /* input stream */ |
| 64 | 64 | Mbuffer *buff; /* buffer for tokens */ |
| 65 | 65 | TString *source; /* current source name */ |
| 66 | − int nestlevel; /* level of nested non-terminals */ | |
| 67 | 66 | } LexState; |
| 68 | 67 | |
| 69 | 68 | |
| 70 | −void luaX_init (lua_State *L); | |
| 71 | −void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); | |
| 72 | −TString *luaX_newstring (LexState *LS, const char *str, size_t l); | |
| 73 | −int luaX_lex (LexState *LS, SemInfo *seminfo); | |
| 74 | −void luaX_lexerror (LexState *ls, const char *msg, int token); | |
| 75 | −void luaX_syntaxerror (LexState *ls, const char *s); | |
| 76 | −const char *luaX_token2str (LexState *ls, int token); | |
| 69 | +LUAI_FUNC void luaX_init (lua_State *L); | |
| 70 | +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, | |
| 71 | + TString *source); | |
| 72 | +LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l); | |
| 73 | +LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo); | |
| 74 | +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); | |
| 75 | +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); | |
| 76 | +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); | |
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llimits.h,v 1.63 2005/01/14 14:19:42 roberto Exp $ | |
| 2 | +** $Id: llimits.h,v 1.65 2005/03/09 16:28:07 roberto Exp $ | |
| 3 | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -15,12 +15,14 @@ · 9 unmodified lines | ||
| 15 | 15 | #include "lua.h" |
| 16 | 16 | |
| 17 | 17 | |
| 18 | +#define api_check luai_apicheck | |
| 18 | 19 | |
| 19 | −typedef LUA_UINT32 lu_int32; | |
| 20 | 20 | |
| 21 | −typedef LU_MEM lu_mem; | |
| 21 | +typedef LUAI_UINT32 lu_int32; | |
| 22 | 22 | |
| 23 | −typedef L_MEM l_mem; | |
| 23 | +typedef LUAI_UMEM lu_mem; | |
| 24 | + | |
| 25 | +typedef LUAI_MEM l_mem; | |
| 24 | 26 | |
| 25 | 27 | |
| 26 | 28 | |
| @@ -45,11 +47,11 @@ typedef unsigned char lu_byte; · 18 unmodified lines | ||
| 45 | 47 | |
| 46 | 48 | |
| 47 | 49 | /* type to ensure maximum alignment */ |
| 48 | −typedef LUSER_ALIGNMENT_T L_Umaxalign; | |
| 50 | +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; | |
| 49 | 51 | |
| 50 | 52 | |
| 51 | 53 | /* result of a `usual argument conversion' over lua_Number */ |
| 52 | −typedef LUA_UACNUMBER l_uacNumber; | |
| 54 | +typedef LUAI_UACNUMBER l_uacNumber; | |
| 53 | 55 | |
| 54 | 56 | |
| 55 | 57 | #define check_exp(c,e) (lua_assert(c), (e)) |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lmathlib.c,v 1.62 2005/01/07 20:00:33 roberto Exp $ | |
| 2 | +** $Id: lmathlib.c,v 1.63 2005/03/04 18:57:03 roberto Exp $ | |
| 3 | 3 | ** Standard mathematical library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -33,16 +33,31 @@ static int math_sin (lua_State *L) { · 27 unmodified lines | ||
| 33 | 33 | return 1; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | +static int math_sinh (lua_State *L) { | |
| 37 | + lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); | |
| 38 | + return 1; | |
| 39 | +} | |
| 40 | + | |
| 36 | 41 | static int math_cos (lua_State *L) { |
| 37 | 42 | lua_pushnumber(L, cos(luaL_checknumber(L, 1))); |
| 38 | 43 | return 1; |
| 39 | 44 | } |
| 40 | 45 | |
| 46 | +static int math_cosh (lua_State *L) { | |
| 47 | + lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); | |
| 48 | + return 1; | |
| 49 | +} | |
| 50 | + | |
| 41 | 51 | static int math_tan (lua_State *L) { |
| 42 | 52 | lua_pushnumber(L, tan(luaL_checknumber(L, 1))); |
| 43 | 53 | return 1; |
| 44 | 54 | } |
| 45 | 55 | |
| 56 | +static int math_tanh (lua_State *L) { | |
| 57 | + lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); | |
| 58 | + return 1; | |
| 59 | +} | |
| 60 | + | |
| 46 | 61 | static int math_asin (lua_State *L) { |
| 47 | 62 | lua_pushnumber(L, asin(luaL_checknumber(L, 1))); |
| 48 | 63 | return 1; |
| @@ -78,6 +93,14 @@ static int math_mod (lua_State *L) { · 29 unmodified lines | ||
| 78 | 93 | return 1; |
| 79 | 94 | } |
| 80 | 95 | |
| 96 | +static int math_modf (lua_State *L) { | |
| 97 | + double ip; | |
| 98 | + double fp = modf(luaL_checknumber(L, 1), &ip); | |
| 99 | + lua_pushnumber(L, ip); | |
| 100 | + lua_pushnumber(L, fp); | |
| 101 | + return 2; | |
| 102 | +} | |
| 103 | + | |
| 81 | 104 | static int math_sqrt (lua_State *L) { |
| 82 | 105 | lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); |
| 83 | 106 | return 1; |
| @@ -192,8 +215,11 @@ static int math_randomseed (lua_State *L) { · 108 unmodified lines | ||
| 192 | 215 | static const luaL_reg mathlib[] = { |
| 193 | 216 | {"abs", math_abs}, |
| 194 | 217 | {"sin", math_sin}, |
| 218 | + {"sinh", math_sinh}, | |
| 195 | 219 | {"cos", math_cos}, |
| 220 | + {"cosh", math_cosh}, | |
| 196 | 221 | {"tan", math_tan}, |
| 222 | + {"tanh", math_tanh}, | |
| 197 | 223 | {"asin", math_asin}, |
| 198 | 224 | {"acos", math_acos}, |
| 199 | 225 | {"atan", math_atan}, |
| @@ -201,6 +227,7 @@ static const luaL_reg mathlib[] = { · 1 unmodified line | ||
| 201 | 227 | {"ceil", math_ceil}, |
| 202 | 228 | {"floor", math_floor}, |
| 203 | 229 | {"mod", math_mod}, |
| 230 | + {"modf", math_modf}, | |
| 204 | 231 | {"frexp", math_frexp}, |
| 205 | 232 | {"ldexp", math_ldexp}, |
| 206 | 233 | {"sqrt", math_sqrt}, |
| @@ -225,6 +252,8 @@ LUALIB_API int luaopen_math (lua_State *L) { · 18 unmodified lines | ||
| 225 | 252 | luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0); |
| 226 | 253 | lua_pushnumber(L, PI); |
| 227 | 254 | lua_setfield(L, -2, "pi"); |
| 255 | + lua_pushnumber(L, HUGE_VAL); | |
| 256 | + lua_setfield(L, -2, "huge"); | |
| 228 | 257 | return 1; |
| 229 | 258 | } |
| 230 | 259 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lmem.h,v 1.29 2004/12/01 15:46:18 roberto Exp $ | |
| 2 | +** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Interface to Memory Manager |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -16,18 +16,10 @@ · 10 unmodified lines | ||
| 16 | 16 | #define MEMERRMSG "not enough memory" |
| 17 | 17 | |
| 18 | 18 | |
| 19 | −void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size); | |
| 20 | − | |
| 21 | −void *luaM_toobig (lua_State *L); | |
| 22 | − | |
| 23 | 19 | #define luaM_reallocv(L,b,on,n,e) \ |
| 24 | − ((cast(unsigned int, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ | |
| 25 | − luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ | |
| 26 | − luaM_toobig(L)) | |
| 27 | − | |
| 28 | − | |
| 29 | −void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem, | |
| 30 | − int limit, const char *errormsg); | |
| 20 | + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ | |
| 21 | + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ | |
| 22 | + luaM_toobig(L)) | |
| 31 | 23 | |
| 32 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) |
| 33 | 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) |
| @@ -46,5 +38,12 @@ void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem, · 12 unmodified lines | ||
| 46 | 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) |
| 47 | 39 | |
| 48 | 40 | |
| 41 | +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, | |
| 42 | + size_t size); | |
| 43 | +LUAI_FUNC void *luaM_toobig (lua_State *L); | |
| 44 | +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, | |
| 45 | + size_t size_elem, int limit, | |
| 46 | + const char *errormsg); | |
| 47 | + | |
| 49 | 48 | #endif |
| 50 | 49 | |
| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loadlib.c,v 1.18 2005/02/28 15:58:48 roberto Exp $ | |
| 2 | +** $Id: loadlib.c,v 1.28 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Dynamic library loader for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | −* | |
| 6 | −* This module contains an implementation of loadlib for Unix systems | |
| 7 | −* that have dlfcn, an implementation for Darwin (Mac OS X), an | |
| 8 | −* implementation for Windows, and a stub for other systems. | |
| 5 | +** | |
| 6 | +** This module contains an implementation of loadlib for Unix systems | |
| 7 | +** that have dlfcn, an implementation for Darwin (Mac OS X), an | |
| 8 | +** implementation for Windows, and a stub for other systems. | |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | |
| @@ -21,6 +21,17 @@ · 9 unmodified lines | ||
| 21 | 21 | #include "lualib.h" |
| 22 | 22 | |
| 23 | 23 | |
| 24 | +/* environment variables that hold the search path for packages */ | |
| 25 | +#define LUA_PATH "LUA_PATH" | |
| 26 | +#define LUA_CPATH "LUA_CPATH" | |
| 27 | + | |
| 28 | +/* prefix for open functions in C libraries */ | |
| 29 | +#define LUA_POF "luaopen_" | |
| 30 | + | |
| 31 | +/* separator for open functions in C libraries */ | |
| 32 | +#define LUA_OFSEP "_" | |
| 33 | + | |
| 34 | + | |
| 24 | 35 | #define LIBPREFIX "LOADLIB: " |
| 25 | 36 | |
| 26 | 37 | #define POF LUA_POF |
| @@ -33,7 +44,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); · 6 unmodified lines | ||
| 33 | 44 | |
| 34 | 45 | |
| 35 | 46 | |
| 36 | −#if defined(USE_DLOPEN) | |
| 47 | +#if defined(LUA_DL_DLOPEN) | |
| 37 | 48 | /* |
| 38 | 49 | ** {======================================================================== |
| 39 | 50 | ** This is an implementation of loadlib based on the dlfcn interface. |
| @@ -67,7 +78,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 27 unmodified lines | ||
| 67 | 78 | |
| 68 | 79 | |
| 69 | 80 | |
| 70 | −#elif defined(USE_DLL) | |
| 81 | +#elif defined(LUA_DL_DLL) | |
| 71 | 82 | /* |
| 72 | 83 | ** {====================================================================== |
| 73 | 84 | ** This is an implementation of loadlib for Windows using native functions. |
| @@ -82,7 +93,7 @@ static void pusherror (lua_State *L) { · 8 unmodified lines | ||
| 82 | 93 | char buffer[128]; |
| 83 | 94 | if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, |
| 84 | 95 | NULL, error, 0, buffer, sizeof(buffer), NULL)) |
| 85 | − lua_pushstring(L,buffer); | |
| 96 | + lua_pushstring(L, buffer); | |
| 86 | 97 | else |
| 87 | 98 | lua_pushfstring(L, "system error %d\n", error); |
| 88 | 99 | } |
| @@ -109,7 +120,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 20 unmodified lines | ||
| 109 | 120 | |
| 110 | 121 | |
| 111 | 122 | |
| 112 | −#elif defined(USE_DYLD) | |
| 123 | +#elif defined(LUA_DL_DYLD) | |
| 113 | 124 | /* |
| 114 | 125 | ** {====================================================================== |
| 115 | 126 | ** Native Mac OS X / Darwin Implementation |
| @@ -119,6 +130,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 3 unmodified lines | ||
| 119 | 130 | #include <mach-o/dyld.h> |
| 120 | 131 | |
| 121 | 132 | |
| 133 | +/* Mac appends a `_' before C function names */ | |
| 122 | 134 | #undef POF |
| 123 | 135 | #define POF "_" LUA_POF |
| 124 | 136 | |
| @@ -179,7 +191,7 @@ static void *ll_load (lua_State *L, const char *path) { · 54 unmodified lines | ||
| 179 | 191 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { |
| 180 | 192 | NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); |
| 181 | 193 | if (nss == NULL) { |
| 182 | − lua_pushfstring(L, "symbol `%s' not found", sym); | |
| 194 | + lua_pushfstring(L, "symbol " LUA_QS " not found", sym); | |
| 183 | 195 | return NULL; |
| 184 | 196 | } |
| 185 | 197 | return (lua_CFunction)NSAddressOfSymbol(nss); |
| @@ -200,6 +212,12 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 14 unmodified lines | ||
| 200 | 212 | #define LIB_FAIL "absent" |
| 201 | 213 | |
| 202 | 214 | |
| 215 | +#if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux) | |
| 216 | +#define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation" | |
| 217 | +#else | |
| 218 | +#define DLMSG LUA_QL("loadlib") " not supported" | |
| 219 | +#endif | |
| 220 | + | |
| 203 | 221 | static void ll_unloadlib (void *lib) { |
| 204 | 222 | (void)lib; /* to avoid warnings */ |
| 205 | 223 | } |
| @@ -207,14 +225,14 @@ static void ll_unloadlib (void *lib) { · 1 unmodified line | ||
| 207 | 225 | |
| 208 | 226 | static void *ll_load (lua_State *L, const char *path) { |
| 209 | 227 | (void)path; /* to avoid warnings */ |
| 210 | − lua_pushliteral(L,"`loadlib' not supported"); | |
| 228 | + lua_pushliteral(L, DLMSG); | |
| 211 | 229 | return NULL; |
| 212 | 230 | } |
| 213 | 231 | |
| 214 | 232 | |
| 215 | 233 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { |
| 216 | 234 | (void)lib; (void)sym; /* to avoid warnings */ |
| 217 | − lua_pushliteral(L,"`loadlib' not supported"); | |
| 235 | + lua_pushliteral(L, DLMSG); | |
| 218 | 236 | return NULL; |
| 219 | 237 | } |
| 220 | 238 | |
| @@ -296,22 +314,25 @@ static int ll_loadlib (lua_State *L) { · 75 unmodified lines | ||
| 296 | 314 | static int loader_Lua (lua_State *L) { |
| 297 | 315 | const char *name = luaL_checkstring(L, 1); |
| 298 | 316 | const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP); |
| 299 | − const char *path; | |
| 317 | + const char *path = NULL; | |
| 318 | +#if LUA_COMPAT_PATH | |
| 300 | 319 | /* try first `LUA_PATH' for compatibility */ |
| 301 | 320 | lua_pushstring(L, "LUA_PATH"); |
| 302 | 321 | lua_rawget(L, LUA_GLOBALSINDEX); |
| 303 | 322 | path = lua_tostring(L, -1); |
| 323 | +#endif | |
| 304 | 324 | if (!path) { |
| 305 | 325 | lua_pop(L, 1); |
| 306 | 326 | lua_getfield(L, LUA_ENVIRONINDEX, "path"); |
| 307 | 327 | path = lua_tostring(L, -1); |
| 308 | 328 | } |
| 309 | 329 | if (path == NULL) |
| 310 | − luaL_error(L, "`package.path' must be a string"); | |
| 330 | + luaL_error(L, LUA_QL("package.path") " must be a string"); | |
| 311 | 331 | fname = luaL_searchpath(L, fname, path); |
| 312 | 332 | if (fname == NULL) return 0; /* library not found in this path */ |
| 313 | 333 | if (luaL_loadfile(L, fname) != 0) |
| 314 | − luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); | |
| 334 | + luaL_error(L, "error loading package " LUA_QS " (%s)", | |
| 335 | + name, lua_tostring(L, -1)); | |
| 315 | 336 | return 1; /* library loaded successfully */ |
| 316 | 337 | } |
| 317 | 338 | |
| @@ -324,13 +345,14 @@ static int loader_C (lua_State *L) { · 6 unmodified lines | ||
| 324 | 345 | lua_getfield(L, LUA_ENVIRONINDEX, "cpath"); |
| 325 | 346 | path = lua_tostring(L, -1); |
| 326 | 347 | if (path == NULL) |
| 327 | − luaL_error(L, "`package.cpath' must be a string"); | |
| 348 | + luaL_error(L, LUA_QL("package.cpath") " must be a string"); | |
| 328 | 349 | fname = luaL_searchpath(L, fname, path); |
| 329 | 350 | if (fname == NULL) return 0; /* library not found in this path */ |
| 330 | 351 | funcname = luaL_gsub(L, name, ".", LUA_OFSEP); |
| 331 | 352 | funcname = lua_pushfstring(L, "%s%s", POF, funcname); |
| 332 | 353 | if (ll_loadfunc(L, fname, funcname) != 1) |
| 333 | − luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -2)); | |
| 354 | + luaL_error(L, "error loading package " LUA_QS " (%s)", | |
| 355 | + name, lua_tostring(L, -2)); | |
| 334 | 356 | return 1; /* library loaded successfully */ |
| 335 | 357 | } |
| 336 | 358 | |
| @@ -338,7 +360,7 @@ static int loader_C (lua_State *L) { · 1 unmodified line | ||
| 338 | 360 | static int loader_preload (lua_State *L) { |
| 339 | 361 | lua_getfield(L, LUA_ENVIRONINDEX, "preload"); |
| 340 | 362 | if (!lua_istable(L, -1)) |
| 341 | − luaL_error(L, "`package.preload' must be a table"); | |
| 363 | + luaL_error(L, LUA_QL("package.preload") " must be a table"); | |
| 342 | 364 | lua_getfield(L, -1, luaL_checkstring(L, 1)); |
| 343 | 365 | return 1; |
| 344 | 366 | } |
| @@ -358,11 +380,11 @@ static int ll_require (lua_State *L) { · 13 unmodified lines | ||
| 358 | 380 | /* iterate over available loaders */ |
| 359 | 381 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); |
| 360 | 382 | if (!lua_istable(L, -1)) |
| 361 | − luaL_error(L, "`package.loaders' must be a table"); | |
| 383 | + luaL_error(L, LUA_QL("package.loaders") " must be a table"); | |
| 362 | 384 | for (i=1;; i++) { |
| 363 | 385 | lua_rawgeti(L, -1, i); /* get a loader */ |
| 364 | 386 | if (lua_isnil(L, -1)) |
| 365 | − return luaL_error(L, "package `%s' not found", name); | |
| 387 | + return luaL_error(L, "package " LUA_QS " not found", name); | |
| 366 | 388 | lua_pushstring(L, name); |
| 367 | 389 | lua_call(L, 1, 1); /* call it */ |
| 368 | 390 | if (lua_isnil(L, -1)) lua_pop(L, 1); |
| @@ -401,7 +423,7 @@ static int ll_module (lua_State *L) { · 32 unmodified lines | ||
| 401 | 423 | luaL_setfield(L, LUA_GLOBALSINDEX, modname); |
| 402 | 424 | } |
| 403 | 425 | else if (!lua_istable(L, -1)) |
| 404 | − return luaL_error(L, "name conflict for module `%s'", modname); | |
| 426 | + return luaL_error(L, "name conflict for module " LUA_QS, modname); | |
| 405 | 427 | /* check whether table already has a _NAME field */ |
| 406 | 428 | lua_getfield(L, -1, "_NAME"); |
| 407 | 429 | if (!lua_isnil(L, -1)) /* is table an initialized module? */ |
| @@ -434,7 +456,6 @@ static int ll_module (lua_State *L) { · 26 unmodified lines | ||
| 434 | 456 | |
| 435 | 457 | |
| 436 | 458 | static const luaL_reg ll_funcs[] = { |
| 437 | − {"loadlib", ll_loadlib}, | |
| 438 | 459 | {"require", ll_require}, |
| 439 | 460 | {"module", ll_module}, |
| 440 | 461 | {NULL, NULL} |
| @@ -455,7 +476,7 @@ LUALIB_API int luaopen_loadlib (lua_State *L) { · 14 unmodified lines | ||
| 455 | 476 | /* create `package' table */ |
| 456 | 477 | lua_newtable(L); |
| 457 | 478 | lua_pushvalue(L, -1); |
| 458 | − lua_setglobal(L, "package"); | |
| 479 | + lua_setglobal(L, LUA_LOADLIBNAME); | |
| 459 | 480 | lua_pushvalue(L, -1); |
| 460 | 481 | lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE"); |
| 461 | 482 | lua_pushvalue(L, -1); |
| @@ -485,6 +506,13 @@ LUALIB_API int luaopen_loadlib (lua_State *L) { · 23 unmodified lines | ||
| 485 | 506 | /* set field `preload' */ |
| 486 | 507 | lua_newtable(L); |
| 487 | 508 | lua_setfield(L, -2, "preload"); |
| 509 | + /* create `loadlib' function */ | |
| 510 | + lua_pushcfunction(L, ll_loadlib); | |
| 511 | +#if LUA_COMPAT_LOADLIB | |
| 512 | + lua_pushvalue(L, -1); | |
| 513 | + lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); | |
| 514 | +#endif | |
| 515 | + lua_setfield(L, -2, "loadlib"); | |
| 488 | 516 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 489 | 517 | luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */ |
| 490 | 518 | return 1; |
| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lobject.c,v 2.8 2005/01/10 18:17:39 roberto Exp $ | |
| 2 | +** $Id: lobject.c,v 2.13 2005/05/16 21:19:00 roberto Exp $ | |
| 3 | 3 | ** Some generic functions over Lua objects |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #include <ctype.h> |
| 8 | 8 | #include <stdarg.h> |
| 9 | +#include <stdio.h> | |
| 9 | 10 | #include <stdlib.h> |
| 10 | 11 | #include <string.h> |
| 11 | 12 | |
| @@ -28,7 +29,8 @@ const TValue luaO_nilobject = {{NULL}, LUA_TNIL}; · 16 unmodified lines | ||
| 28 | 29 | |
| 29 | 30 | /* |
| 30 | 31 | ** converts an integer to a "floating point byte", represented as |
| 31 | −** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm) | |
| 32 | +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if | |
| 33 | +** eeeee != 0 and (xxx) otherwise. | |
| 32 | 34 | */ |
| 33 | 35 | int luaO_int2fb (unsigned int x) { |
| 34 | 36 | int e = 0; /* expoent */ |
| @@ -73,7 +75,7 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) { · 38 unmodified lines | ||
| 73 | 75 | case LUA_TNIL: |
| 74 | 76 | return 1; |
| 75 | 77 | case LUA_TNUMBER: |
| 76 | − return num_eq(nvalue(t1), nvalue(t2)); | |
| 78 | + return luai_numeq(nvalue(t1), nvalue(t2)); | |
| 77 | 79 | case LUA_TBOOLEAN: |
| 78 | 80 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ |
| 79 | 81 | case LUA_TLIGHTUSERDATA: |
| @@ -182,7 +184,7 @@ void luaO_chunkid (char *out, const char *source, int bufflen) { · 102 unmodified lines | ||
| 182 | 184 | if (*source == '@') { |
| 183 | 185 | int l; |
| 184 | 186 | source++; /* skip the `@' */ |
| 185 | − bufflen -= sizeof(" `...' "); | |
| 187 | + bufflen -= sizeof(" '...' "); | |
| 186 | 188 | l = strlen(source); |
| 187 | 189 | strcpy(out, ""); |
| 188 | 190 | if (l>bufflen) { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lobject.h,v 2.11 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: lobject.h,v 2.13 2005/05/05 20:47:02 roberto Exp $ | |
| 3 | 3 | ** Type definitions for Lua objects |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -244,7 +244,8 @@ typedef struct Proto { · 238 unmodified lines | ||
| 244 | 244 | int sizelineinfo; |
| 245 | 245 | int sizep; /* size of `p' */ |
| 246 | 246 | int sizelocvars; |
| 247 | − int lineDefined; | |
| 247 | + int linedefined; | |
| 248 | + int lastlinedefined; | |
| 248 | 249 | GCObject *gclist; |
| 249 | 250 | lu_byte nups; /* number of upvalues */ |
| 250 | 251 | lu_byte numparams; |
| @@ -360,16 +361,15 @@ extern const TValue luaO_nilobject; · 109 unmodified lines | ||
| 360 | 361 | |
| 361 | 362 | #define ceillog2(x) (luaO_log2((x)-1) + 1) |
| 362 | 363 | |
| 363 | −int luaO_log2 (unsigned int x); | |
| 364 | −int luaO_int2fb (unsigned int x); | |
| 365 | −int luaO_fb2int (int x); | |
| 366 | − | |
| 367 | −int luaO_rawequalObj (const TValue *t1, const TValue *t2); | |
| 368 | −int luaO_str2d (const char *s, lua_Number *result); | |
| 369 | − | |
| 370 | −const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp); | |
| 371 | −const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); | |
| 372 | −void luaO_chunkid (char *out, const char *source, int len); | |
| 364 | +LUAI_FUNC int luaO_log2 (unsigned int x); | |
| 365 | +LUAI_FUNC int luaO_int2fb (unsigned int x); | |
| 366 | +LUAI_FUNC int luaO_fb2int (int x); | |
| 367 | +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); | |
| 368 | +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); | |
| 369 | +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | |
| 370 | + va_list argp); | |
| 371 | +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); | |
| 372 | +LUAI_FUNC void luaO_chunkid (char *out, const char *source, int len); | |
| 373 | 373 | |
| 374 | 374 | |
| 375 | 375 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lopcodes.c,v 1.30 2004/12/02 12:59:10 roberto Exp $ | |
| 2 | +** $Id: lopcodes.c,v 1.33 2005/05/04 20:42:28 roberto Exp $ | |
| 3 | 3 | ** See Copyright Notice in lua.h |
| 4 | 4 | */ |
| 5 | 5 | |
| @@ -32,9 +32,11 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { · 26 unmodified lines | ||
| 32 | 32 | "SUB", |
| 33 | 33 | "MUL", |
| 34 | 34 | "DIV", |
| 35 | + "MOD", | |
| 35 | 36 | "POW", |
| 36 | 37 | "UNM", |
| 37 | 38 | "NOT", |
| 39 | + "SIZ", | |
| 38 | 40 | "CONCAT", |
| 39 | 41 | "JMP", |
| 40 | 42 | "EQ", |
| @@ -47,7 +49,6 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { · 6 unmodified lines | ||
| 47 | 49 | "FORLOOP", |
| 48 | 50 | "FORPREP", |
| 49 | 51 | "TFORLOOP", |
| 50 | − "TFORPREP", | |
| 51 | 52 | "SETLIST", |
| 52 | 53 | "CLOSE", |
| 53 | 54 | "CLOSURE", |
| @@ -76,9 +77,11 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 22 unmodified lines | ||
| 76 | 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ |
| 77 | 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ |
| 78 | 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ |
| 80 | + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ | |
| 79 | 81 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ |
| 80 | 82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ |
| 81 | 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ |
| 84 | + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_SIZ */ | |
| 82 | 85 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ |
| 83 | 86 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ |
| 84 | 87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ |
| @@ -91,7 +94,6 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 6 unmodified lines | ||
| 91 | 94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ |
| 92 | 95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ |
| 93 | 96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ |
| 94 | − ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_TFORPREP */ | |
| 95 | 97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ |
| 96 | 98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ |
| 97 | 99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lopcodes.h,v 1.114 2004/12/02 12:59:10 roberto Exp $ | |
| 2 | +** $Id: lopcodes.h,v 1.119 2005/05/04 20:42:28 roberto Exp $ | |
| 3 | 3 | ** Opcodes for Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -51,9 +51,9 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ · 45 unmodified lines | ||
| 51 | 51 | /* |
| 52 | 52 | ** limits for opcode arguments. |
| 53 | 53 | ** we use (signed) int to manipulate most arguments, |
| 54 | −** so they must fit in LUA_BITSINT-1 bits (-1 for sign) | |
| 54 | +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) | |
| 55 | 55 | */ |
| 56 | −#if SIZE_Bx < LUA_BITSINT-1 | |
| 56 | +#if SIZE_Bx < LUAI_BITSINT-1 | |
| 57 | 57 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) |
| 58 | 58 | #define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ |
| 59 | 59 | #else |
| @@ -172,9 +172,11 @@ OP_ADD,/* A B C R(A) := RK(B) + RK(C) */ · 112 unmodified lines | ||
| 172 | 172 | OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ |
| 173 | 173 | OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ |
| 174 | 174 | OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ |
| 175 | +OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ | |
| 175 | 176 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ |
| 176 | 177 | OP_UNM,/* A B R(A) := -R(B) */ |
| 177 | 178 | OP_NOT,/* A B R(A) := not R(B) */ |
| 179 | +OP_SIZ,/* A B R(A) := size of R(B) */ | |
| 178 | 180 | |
| 179 | 181 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ |
| 180 | 182 | |
| @@ -195,8 +197,6 @@ OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ · 14 unmodified lines | ||
| 195 | 197 | |
| 196 | 198 | OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); |
| 197 | 199 | if R(A+2) ~= nil then pc++ */ |
| 198 | −OP_TFORPREP,/* A sBx if type(R(A)) == table then R(A+1):=R(A), R(A):=next; | |
| 199 | − pc+=sBx */ | |
| 200 | 200 | |
| 201 | 201 | OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ |
| 202 | 202 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loslib.c,v 1.4 2005/01/10 19:16:29 roberto Exp $ | |
| 2 | +** $Id: loslib.c,v 1.9 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Standard Operating System library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -57,16 +57,13 @@ static int io_rename (lua_State *L) { · 51 unmodified lines | ||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | static int io_tmpname (lua_State *L) { |
| 60 | −#if !USE_TMPNAME | |
| 61 | − luaL_error(L, "`tmpname' not supported"); | |
| 62 | − return 0; | |
| 63 | −#else | |
| 64 | − char buff[L_tmpnam]; | |
| 65 | − if (tmpnam(buff) != buff) | |
| 66 | − return luaL_error(L, "unable to generate a unique filename in `tmpname'"); | |
| 60 | + char buff[LUA_TMPNAMBUFSIZE]; | |
| 61 | + int err; | |
| 62 | + lua_tmpnam(buff, err); | |
| 63 | + if (err) | |
| 64 | + return luaL_error(L, "unable to generate a unique filename"); | |
| 67 | 65 | lua_pushstring(L, buff); |
| 68 | 66 | return 1; |
| 69 | −#endif | |
| 70 | 67 | } |
| 71 | 68 | |
| 72 | 69 | |
| @@ -116,7 +113,7 @@ static int getfield (lua_State *L, const char *key, int d) { · 43 unmodified lines | ||
| 116 | 113 | res = (int)lua_tointeger(L, -1); |
| 117 | 114 | else { |
| 118 | 115 | if (d < 0) |
| 119 | − return luaL_error(L, "field `%s' missing in date table", key); | |
| 116 | + return luaL_error(L, "field " LUA_QS " missing in date table", key); | |
| 120 | 117 | res = d; |
| 121 | 118 | } |
| 122 | 119 | lua_pop(L, 1); |
| @@ -154,7 +151,7 @@ static int io_date (lua_State *L) { · 31 unmodified lines | ||
| 154 | 151 | if (strftime(b, sizeof(b), s, stm)) |
| 155 | 152 | lua_pushstring(L, b); |
| 156 | 153 | else |
| 157 | − return luaL_error(L, "`date' format too long"); | |
| 154 | + return luaL_error(L, LUA_QL("date") " format too long"); | |
| 158 | 155 | } |
| 159 | 156 | return 1; |
| 160 | 157 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lparser.c,v 2.13 2005/01/05 18:20:51 roberto Exp $ | |
| 2 | +** $Id: lparser.c,v 2.27 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lua Parser |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -33,10 +33,6 @@ · 27 unmodified lines | ||
| 33 | 33 | |
| 34 | 34 | #define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) |
| 35 | 35 | |
| 36 | −#define enterlevel(ls) if (++(ls)->nestlevel > LUA_MAXPARSERLEVEL) \ | |
| 37 | − luaX_lexerror(ls, "chunk has too many syntax levels", 0) | |
| 38 | −#define leavelevel(ls) ((ls)->nestlevel--) | |
| 39 | − | |
| 40 | 36 | |
| 41 | 37 | /* |
| 42 | 38 | ** nodes for block list (list of active blocks) |
| @@ -86,15 +82,15 @@ static void anchor_token (LexState *ls) { · 43 unmodified lines | ||
| 86 | 82 | |
| 87 | 83 | static void error_expected (LexState *ls, int token) { |
| 88 | 84 | luaX_syntaxerror(ls, |
| 89 | − luaO_pushfstring(ls->L, "`%s' expected", luaX_token2str(ls, token))); | |
| 85 | + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); | |
| 90 | 86 | } |
| 91 | 87 | |
| 92 | 88 | |
| 93 | 89 | static void errorlimit (FuncState *fs, int limit, const char *what) { |
| 94 | − const char *msg = (fs->f->lineDefined == 0) ? | |
| 90 | + const char *msg = (fs->f->linedefined == 0) ? | |
| 95 | 91 | luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : |
| 96 | 92 | luaO_pushfstring(fs->L, "function at line %d has more than %d %s", |
| 97 | − fs->f->lineDefined, limit, what); | |
| 93 | + fs->f->linedefined, limit, what); | |
| 98 | 94 | luaX_lexerror(fs->ls, msg, 0); |
| 99 | 95 | } |
| 100 | 96 | |
| @@ -129,7 +125,7 @@ static void check_match (LexState *ls, int what, int who, int where) { · 28 unmodified lines | ||
| 129 | 125 | error_expected(ls, what); |
| 130 | 126 | else { |
| 131 | 127 | luaX_syntaxerror(ls, luaO_pushfstring(ls->L, |
| 132 | − "`%s' expected (to close `%s' at line %d)", | |
| 128 | + LUA_QS " expected (to close " LUA_QS " at line %d)", | |
| 133 | 129 | luaX_token2str(ls, what), luaX_token2str(ls, who), where)); |
| 134 | 130 | } |
| 135 | 131 | } |
| @@ -167,7 +163,7 @@ static int registerlocalvar (LexState *ls, TString *varname) { · 31 unmodified lines | ||
| 167 | 163 | Proto *f = fs->f; |
| 168 | 164 | int oldsize = f->sizelocvars; |
| 169 | 165 | luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, |
| 170 | − LocVar, USHRT_MAX, "too many local variables"); | |
| 166 | + LocVar, SHRT_MAX, "too many local variables"); | |
| 171 | 167 | while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; |
| 172 | 168 | f->locvars[fs->nlocvars].varname = varname; |
| 173 | 169 | luaC_objbarrier(ls->L, f, varname); |
| @@ -181,7 +177,7 @@ static int registerlocalvar (LexState *ls, TString *varname) { · 7 unmodified lines | ||
| 181 | 177 | |
| 182 | 178 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 183 | 179 | FuncState *fs = ls->fs; |
| 184 | − luaY_checklimit(fs, fs->nactvar+n+1, MAXVARS, "local variables"); | |
| 180 | + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); | |
| 185 | 181 | fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); |
| 186 | 182 | } |
| 187 | 183 | |
| @@ -213,7 +209,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 25 unmodified lines | ||
| 213 | 209 | } |
| 214 | 210 | } |
| 215 | 211 | /* new one */ |
| 216 | − luaY_checklimit(fs, f->nups + 1, MAXUPVALUES, "upvalues"); | |
| 212 | + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); | |
| 217 | 213 | luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, |
| 218 | 214 | TString *, MAX_INT, ""); |
| 219 | 215 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; |
| @@ -295,6 +291,15 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { · 75 unmodified lines | ||
| 295 | 291 | } |
| 296 | 292 | |
| 297 | 293 | |
| 294 | +static void enterlevel (LexState *ls) { | |
| 295 | + if (++ls->L->nCcalls > LUAI_MAXCCALLS) | |
| 296 | + luaX_lexerror(ls, "chunk has too many syntax levels", 0); | |
| 297 | +} | |
| 298 | + | |
| 299 | + | |
| 300 | +#define leavelevel(ls) ((ls)->L->nCcalls--) | |
| 301 | + | |
| 302 | + | |
| 298 | 303 | static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) { |
| 299 | 304 | bl->breaklist = NO_JUMP; |
| 300 | 305 | bl->isbreakable = isbreakable; |
| @@ -395,7 +400,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 94 unmodified lines | ||
| 395 | 400 | struct LexState lexstate; |
| 396 | 401 | struct FuncState funcstate; |
| 397 | 402 | lexstate.buff = buff; |
| 398 | − lexstate.nestlevel = 0; | |
| 399 | 403 | luaX_setinput(L, &lexstate, z, luaS_new(L, name)); |
| 400 | 404 | open_func(&lexstate, &funcstate); |
| 401 | 405 | funcstate.f->is_vararg = NEWSTYLEVARARG; |
| @@ -405,7 +409,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 3 unmodified lines | ||
| 405 | 409 | close_func(&lexstate); |
| 406 | 410 | lua_assert(funcstate.prev == NULL); |
| 407 | 411 | lua_assert(funcstate.f->nups == 0); |
| 408 | − lua_assert(lexstate.nestlevel == 0); | |
| 409 | 412 | lua_assert(lexstate.fs == NULL); |
| 410 | 413 | return funcstate.f; |
| 411 | 414 | } |
| @@ -460,11 +463,11 @@ static void recfield (LexState *ls, struct ConsControl *cc) { · 48 unmodified lines | ||
| 460 | 463 | expdesc key, val; |
| 461 | 464 | if (ls->t.token == TK_NAME) { |
| 462 | 465 | luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); |
| 463 | − cc->nh++; | |
| 464 | 466 | checkname(ls, &key); |
| 465 | 467 | } |
| 466 | 468 | else /* ls->t.token == '[' */ |
| 467 | 469 | yindex(ls, &key); |
| 470 | + cc->nh++; | |
| 468 | 471 | checknext(ls, '='); |
| 469 | 472 | luaK_exp2RK(fs, &key); |
| 470 | 473 | expr(ls, &val); |
| @@ -574,7 +577,7 @@ static void parlist (LexState *ls) { · 103 unmodified lines | ||
| 574 | 577 | f->is_vararg = 1; |
| 575 | 578 | break; |
| 576 | 579 | } |
| 577 | − default: luaX_syntaxerror(ls, "<name> or `...' expected"); | |
| 580 | + default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected"); | |
| 578 | 581 | } |
| 579 | 582 | } while (!f->is_vararg && testnext(ls, ',')); |
| 580 | 583 | } |
| @@ -588,7 +591,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { · 7 unmodified lines | ||
| 588 | 591 | /* body -> `(' parlist `)' chunk END */ |
| 589 | 592 | FuncState new_fs; |
| 590 | 593 | open_func(ls, &new_fs); |
| 591 | − new_fs.f->lineDefined = line; | |
| 594 | + new_fs.f->linedefined = line; | |
| 592 | 595 | checknext(ls, '('); |
| 593 | 596 | if (needself) { |
| 594 | 597 | new_localvarliteral(ls, "self", 0); |
| @@ -597,6 +600,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { · 2 unmodified lines | ||
| 597 | 600 | parlist(ls); |
| 598 | 601 | checknext(ls, ')'); |
| 599 | 602 | chunk(ls); |
| 603 | + new_fs.f->lastlinedefined = ls->linenumber; | |
| 600 | 604 | check_match(ls, TK_END, TK_FUNCTION, line); |
| 601 | 605 | close_func(ls); |
| 602 | 606 | pushclosure(ls, &new_fs, e); |
| @@ -735,8 +739,8 @@ static void primaryexp (LexState *ls, expdesc *v) { · 132 unmodified lines | ||
| 735 | 739 | |
| 736 | 740 | |
| 737 | 741 | static void simpleexp (LexState *ls, expdesc *v) { |
| 738 | − /* simpleexp -> NUMBER | STRING | NIL | constructor | FUNCTION body | |
| 739 | − | primaryexp */ | |
| 742 | + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | | |
| 743 | + constructor | FUNCTION body | primaryexp */ | |
| 740 | 744 | switch (ls->t.token) { |
| 741 | 745 | case TK_NUMBER: { |
| 742 | 746 | init_exp(v, VK, luaK_numberK(ls->fs, ls->t.seminfo.r)); |
| @@ -761,7 +765,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 18 unmodified lines | ||
| 761 | 765 | case TK_DOTS: { /* vararg */ |
| 762 | 766 | FuncState *fs = ls->fs; |
| 763 | 767 | check_condition(ls, fs->f->is_vararg, |
| 764 | − "cannot use `...' outside a vararg function"); | |
| 768 | + "cannot use " LUA_QL("...") " outside a vararg function"); | |
| 765 | 769 | fs->f->is_vararg = NEWSTYLEVARARG; |
| 766 | 770 | init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); |
| 767 | 771 | break; |
| @@ -788,6 +792,7 @@ static UnOpr getunopr (int op) { · 20 unmodified lines | ||
| 788 | 792 | switch (op) { |
| 789 | 793 | case TK_NOT: return OPR_NOT; |
| 790 | 794 | case '-': return OPR_MINUS; |
| 795 | + case '*': return OPR_SIZE; | |
| 791 | 796 | default: return OPR_NOUNOPR; |
| 792 | 797 | } |
| 793 | 798 | } |
| @@ -799,6 +804,7 @@ static BinOpr getbinopr (int op) { · 5 unmodified lines | ||
| 799 | 804 | case '-': return OPR_SUB; |
| 800 | 805 | case '*': return OPR_MULT; |
| 801 | 806 | case '/': return OPR_DIV; |
| 807 | + case '%': return OPR_MOD; | |
| 802 | 808 | case '^': return OPR_POW; |
| 803 | 809 | case TK_CONCAT: return OPR_CONCAT; |
| 804 | 810 | case TK_NE: return OPR_NE; |
| @@ -818,9 +824,9 @@ static const struct { · 13 unmodified lines | ||
| 818 | 824 | lu_byte left; /* left priority for each binary operator */ |
| 819 | 825 | lu_byte right; /* right priority */ |
| 820 | 826 | } priority[] = { /* ORDER OPR */ |
| 821 | − {6, 6}, {6, 6}, {7, 7}, {7, 7}, /* arithmetic */ | |
| 827 | + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ | |
| 822 | 828 | {10, 9}, {5, 4}, /* power and concat (right associative) */ |
| 823 | − {3, 3}, {3, 3}, /* equality */ | |
| 829 | + {3, 3}, {3, 3}, /* equality and inequality */ | |
| 824 | 830 | {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ |
| 825 | 831 | {2, 2}, {1, 1} /* logical (and/or) */ |
| 826 | 832 | }; |
| @@ -829,7 +835,7 @@ static const struct { · 2 unmodified lines | ||
| 829 | 835 | |
| 830 | 836 | |
| 831 | 837 | /* |
| 832 | −** subexpr -> (simplexep | unop subexpr) { binop subexpr } | |
| 838 | +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } | |
| 833 | 839 | ** where `binop' is any binary operator with a priority higher than `limit' |
| 834 | 840 | */ |
| 835 | 841 | static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { |
| @@ -992,7 +998,7 @@ static int cond (LexState *ls) { · 156 unmodified lines | ||
| 992 | 998 | |
| 993 | 999 | static void whilestat (LexState *ls, int line) { |
| 994 | 1000 | /* whilestat -> WHILE cond DO block END */ |
| 995 | − Instruction codeexp[MAXEXPWHILE + EXTRAEXP]; | |
| 1001 | + Instruction codeexp[LUAI_MAXEXPWHILE + EXTRAEXP]; | |
| 996 | 1002 | int lineexp; |
| 997 | 1003 | int i; |
| 998 | 1004 | int sizeexp; |
| @@ -1010,8 +1016,8 @@ static void whilestat (LexState *ls, int line) { · 11 unmodified lines | ||
| 1010 | 1016 | luaK_concat(fs, &v.f, fs->jpc); |
| 1011 | 1017 | fs->jpc = NO_JUMP; |
| 1012 | 1018 | sizeexp = fs->pc - expinit; /* size of expression code */ |
| 1013 | − if (sizeexp > MAXEXPWHILE) | |
| 1014 | − luaX_syntaxerror(ls, "`while' condition too complex"); | |
| 1019 | + if (sizeexp > LUAI_MAXEXPWHILE) | |
| 1020 | + luaX_syntaxerror(ls, LUA_QL("while") " condition too complex"); | |
| 1015 | 1021 | for (i = 0; i < sizeexp; i++) /* save `exp' code */ |
| 1016 | 1022 | codeexp[i] = fs->f->code[expinit + i]; |
| 1017 | 1023 | fs->pc = expinit; /* remove `exp' code */ |
| @@ -1065,7 +1071,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { · 47 unmodified lines | ||
| 1065 | 1071 | int prep, endfor; |
| 1066 | 1072 | adjustlocalvars(ls, 3); /* control variables */ |
| 1067 | 1073 | checknext(ls, TK_DO); |
| 1068 | − prep = luaK_codeAsBx(fs, (isnum ? OP_FORPREP : OP_TFORPREP), base, NO_JUMP); | |
| 1074 | + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); | |
| 1069 | 1075 | enterblock(fs, &bl, 0); /* scope for declared variables */ |
| 1070 | 1076 | adjustlocalvars(ls, nvars); |
| 1071 | 1077 | luaK_reserveregs(fs, nvars); |
| @@ -1135,7 +1141,7 @@ static void forstat (LexState *ls, int line) { · 63 unmodified lines | ||
| 1135 | 1141 | switch (ls->t.token) { |
| 1136 | 1142 | case '=': fornum(ls, varname, line); break; |
| 1137 | 1143 | case ',': case TK_IN: forlist(ls, varname); break; |
| 1138 | − default: luaX_syntaxerror(ls, "`=' or `in' expected"); | |
| 1144 | + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); | |
| 1139 | 1145 | } |
| 1140 | 1146 | check_match(ls, TK_END, TK_FOR, line); |
| 1141 | 1147 | leaveblock(fs); /* loop scope (`break' jumps to this point) */ |
| @@ -1284,7 +1290,7 @@ static void retstat (LexState *ls) { · 142 unmodified lines | ||
| 1284 | 1290 | |
| 1285 | 1291 | |
| 1286 | 1292 | static void breakstat (LexState *ls) { |
| 1287 | − /* stat -> BREAK [NAME] */ | |
| 1293 | + /* stat -> BREAK */ | |
| 1288 | 1294 | FuncState *fs = ls->fs; |
| 1289 | 1295 | BlockCnt *bl = fs->bl; |
| 1290 | 1296 | int upval = 0; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lparser.h,v 1.51 2004/05/31 18:51:50 roberto Exp $ | |
| 2 | +** $Id: lparser.h,v 1.55 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Lua Parser |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -65,14 +65,15 @@ typedef struct FuncState { · 59 unmodified lines | ||
| 65 | 65 | int freereg; /* first free register */ |
| 66 | 66 | int nk; /* number of elements in `k' */ |
| 67 | 67 | int np; /* number of elements in `p' */ |
| 68 | − int nlocvars; /* number of elements in `locvars' */ | |
| 68 | + short nlocvars; /* number of elements in `locvars' */ | |
| 69 | 69 | lu_byte nactvar; /* number of active local variables */ |
| 70 | − upvaldesc upvalues[MAXUPVALUES]; /* upvalues */ | |
| 71 | − unsigned short actvar[MAXVARS]; /* declared-variable stack */ | |
| 70 | + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ | |
| 71 | + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ | |
| 72 | 72 | } FuncState; |
| 73 | 73 | |
| 74 | 74 | |
| 75 | −Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name); | |
| 75 | +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | |
| 76 | + const char *name); | |
| 76 | 77 | |
| 77 | 78 | |
| 78 | 79 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstate.c,v 2.25 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lstate.c,v 2.31 2005/05/05 15:34:03 roberto Exp $ | |
| 3 | 3 | ** Global State |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -24,20 +24,9 @@ · 18 unmodified lines | ||
| 24 | 24 | #include "ltm.h" |
| 25 | 25 | |
| 26 | 26 | |
| 27 | −/* | |
| 28 | −** macro to allow the inclusion of user information in Lua state | |
| 29 | −*/ | |
| 30 | −#ifndef LUA_USERSTATE | |
| 31 | −#define EXTRASPACE 0 | |
| 32 | −#else | |
| 33 | −union UEXTRASPACE {L_Umaxalign a; LUA_USERSTATE b;}; | |
| 34 | −#define EXTRASPACE (sizeof(union UEXTRASPACE)) | |
| 35 | −#endif | |
| 36 | − | |
| 37 | − | |
| 38 | −#define state_size(x) (sizeof(x) + EXTRASPACE) | |
| 39 | −#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + EXTRASPACE)) | |
| 40 | −#define fromstate(l) (cast(lu_byte *, (l)) - EXTRASPACE) | |
| 27 | +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) | |
| 28 | +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) | |
| 29 | +#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) | |
| 41 | 30 | |
| 42 | 31 | |
| 43 | 32 | /* |
| @@ -51,18 +40,21 @@ typedef struct LG { · 7 unmodified lines | ||
| 51 | 40 | |
| 52 | 41 | |
| 53 | 42 | static void stack_init (lua_State *L1, lua_State *L) { |
| 43 | + /* initialize CallInfo array */ | |
| 44 | + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); | |
| 45 | + L1->ci = L1->base_ci; | |
| 46 | + L1->size_ci = BASIC_CI_SIZE; | |
| 47 | + L1->end_ci = L1->base_ci + L1->size_ci - 1; | |
| 48 | + /* initialize stack array */ | |
| 54 | 49 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); |
| 55 | 50 | L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; |
| 56 | 51 | L1->top = L1->stack; |
| 57 | 52 | L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; |
| 58 | − L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); | |
| 59 | − L1->ci = L1->base_ci; | |
| 53 | + /* initialize first ci */ | |
| 60 | 54 | L1->ci->func = L1->top; |
| 61 | 55 | setnilvalue(L1->top++); /* `function' entry for this `ci' */ |
| 62 | 56 | L1->base = L1->ci->base = L1->top; |
| 63 | 57 | L1->ci->top = L1->top + LUA_MINSTACK; |
| 64 | − L1->size_ci = BASIC_CI_SIZE; | |
| 65 | − L1->end_ci = L1->base_ci + L1->size_ci - 1; | |
| 66 | 58 | } |
| 67 | 59 | |
| 68 | 60 | |
| @@ -105,6 +97,7 @@ static void preinit_state (lua_State *L, global_State *g) { · 36 unmodified lines | ||
| 105 | 97 | L->nCcalls = 0; |
| 106 | 98 | L->status = 0; |
| 107 | 99 | L->base_ci = L->ci = NULL; |
| 100 | + L->savedpc = NULL; | |
| 108 | 101 | L->errfunc = 0; |
| 109 | 102 | setnilvalue(gt(L)); |
| 110 | 103 | } |
| @@ -148,6 +141,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) { · 37 unmodified lines | ||
| 148 | 141 | |
| 149 | 142 | |
| 150 | 143 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { |
| 144 | + int i; | |
| 151 | 145 | lua_State *L; |
| 152 | 146 | global_State *g; |
| 153 | 147 | void *l = (*f)(ud, NULL, 0, state_size(LG)); |
| @@ -181,16 +175,17 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 27 unmodified lines | ||
| 181 | 175 | g->weak = NULL; |
| 182 | 176 | g->tmudata = NULL; |
| 183 | 177 | g->totalbytes = sizeof(LG); |
| 184 | − g->gcpace = 200; /* 200% (wait memory to double before next collection) */ | |
| 185 | − g->gcstepmul = 200; /* GC runs `twice the speed' of memory allocation */ | |
| 178 | + g->gcpause = LUAI_GCPAUSE; | |
| 179 | + g->gcstepmul = LUAI_GCMUL; | |
| 186 | 180 | g->gcdept = 0; |
| 181 | + for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL; | |
| 187 | 182 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { |
| 188 | 183 | /* memory allocation error: free partial state */ |
| 189 | 184 | close_state(L); |
| 190 | 185 | L = NULL; |
| 191 | 186 | } |
| 192 | 187 | else |
| 193 | − lua_userstateopen(L); | |
| 188 | + luai_userstateopen(L); | |
| 194 | 189 | return L; |
| 195 | 190 | } |
| 196 | 191 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstate.h,v 2.16 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lstate.h,v 2.21 2005/05/05 15:34:03 roberto Exp $ | |
| 3 | 3 | ** Global State |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -83,12 +83,13 @@ typedef struct global_State { · 77 unmodified lines | ||
| 83 | 83 | lu_mem totalbytes; /* number of bytes currently allocated */ |
| 84 | 84 | lu_mem estimate; /* an estimate of number of bytes actually in use */ |
| 85 | 85 | lu_mem gcdept; /* how much GC is `behind schedule' */ |
| 86 | − int gcpace; /* size of pause between successive GCs */ | |
| 86 | + int gcpause; /* size of pause between successive GCs */ | |
| 87 | 87 | int gcstepmul; /* GC `granularity' */ |
| 88 | 88 | lua_CFunction panic; /* to be called in unprotected errors */ |
| 89 | 89 | TValue _registry; |
| 90 | 90 | struct lua_State *mainthread; |
| 91 | 91 | UpVal uvhead; /* head of double-linked list of all open upvalues */ |
| 92 | + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ | |
| 92 | 93 | TString *tmname[TM_N]; /* array with tag-method names */ |
| 93 | 94 | } global_State; |
| 94 | 95 | |
| @@ -102,12 +103,13 @@ struct lua_State { · 7 unmodified lines | ||
| 102 | 103 | StkId base; /* base of current function */ |
| 103 | 104 | global_State *l_G; |
| 104 | 105 | CallInfo *ci; /* call info for current function */ |
| 106 | + const Instruction *savedpc; /* `savedpc' of current function */ | |
| 105 | 107 | StkId stack_last; /* last free slot in the stack */ |
| 106 | 108 | StkId stack; /* stack base */ |
| 107 | 109 | int stacksize; |
| 108 | 110 | CallInfo *end_ci; /* points after end of ci array*/ |
| 109 | 111 | CallInfo *base_ci; /* array of CallInfo's */ |
| 110 | − unsigned short size_ci; /* size of array `base_ci' */ | |
| 112 | + int size_ci; /* size of array `base_ci' */ | |
| 111 | 113 | unsigned short nCcalls; /* number of nested C calls */ |
| 112 | 114 | lu_byte hookmask; |
| 113 | 115 | lu_byte allowhook; |
| @@ -159,8 +161,8 @@ union GCObject { · 45 unmodified lines | ||
| 159 | 161 | #define obj2gco(v) (cast(GCObject *, (v))) |
| 160 | 162 | |
| 161 | 163 | |
| 162 | −lua_State *luaE_newthread (lua_State *L); | |
| 163 | −void luaE_freethread (lua_State *L, lua_State *L1); | |
| 164 | +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); | |
| 165 | +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); | |
| 164 | 166 | |
| 165 | 167 | #endif |
| 166 | 168 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstring.h,v 1.42 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** String table (keep all strings handled by Lua) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -23,9 +23,9 @@ · 17 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) |
| 25 | 25 | |
| 26 | −void luaS_resize (lua_State *L, int newsize); | |
| 27 | −Udata *luaS_newudata (lua_State *L, size_t s, Table *e); | |
| 28 | −TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | |
| 26 | +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); | |
| 27 | +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); | |
| 28 | +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | |
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstrlib.c,v 1.109 2004/12/01 15:46:06 roberto Exp $ | |
| 2 | +** $Id: lstrlib.c,v 1.115 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Standard library for string operations and pattern-matching |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -172,11 +172,11 @@ typedef struct MatchState { · 166 unmodified lines | ||
| 172 | 172 | struct { |
| 173 | 173 | const char *init; |
| 174 | 174 | ptrdiff_t len; |
| 175 | − } capture[MAX_CAPTURES]; | |
| 175 | + } capture[LUA_MAXCAPTURES]; | |
| 176 | 176 | } MatchState; |
| 177 | 177 | |
| 178 | 178 | |
| 179 | −#define ESC '%' | |
| 179 | +#define L_ESC '%' | |
| 180 | 180 | #define SPECIALS "^$*+?.([%-" |
| 181 | 181 | |
| 182 | 182 | |
| @@ -198,17 +198,17 @@ static int capture_to_close (MatchState *ms) { · 15 unmodified lines | ||
| 198 | 198 | |
| 199 | 199 | static const char *classend (MatchState *ms, const char *p) { |
| 200 | 200 | switch (*p++) { |
| 201 | − case ESC: { | |
| 201 | + case L_ESC: { | |
| 202 | 202 | if (*p == '\0') |
| 203 | − luaL_error(ms->L, "malformed pattern (ends with `%%')"); | |
| 203 | + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); | |
| 204 | 204 | return p+1; |
| 205 | 205 | } |
| 206 | 206 | case '[': { |
| 207 | 207 | if (*p == '^') p++; |
| 208 | 208 | do { /* look for a `]' */ |
| 209 | 209 | if (*p == '\0') |
| 210 | − luaL_error(ms->L, "malformed pattern (missing `]')"); | |
| 211 | − if (*(p++) == ESC && *p != '\0') | |
| 210 | + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); | |
| 211 | + if (*(p++) == L_ESC && *p != '\0') | |
| 212 | 212 | p++; /* skip escapes (e.g. `%]') */ |
| 213 | 213 | } while (*p != ']'); |
| 214 | 214 | return p+1; |
| @@ -246,7 +246,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 31 unmodified lines | ||
| 246 | 246 | p++; /* skip the `^' */ |
| 247 | 247 | } |
| 248 | 248 | while (++p < ec) { |
| 249 | − if (*p == ESC) { | |
| 249 | + if (*p == L_ESC) { | |
| 250 | 250 | p++; |
| 251 | 251 | if (match_class(c, uchar(*p))) |
| 252 | 252 | return sig; |
| @@ -265,7 +265,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 12 unmodified lines | ||
| 265 | 265 | static int singlematch (int c, const char *p, const char *ep) { |
| 266 | 266 | switch (*p) { |
| 267 | 267 | case '.': return 1; /* matches any char */ |
| 268 | − case ESC: return match_class(c, uchar(*(p+1))); | |
| 268 | + case L_ESC: return match_class(c, uchar(*(p+1))); | |
| 269 | 269 | case '[': return matchbracketclass(c, p, ep-1); |
| 270 | 270 | default: return (uchar(*p) == c); |
| 271 | 271 | } |
| @@ -327,7 +327,7 @@ static const char *start_capture (MatchState *ms, const char *s, · 55 unmodified lines | ||
| 327 | 327 | const char *p, int what) { |
| 328 | 328 | const char *res; |
| 329 | 329 | int level = ms->level; |
| 330 | − if (level >= MAX_CAPTURES) luaL_error(ms->L, "too many captures"); | |
| 330 | + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); | |
| 331 | 331 | ms->capture[level].init = s; |
| 332 | 332 | ms->capture[level].len = what; |
| 333 | 333 | ms->level = level+1; |
| @@ -371,7 +371,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 37 unmodified lines | ||
| 371 | 371 | case ')': { /* end capture */ |
| 372 | 372 | return end_capture(ms, s, p+1); |
| 373 | 373 | } |
| 374 | − case ESC: { | |
| 374 | + case L_ESC: { | |
| 375 | 375 | switch (*(p+1)) { |
| 376 | 376 | case 'b': { /* balanced string? */ |
| 377 | 377 | s = matchbalance(ms, s, p+2); |
| @@ -382,7 +382,8 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 4 unmodified lines | ||
| 382 | 382 | const char *ep; char previous; |
| 383 | 383 | p += 2; |
| 384 | 384 | if (*p != '[') |
| 385 | − luaL_error(ms->L, "missing `[' after `%%f' in pattern"); | |
| 385 | + luaL_error(ms->L, "missing " LUA_QL("[") " after " | |
| 386 | + LUA_QL("%%f") " in pattern"); | |
| 386 | 387 | ep = classend(ms, p); /* points to what is next */ |
| 387 | 388 | previous = (s == ms->src_init) ? '\0' : *(s-1); |
| 388 | 389 | if (matchbracketclass(uchar(previous), p, ep-1) || |
| @@ -525,8 +526,8 @@ static int str_find (lua_State *L) { · 136 unmodified lines | ||
| 525 | 526 | |
| 526 | 527 | static int gfind_aux (lua_State *L) { |
| 527 | 528 | MatchState ms; |
| 528 | − const char *s = lua_tostring(L, lua_upvalueindex(1)); | |
| 529 | − size_t ls = lua_strlen(L, lua_upvalueindex(1)); | |
| 529 | + size_t ls; | |
| 530 | + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); | |
| 530 | 531 | const char *p = lua_tostring(L, lua_upvalueindex(2)); |
| 531 | 532 | const char *src; |
| 532 | 533 | ms.L = L; |
| @@ -563,11 +564,11 @@ static void add_s (MatchState *ms, luaL_Buffer *b, · 30 unmodified lines | ||
| 563 | 564 | const char *s, const char *e) { |
| 564 | 565 | lua_State *L = ms->L; |
| 565 | 566 | if (lua_isstring(L, 3)) { |
| 566 | − const char *news = lua_tostring(L, 3); | |
| 567 | − size_t l = lua_strlen(L, 3); | |
| 567 | + size_t l; | |
| 568 | + const char *news = lua_tolstring(L, 3, &l); | |
| 568 | 569 | size_t i; |
| 569 | 570 | for (i=0; i<l; i++) { |
| 570 | − if (news[i] != ESC) | |
| 571 | + if (news[i] != L_ESC) | |
| 571 | 572 | luaL_putchar(b, news[i]); |
| 572 | 573 | else { |
| 573 | 574 | i++; /* skip ESC */ |
| @@ -682,7 +683,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, · 108 unmodified lines | ||
| 682 | 683 | luaL_error(L, "invalid format (width or precision too long)"); |
| 683 | 684 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ |
| 684 | 685 | luaL_error(L, "invalid format (too long)"); |
| 685 | − form[0] = ESC; | |
| 686 | + form[0] = L_ESC; | |
| 686 | 687 | strncpy(form+1, strfrmt, p-strfrmt+1); |
| 687 | 688 | form[p-strfrmt+2] = 0; |
| 688 | 689 | return p; |
| @@ -697,16 +698,14 @@ static int str_format (lua_State *L) { · 8 unmodified lines | ||
| 697 | 698 | luaL_Buffer b; |
| 698 | 699 | luaL_buffinit(L, &b); |
| 699 | 700 | while (strfrmt < strfrmt_end) { |
| 700 | − if (*strfrmt != ESC) | |
| 701 | + if (*strfrmt != L_ESC) | |
| 701 | 702 | luaL_putchar(&b, *strfrmt++); |
| 702 | − else if (*++strfrmt == ESC) | |
| 703 | + else if (*++strfrmt == L_ESC) | |
| 703 | 704 | luaL_putchar(&b, *strfrmt++); /* %% */ |
| 704 | 705 | else { /* format item */ |
| 705 | 706 | char form[MAX_FORMAT]; /* to store the format (`%...') */ |
| 706 | 707 | char buff[MAX_ITEM]; /* to store the formatted item */ |
| 707 | 708 | int hasprecision = 0; |
| 708 | − if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') | |
| 709 | − return luaL_error(L, "obsolete option (d$) to `format'"); | |
| 710 | 709 | arg++; |
| 711 | 710 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); |
| 712 | 711 | switch (*strfrmt++) { |
| @@ -725,7 +724,7 @@ static int str_format (lua_State *L) { · 12 unmodified lines | ||
| 725 | 724 | } |
| 726 | 725 | case 'q': { |
| 727 | 726 | addquoted(L, &b, arg); |
| 728 | − continue; /* skip the `addsize' at the end */ | |
| 727 | + continue; /* skip the 'addsize' at the end */ | |
| 729 | 728 | } |
| 730 | 729 | case 's': { |
| 731 | 730 | size_t l; |
| @@ -743,7 +742,7 @@ static int str_format (lua_State *L) { · 11 unmodified lines | ||
| 743 | 742 | } |
| 744 | 743 | } |
| 745 | 744 | default: { /* also treat cases `pnLlh' */ |
| 746 | − return luaL_error(L, "invalid option to `format'"); | |
| 745 | + return luaL_error(L, "invalid option to " LUA_QL("format")); | |
| 747 | 746 | } |
| 748 | 747 | } |
| 749 | 748 | luaL_addlstring(&b, buff, strlen(buff)); |
| @@ -772,11 +771,26 @@ static const luaL_reg strlib[] = { · 22 unmodified lines | ||
| 772 | 771 | }; |
| 773 | 772 | |
| 774 | 773 | |
| 774 | +static void createmetatable (lua_State *L) { | |
| 775 | + lua_newtable(L); /* create metatable for strings */ | |
| 776 | + lua_pushliteral(L, ""); /* dummy string */ | |
| 777 | + lua_pushvalue(L, -2); | |
| 778 | + lua_setmetatable(L, -2); /* set string metatable */ | |
| 779 | + lua_pop(L, 1); /* pop dummy string */ | |
| 780 | + lua_pushvalue(L, -2); /* string library... */ | |
| 781 | + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ | |
| 782 | + lua_getfield(L, -2, "len"); | |
| 783 | + lua_setfield(L, -2, "__siz"); | |
| 784 | + lua_pop(L, 1); /* pop metatable */ | |
| 785 | +} | |
| 786 | + | |
| 787 | + | |
| 775 | 788 | /* |
| 776 | 789 | ** Open string library |
| 777 | 790 | */ |
| 778 | 791 | LUALIB_API int luaopen_string (lua_State *L) { |
| 779 | 792 | luaL_openlib(L, LUA_STRLIBNAME, strlib, 0); |
| 793 | + createmetatable(L); | |
| 780 | 794 | return 1; |
| 781 | 795 | } |
| 782 | 796 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltable.c,v 2.15 2005/01/10 18:17:39 roberto Exp $ | |
| 2 | +** $Id: ltable.c,v 2.23 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lua tables (hash) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -18,6 +18,7 @@ · 12 unmodified lines | ||
| 18 | 18 | ** Hence even when the load factor reaches 100%, performance remains good. |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | +#include <math.h> | |
| 21 | 22 | #include <string.h> |
| 22 | 23 | |
| 23 | 24 | #define ltable_c |
| @@ -37,10 +38,10 @@ · 13 unmodified lines | ||
| 37 | 38 | /* |
| 38 | 39 | ** max size of array part is 2^MAXBITS |
| 39 | 40 | */ |
| 40 | −#if LUA_BITSINT > 26 | |
| 41 | +#if LUAI_BITSINT > 26 | |
| 41 | 42 | #define MAXBITS 26 |
| 42 | 43 | #else |
| 43 | −#define MAXBITS (LUA_BITSINT-2) | |
| 44 | +#define MAXBITS (LUAI_BITSINT-2) | |
| 44 | 45 | #endif |
| 45 | 46 | |
| 46 | 47 | #define MAXASIZE (1 << MAXBITS) |
| @@ -119,7 +120,7 @@ static int arrayindex (const TValue *key) { · 72 unmodified lines | ||
| 119 | 120 | lua_Number n = nvalue(key); |
| 120 | 121 | int k; |
| 121 | 122 | lua_number2int(k, n); |
| 122 | − if (num_eq(cast(lua_Number, k), nvalue(key))) | |
| 123 | + if (luai_numeq(cast(lua_Number, k), nvalue(key))) | |
| 123 | 124 | return k; |
| 124 | 125 | } |
| 125 | 126 | return -1; /* `key' did not match some condition */ |
| @@ -150,7 +151,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 24 unmodified lines | ||
| 150 | 151 | } |
| 151 | 152 | else n = gnext(n); |
| 152 | 153 | } while (n); |
| 153 | − luaG_runerror(L, "invalid key for `next'"); /* key not found */ | |
| 154 | + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ | |
| 154 | 155 | return 0; /* to avoid warnings */ |
| 155 | 156 | } |
| 156 | 157 | } |
| @@ -436,7 +437,7 @@ const TValue *luaH_getnum (Table *t, int key) { · 279 unmodified lines | ||
| 436 | 437 | lua_Number nk = cast(lua_Number, key); |
| 437 | 438 | Node *n = hashnum(t, nk); |
| 438 | 439 | do { /* check whether `key' is somewhere in the chain */ |
| 439 | − if (ttisnumber(gkey(n)) && num_eq(nvalue(gkey(n)), nk)) | |
| 440 | + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) | |
| 440 | 441 | return gval(n); /* that's it */ |
| 441 | 442 | else n = gnext(n); |
| 442 | 443 | } while (n); |
| @@ -468,8 +469,9 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 25 unmodified lines | ||
| 468 | 469 | case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); |
| 469 | 470 | case LUA_TNUMBER: { |
| 470 | 471 | int k; |
| 471 | − lua_number2int(k, (nvalue(key))); | |
| 472 | − if (num_eq(cast(lua_Number, k), nvalue(key))) /* is an integer index? */ | |
| 472 | + lua_Number n = nvalue(key); | |
| 473 | + lua_number2int(k, n); | |
| 474 | + if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is integer? */ | |
| 473 | 475 | return luaH_getnum(t, k); /* use specialized version */ |
| 474 | 476 | /* else go through */ |
| 475 | 477 | } |
| @@ -493,7 +495,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 17 unmodified lines | ||
| 493 | 495 | return cast(TValue *, p); |
| 494 | 496 | else { |
| 495 | 497 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); |
| 496 | − else if (ttisnumber(key) && !num_eq(nvalue(key), nvalue(key))) | |
| 498 | + else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key))) | |
| 497 | 499 | luaG_runerror(L, "table index is NaN"); |
| 498 | 500 | return newkey(L, t, key); |
| 499 | 501 | } |
| @@ -523,3 +525,50 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { · 23 unmodified lines | ||
| 523 | 525 | } |
| 524 | 526 | } |
| 525 | 527 | |
| 528 | + | |
| 529 | +static int unbound_search (Table *t, unsigned int j) { | |
| 530 | + unsigned int i = j; /* i is zero or a present index */ | |
| 531 | + j = j+1; | |
| 532 | + /* find `i' and `j' such that i is present and j is not */ | |
| 533 | + while (!ttisnil(luaH_getnum(t, j))) { | |
| 534 | + i = j; | |
| 535 | + j = i*2; | |
| 536 | + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ | |
| 537 | + /* table was built with bad purposes: resort to linear search */ | |
| 538 | + i = 1; | |
| 539 | + while (!ttisnil(luaH_getnum(t, i))) i++; | |
| 540 | + return i - 1; | |
| 541 | + } | |
| 542 | + } | |
| 543 | + /* now do a binary search between them */ | |
| 544 | + while (i < j-1) { | |
| 545 | + unsigned int m = (i+j)/2; | |
| 546 | + if (ttisnil(luaH_getnum(t, m))) j = m; | |
| 547 | + else i = m; | |
| 548 | + } | |
| 549 | + return i; | |
| 550 | +} | |
| 551 | + | |
| 552 | + | |
| 553 | +/* | |
| 554 | +** Try to find a boundary in table `t'. A `boundary' is an integer index | |
| 555 | +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). | |
| 556 | +*/ | |
| 557 | +int luaH_getn (Table *t) { | |
| 558 | + unsigned int j = t->sizearray; | |
| 559 | + if (j > 0 && ttisnil(&t->array[j - 1])) { | |
| 560 | + /* there is a boundary in the array part: (binary) search for it */ | |
| 561 | + unsigned int i = 0; | |
| 562 | + while (j - i > 1) { | |
| 563 | + unsigned int m = (i+j)/2; | |
| 564 | + if (ttisnil(&t->array[m - 1])) j = m; | |
| 565 | + else i = m; | |
| 566 | + } | |
| 567 | + return i; | |
| 568 | + } | |
| 569 | + /* else must find a boundary in hash part */ | |
| 570 | + else if (t->node == &luaH_dummynode) /* hash part is empty? */ | |
| 571 | + return j; /* that is easy... */ | |
| 572 | + else return unbound_search(t, j); | |
| 573 | +} | |
| 574 | + | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltable.h,v 2.5 2005/01/05 18:20:51 roberto Exp $ | |
| 2 | +** $Id: ltable.h,v 2.7 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Lua tables (hash) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -20,19 +20,20 @@ · 14 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | extern const Node luaH_dummynode; |
| 22 | 22 | |
| 23 | −const TValue *luaH_getnum (Table *t, int key); | |
| 24 | −TValue *luaH_setnum (lua_State *L, Table *t, int key); | |
| 25 | −const TValue *luaH_getstr (Table *t, TString *key); | |
| 26 | −TValue *luaH_setstr (lua_State *L, Table *t, TString *key); | |
| 27 | −const TValue *luaH_get (Table *t, const TValue *key); | |
| 28 | −TValue *luaH_set (lua_State *L, Table *t, const TValue *key); | |
| 29 | −Table *luaH_new (lua_State *L, int narray, int lnhash); | |
| 30 | −void luaH_resizearray (lua_State *L, Table *t, int nasize); | |
| 31 | −void luaH_free (lua_State *L, Table *t); | |
| 32 | −int luaH_next (lua_State *L, Table *t, StkId key); | |
| 23 | +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); | |
| 24 | +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); | |
| 25 | +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); | |
| 26 | +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); | |
| 27 | +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); | |
| 28 | +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); | |
| 29 | +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); | |
| 30 | +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); | |
| 31 | +LUAI_FUNC void luaH_free (lua_State *L, Table *t); | |
| 32 | +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); | |
| 33 | +LUAI_FUNC int luaH_getn (Table *t); | |
| 33 | 34 | |
| 34 | 35 | /* exported only for debugging */ |
| 35 | −Node *luaH_mainposition (const Table *t, const TValue *key); | |
| 36 | +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); | |
| 36 | 37 | |
| 37 | 38 | |
| 38 | 39 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp $ | |
| 2 | +** $Id: ltablib.c,v 1.31 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Library for Table Manipulation |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -23,7 +23,7 @@ static int foreachi (lua_State *L) { · 17 unmodified lines | ||
| 23 | 23 | int i; |
| 24 | 24 | int n = aux_getn(L, 1); |
| 25 | 25 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 26 | − for (i=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) { | |
| 26 | + for (i=1; i <= n; i++) { | |
| 27 | 27 | lua_pushvalue(L, 2); /* function */ |
| 28 | 28 | lua_pushinteger(L, i); /* 1st argument */ |
| 29 | 29 | lua_rawgeti(L, 1, i); /* 2nd argument */ |
| @@ -62,39 +62,42 @@ static int getn (lua_State *L) { · 32 unmodified lines | ||
| 62 | 62 | |
| 63 | 63 | static int setn (lua_State *L) { |
| 64 | 64 | luaL_checktype(L, 1, LUA_TTABLE); |
| 65 | +#ifndef luaL_setn | |
| 65 | 66 | luaL_setn(L, 1, luaL_checkint(L, 2)); |
| 67 | +#else | |
| 68 | + luaL_error(L, LUA_QL("setn") " is obsolete"); | |
| 69 | +#endif | |
| 66 | 70 | lua_pushvalue(L, 1); |
| 67 | 71 | return 1; |
| 68 | 72 | } |
| 69 | 73 | |
| 70 | 74 | |
| 71 | 75 | static int tinsert (lua_State *L) { |
| 72 | − int v = lua_gettop(L); /* number of arguments */ | |
| 73 | − int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ | |
| 76 | + int e = aux_getn(L, 1) + 1; /* first empty element */ | |
| 74 | 77 | int pos; /* where to insert new element */ |
| 75 | − if (v == 2) /* called with only 2 arguments */ | |
| 78 | + if (lua_isnone(L, 3)) /* called with only 2 arguments */ | |
| 76 | 79 | pos = e; /* insert new element at the end */ |
| 77 | 80 | else { |
| 81 | + int i; | |
| 78 | 82 | pos = luaL_checkint(L, 2); /* 2nd argument is the position */ |
| 79 | 83 | if (pos > e) e = pos; /* `grow' array if necessary */ |
| 80 | − v = 3; /* function may be called with more than 3 args */ | |
| 81 | − } | |
| 82 | − luaL_setn(L, 1, e - LUA_FIRSTINDEX + 1); /* new size */ | |
| 83 | − while (--e >= pos) { /* move up elements */ | |
| 84 | − lua_rawgeti(L, 1, e); | |
| 85 | − lua_rawseti(L, 1, e+1); /* t[e+1] = t[e] */ | |
| 84 | + lua_settop(L, 3); /* function may be called with more than 3 args */ | |
| 85 | + for (i = e; i > pos; i--) { /* move up elements */ | |
| 86 | + lua_rawgeti(L, 1, i-1); | |
| 87 | + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ | |
| 88 | + } | |
| 86 | 89 | } |
| 87 | − lua_pushvalue(L, v); | |
| 90 | + luaL_setn(L, 1, e); /* new size */ | |
| 88 | 91 | lua_rawseti(L, 1, pos); /* t[pos] = v */ |
| 89 | 92 | return 0; |
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | |
| 93 | 96 | static int tremove (lua_State *L) { |
| 94 | − int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; | |
| 97 | + int e = aux_getn(L, 1); | |
| 95 | 98 | int pos = luaL_optint(L, 2, e); |
| 96 | − if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ | |
| 97 | − luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */ | |
| 99 | + if (e == 0) return 0; /* table is `empty' */ | |
| 100 | + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ | |
| 98 | 101 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ |
| 99 | 102 | for ( ;pos<e; pos++) { |
| 100 | 103 | lua_rawgeti(L, 1, pos+1); |
| @@ -110,11 +113,11 @@ static int str_concat (lua_State *L) { · 9 unmodified lines | ||
| 110 | 113 | luaL_Buffer b; |
| 111 | 114 | size_t lsep; |
| 112 | 115 | const char *sep = luaL_optlstring(L, 2, "", &lsep); |
| 113 | − int i = luaL_optint(L, 3, LUA_FIRSTINDEX); | |
| 116 | + int i = luaL_optint(L, 3, 1); | |
| 114 | 117 | int last = luaL_optint(L, 4, -2); |
| 115 | 118 | luaL_checktype(L, 1, LUA_TTABLE); |
| 116 | 119 | if (last == -2) |
| 117 | − last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | |
| 120 | + last = luaL_getn(L, 1); | |
| 118 | 121 | luaL_buffinit(L, &b); |
| 119 | 122 | for (; i <= last; i++) { |
| 120 | 123 | lua_rawgeti(L, 1, i); |
| @@ -226,7 +229,7 @@ static int sort (lua_State *L) { · 105 unmodified lines | ||
| 226 | 229 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
| 227 | 230 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 228 | 231 | lua_settop(L, 2); /* make sure there is two arguments */ |
| 229 | − auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1); | |
| 232 | + auxsort(L, 1, n); | |
| 230 | 233 | return 0; |
| 231 | 234 | } |
| 232 | 235 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltm.c,v 2.3 2004/04/30 20:13:38 roberto Exp $ | |
| 2 | +** $Id: ltm.c,v 2.5 2005/05/05 15:34:03 roberto Exp $ | |
| 3 | 3 | ** Tag methods |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -31,8 +31,8 @@ void luaT_init (lua_State *L) { · 25 unmodified lines | ||
| 31 | 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ |
| 32 | 32 | "__index", "__newindex", |
| 33 | 33 | "__gc", "__mode", "__eq", |
| 34 | − "__add", "__sub", "__mul", "__div", | |
| 35 | − "__pow", "__unm", "__lt", "__le", | |
| 34 | + "__add", "__sub", "__mul", "__div", "__mod", | |
| 35 | + "__pow", "__unm", "__siz", "__lt", "__le", | |
| 36 | 36 | "__concat", "__call" |
| 37 | 37 | }; |
| 38 | 38 | int i; |
| @@ -68,8 +68,8 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { · 29 unmodified lines | ||
| 68 | 68 | mt = uvalue(o)->metatable; |
| 69 | 69 | break; |
| 70 | 70 | default: |
| 71 | − mt = NULL; | |
| 71 | + mt = G(L)->mt[ttype(o)]; | |
| 72 | 72 | } |
| 73 | − return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject); | |
| 73 | + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject); | |
| 74 | 74 | } |
| 75 | 75 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltm.h,v 2.1 2003/12/10 12:13:36 roberto Exp $ | |
| 2 | +** $Id: ltm.h,v 2.4 2005/05/05 15:34:03 roberto Exp $ | |
| 3 | 3 | ** Tag methods |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -25,8 +25,10 @@ typedef enum { · 19 unmodified lines | ||
| 25 | 25 | TM_SUB, |
| 26 | 26 | TM_MUL, |
| 27 | 27 | TM_DIV, |
| 28 | + TM_MOD, | |
| 28 | 29 | TM_POW, |
| 29 | 30 | TM_UNM, |
| 31 | + TM_SIZ, | |
| 30 | 32 | TM_LT, |
| 31 | 33 | TM_LE, |
| 32 | 34 | TM_CONCAT, |
| @@ -41,11 +43,12 @@ typedef enum { · 8 unmodified lines | ||
| 41 | 43 | |
| 42 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) |
| 43 | 45 | |
| 46 | +extern const char *const luaT_typenames[]; | |
| 44 | 47 | |
| 45 | −const TValue *luaT_gettm (Table *events, TMS event, TString *ename); | |
| 46 | −const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event); | |
| 47 | −void luaT_init (lua_State *L); | |
| 48 | 48 | |
| 49 | −extern const char *const luaT_typenames[]; | |
| 49 | +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); | |
| 50 | +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, | |
| 51 | + TMS event); | |
| 52 | +LUAI_FUNC void luaT_init (lua_State *L); | |
| 50 | 53 | |
| 51 | 54 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.c,v 1.135 2005/01/10 17:21:10 roberto Exp $ | |
| 2 | +** $Id: lua.c,v 1.144 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lua stand-alone interpreter |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -18,19 +18,10 @@ · 12 unmodified lines | ||
| 18 | 18 | #include "lualib.h" |
| 19 | 19 | |
| 20 | 20 | |
| 21 | −/* | |
| 22 | −** generic extra include file | |
| 23 | −*/ | |
| 24 | −#ifdef LUA_USERCONFIG | |
| 25 | −#include LUA_USERCONFIG | |
| 26 | −#endif | |
| 27 | − | |
| 28 | − | |
| 29 | − | |
| 30 | 21 | |
| 31 | 22 | static lua_State *globalL = NULL; |
| 32 | 23 | |
| 33 | −static const char *progname = PROGNAME; | |
| 24 | +static const char *progname = LUA_PROGNAME; | |
| 34 | 25 | |
| 35 | 26 | |
| 36 | 27 | |
| @@ -53,10 +44,11 @@ static void print_usage (void) { · 16 unmodified lines | ||
| 53 | 44 | "usage: %s [options] [script [args]].\n" |
| 54 | 45 | "Available options are:\n" |
| 55 | 46 | " - execute stdin as a file\n" |
| 56 | − " -e stat execute string `stat'\n" | |
| 57 | − " -i enter interactive mode after executing `script'\n" | |
| 58 | − " -l name load and run library `name'\n" | |
| 47 | + " -e stat execute string " LUA_QL("stat") "\n" | |
| 48 | + " -i enter interactive mode after executing " LUA_QL("script") "\n" | |
| 49 | + " -l name require library " LUA_QL("name") "\n" | |
| 59 | 50 | " -v show version information\n" |
| 51 | + " -w trap access to undefined globals\n" | |
| 60 | 52 | " -- stop handling options\n" , |
| 61 | 53 | progname); |
| 62 | 54 | } |
| @@ -110,15 +102,14 @@ static void print_version (void) { · 47 unmodified lines | ||
| 110 | 102 | } |
| 111 | 103 | |
| 112 | 104 | |
| 113 | −static int getargs (lua_State *L, char *argv[], int n) { | |
| 114 | − int i, narg; | |
| 115 | − for (i=n+1; argv[i]; i++) { | |
| 116 | − luaL_checkstack(L, 1, "too many arguments to script"); | |
| 105 | +static int getargs (lua_State *L, int argc, char **argv, int n) { | |
| 106 | + int narg = argc - (n + 1); /* number of arguments to the script */ | |
| 107 | + int i; | |
| 108 | + luaL_checkstack(L, narg + 3, "too many arguments to script"); | |
| 109 | + for (i=n+1; i < argc; i++) | |
| 117 | 110 | lua_pushstring(L, argv[i]); |
| 118 | − } | |
| 119 | − narg = i-(n+1); /* number of arguments to the script (not to `lua.c') */ | |
| 120 | 111 | lua_newtable(L); |
| 121 | − for (i=0; argv[i]; i++) { | |
| 112 | + for (i=0; i < argc; i++) { | |
| 122 | 113 | lua_pushstring(L, argv[i]); |
| 123 | 114 | lua_rawseti(L, -2, i - n); |
| 124 | 115 | } |
| @@ -139,54 +130,18 @@ static int dostring (lua_State *L, const char *s, const char *name) { · 14 unmodified lines | ||
| 139 | 130 | |
| 140 | 131 | |
| 141 | 132 | static int dolibrary (lua_State *L, const char *name) { |
| 142 | − luaL_getfield(L, LUA_GLOBALSINDEX, "package.path"); | |
| 143 | − if (!lua_isstring(L, -1)) { | |
| 144 | − l_message(progname, "`package.path' must be a string"); | |
| 145 | − return 1; | |
| 146 | − } | |
| 147 | − name = luaL_searchpath(L, name, lua_tostring(L, -1)); | |
| 148 | − if (name == NULL) return report(L, 1); | |
| 149 | − else return dofile(L, name); | |
| 150 | −} | |
| 151 | − | |
| 152 | − | |
| 153 | − | |
| 154 | −/* | |
| 155 | −** this macro defines a function to show the prompt and reads the | |
| 156 | −** next line for manual input | |
| 157 | −*/ | |
| 158 | −#ifndef lua_readline | |
| 159 | −#define lua_readline(L,prompt) readline(L,prompt) | |
| 160 | − | |
| 161 | −/* maximum length of an input line */ | |
| 162 | −#ifndef MAXINPUT | |
| 163 | −#define MAXINPUT 512 | |
| 164 | −#endif | |
| 165 | − | |
| 166 | − | |
| 167 | −static int readline (lua_State *L, const char *prompt) { | |
| 168 | − static char buffer[MAXINPUT]; | |
| 169 | − if (prompt) { | |
| 170 | − fputs(prompt, stdout); | |
| 171 | − fflush(stdout); | |
| 172 | − } | |
| 173 | − if (fgets(buffer, sizeof(buffer), stdin) == NULL) | |
| 174 | − return 0; /* read fails */ | |
| 175 | − else { | |
| 176 | − lua_pushstring(L, buffer); | |
| 177 | − return 1; | |
| 178 | − } | |
| 133 | + lua_getglobal(L, "require"); | |
| 134 | + lua_pushstring(L, name); | |
| 135 | + return report(L, lua_pcall(L, 1, 0, 0)); | |
| 179 | 136 | } |
| 180 | 137 | |
| 181 | −#endif | |
| 182 | − | |
| 183 | 138 | |
| 184 | 139 | static const char *get_prompt (lua_State *L, int firstline) { |
| 185 | − const char *p = NULL; | |
| 140 | + const char *p; | |
| 186 | 141 | lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2"); |
| 187 | 142 | lua_rawget(L, LUA_GLOBALSINDEX); |
| 188 | 143 | p = lua_tostring(L, -1); |
| 189 | − if (p == NULL) p = (firstline ? PROMPT : PROMPT2); | |
| 144 | + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); | |
| 190 | 145 | lua_pop(L, 1); /* remove global */ |
| 191 | 146 | return p; |
| 192 | 147 | } |
| @@ -194,7 +149,7 @@ static const char *get_prompt (lua_State *L, int firstline) { · 1 unmodified line | ||
| 194 | 149 | |
| 195 | 150 | static int incomplete (lua_State *L, int status) { |
| 196 | 151 | if (status == LUA_ERRSYNTAX && |
| 197 | − strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) { | |
| 152 | + strstr(lua_tostring(L, -1), "<eof>") != NULL) { | |
| 198 | 153 | lua_pop(L, 1); |
| 199 | 154 | return 1; |
| 200 | 155 | } |
| @@ -203,23 +158,40 @@ static int incomplete (lua_State *L, int status) { · 2 unmodified lines | ||
| 203 | 158 | } |
| 204 | 159 | |
| 205 | 160 | |
| 161 | +static int pushline (lua_State *L, int firstline) { | |
| 162 | + char buffer[LUA_MAXINPUT]; | |
| 163 | + char *b = buffer; | |
| 164 | + size_t l; | |
| 165 | + const char *prmt = get_prompt(L, firstline); | |
| 166 | + if (lua_readline(L, b, prmt) == 0) | |
| 167 | + return 0; /* no input */ | |
| 168 | + l = strlen(b); | |
| 169 | + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ | |
| 170 | + b[l-1] = '\0'; /* remove it */ | |
| 171 | + if (firstline && b[0] == '=') /* first line starts with `=' ? */ | |
| 172 | + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ | |
| 173 | + else | |
| 174 | + lua_pushstring(L, b); | |
| 175 | + lua_freeline(L, b); | |
| 176 | + return 1; | |
| 177 | +} | |
| 178 | + | |
| 179 | + | |
| 206 | 180 | static int loadline (lua_State *L) { |
| 207 | 181 | int status; |
| 208 | 182 | lua_settop(L, 0); |
| 209 | − if (lua_readline(L, get_prompt(L, 1)) == 0) /* no input? */ | |
| 210 | − return -1; | |
| 211 | − if (lua_tostring(L, -1)[0] == '=') { /* line starts with `=' ? */ | |
| 212 | − lua_pushfstring(L, "return %s", lua_tostring(L, -1)+1);/* `=' -> `return' */ | |
| 213 | − lua_remove(L, -2); /* remove original line */ | |
| 214 | − } | |
| 183 | + if (!pushline(L, 1)) | |
| 184 | + return -1; /* no input */ | |
| 215 | 185 | for (;;) { /* repeat until gets a complete line */ |
| 216 | 186 | status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); |
| 217 | 187 | if (!incomplete(L, status)) break; /* cannot try to add lines? */ |
| 218 | − if (lua_readline(L, get_prompt(L, 0)) == 0) /* no more input? */ | |
| 188 | + if (!pushline(L, 0)) /* no more input? */ | |
| 219 | 189 | return -1; |
| 220 | − lua_concat(L, lua_gettop(L)); /* join lines */ | |
| 190 | + lua_pushliteral(L, "\n"); /* add a new line... */ | |
| 191 | + lua_insert(L, -2); /* ...between the two lines */ | |
| 192 | + lua_concat(L, 3); /* join them */ | |
| 221 | 193 | } |
| 222 | − lua_saveline(L, lua_tostring(L, 1)); | |
| 194 | + lua_saveline(L, 1); | |
| 223 | 195 | lua_remove(L, 1); /* remove line */ |
| 224 | 196 | return status; |
| 225 | 197 | } |
| @@ -237,8 +209,9 @@ static void dotty (lua_State *L) { · 11 unmodified lines | ||
| 237 | 209 | lua_getglobal(L, "print"); |
| 238 | 210 | lua_insert(L, 1); |
| 239 | 211 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) |
| 240 | − l_message(progname, lua_pushfstring(L, "error calling `print' (%s)", | |
| 241 | − lua_tostring(L, -1))); | |
| 212 | + l_message(progname, lua_pushfstring(L, | |
| 213 | + "error calling " LUA_QL("print") " (%s)", | |
| 214 | + lua_tostring(L, -1))); | |
| 242 | 215 | } |
| 243 | 216 | } |
| 244 | 217 | lua_settop(L, 0); /* clear stack */ |
| @@ -250,17 +223,17 @@ static void dotty (lua_State *L) { · 5 unmodified lines | ||
| 250 | 223 | static int checkvar (lua_State *L) { |
| 251 | 224 | const char *name = lua_tostring(L, 2); |
| 252 | 225 | if (name) |
| 253 | − luaL_error(L, "attempt to access undefined variable `%s'", name); | |
| 226 | + luaL_error(L, "attempt to access undefined variable " LUA_QS, name); | |
| 254 | 227 | return 0; |
| 255 | 228 | } |
| 256 | 229 | |
| 257 | 230 | |
| 258 | 231 | #define clearinteractive(i) (*i &= 2) |
| 259 | 232 | |
| 260 | −static int handle_argv (lua_State *L, char *argv[], int *interactive) { | |
| 233 | +static int handle_argv (lua_State *L, int argc, char **argv, int *interactive) { | |
| 261 | 234 | if (argv[1] == NULL) { /* no arguments? */ |
| 262 | 235 | *interactive = 0; |
| 263 | − if (stdin_is_tty()) | |
| 236 | + if (lua_stdin_is_tty()) | |
| 264 | 237 | dotty(L); |
| 265 | 238 | else |
| 266 | 239 | dofile(L, NULL); /* executes stdin as a file */ |
| @@ -330,9 +303,9 @@ static int handle_argv (lua_State *L, char *argv[], int *interactive) { · 63 unmodified lines | ||
| 330 | 303 | } |
| 331 | 304 | } endloop: |
| 332 | 305 | if (argv[i] != NULL) { |
| 333 | − const char *filename = argv[i]; | |
| 334 | − int narg = getargs(L, argv, i); /* collect arguments */ | |
| 335 | 306 | int status; |
| 307 | + const char *filename = argv[i]; | |
| 308 | + int narg = getargs(L, argc, argv, i); /* collect arguments */ | |
| 336 | 309 | lua_setglobal(L, "arg"); |
| 337 | 310 | clearinteractive(interactive); |
| 338 | 311 | status = luaL_loadfile(L, filename); |
| @@ -371,10 +344,10 @@ static int pmain (lua_State *L) { · 32 unmodified lines | ||
| 371 | 344 | int interactive = 1; |
| 372 | 345 | if (s->argv[0] && s->argv[0][0]) progname = s->argv[0]; |
| 373 | 346 | globalL = L; |
| 374 | − luaopen_stdlibs(L); /* open libraries */ | |
| 347 | + luaL_openlibs(L); /* open libraries */ | |
| 375 | 348 | status = handle_luainit(L); |
| 376 | 349 | if (status == 0) { |
| 377 | − status = handle_argv(L, s->argv, &interactive); | |
| 350 | + status = handle_argv(L, s->argc, s->argv, &interactive); | |
| 378 | 351 | if (status == 0 && interactive) dotty(L); |
| 379 | 352 | } |
| 380 | 353 | s->status = status; |
| @@ -382,7 +355,7 @@ static int pmain (lua_State *L) { · 1 unmodified line | ||
| 382 | 355 | } |
| 383 | 356 | |
| 384 | 357 | |
| 385 | −int main (int argc, char *argv[]) { | |
| 358 | +int main (int argc, char **argv) { | |
| 386 | 359 | int status; |
| 387 | 360 | struct Smain s; |
| 388 | 361 | lua_State *L = lua_open(); /* create state */ |
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.h,v 1.202 2005/02/18 12:40:02 roberto Exp $ | |
| 2 | +** $Id: lua.h,v 1.208 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lua - An Extensible Extension Language |
| 4 | 4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil |
| 5 | −** http://www.lua.org mailto:info@lua.org | |
| 5 | +** http://www.lua.org | |
| 6 | 6 | ** See Copyright Notice at the end of this file |
| 7 | 7 | */ |
| 8 | 8 | |
| @@ -17,7 +17,7 @@ · 8 unmodified lines | ||
| 17 | 17 | #include "luaconf.h" |
| 18 | 18 | |
| 19 | 19 | |
| 20 | −#define LUA_VERSION "Lua 5.1 (work5)" | |
| 20 | +#define LUA_VERSION "Lua 5.1 (work6)" | |
| 21 | 21 | #define LUA_VERSION_NUM 501 |
| 22 | 22 | #define LUA_COPYRIGHT "Copyright (C) 1994-2005 Tecgraf, PUC-Rio" |
| 23 | 23 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" |
| @@ -55,10 +55,9 @@ typedef int (*lua_CFunction) (lua_State *L); · 31 unmodified lines | ||
| 55 | 55 | /* |
| 56 | 56 | ** functions that read/write blocks when loading/dumping Lua chunks |
| 57 | 57 | */ |
| 58 | −typedef const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t *sz); | |
| 58 | +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); | |
| 59 | 59 | |
| 60 | −typedef int (*lua_Chunkwriter) (lua_State *L, const void* p, | |
| 61 | − size_t sz, void* ud); | |
| 60 | +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); | |
| 62 | 61 | |
| 63 | 62 | |
| 64 | 63 | /* |
| @@ -70,22 +69,19 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); · 5 unmodified lines | ||
| 70 | 69 | /* |
| 71 | 70 | ** basic types |
| 72 | 71 | */ |
| 73 | −#define LUA_TNONE (-1) | |
| 72 | +#define LUA_TNONE (-1) | |
| 74 | 73 | |
| 75 | −#define LUA_TNIL 0 | |
| 76 | −#define LUA_TBOOLEAN 1 | |
| 74 | +#define LUA_TNIL 0 | |
| 75 | +#define LUA_TBOOLEAN 1 | |
| 77 | 76 | #define LUA_TLIGHTUSERDATA 2 |
| 78 | −#define LUA_TNUMBER 3 | |
| 79 | −#define LUA_TSTRING 4 | |
| 80 | −#define LUA_TTABLE 5 | |
| 81 | −#define LUA_TFUNCTION 6 | |
| 82 | −#define LUA_TUSERDATA 7 | |
| 83 | −#define LUA_TTHREAD 8 | |
| 77 | +#define LUA_TNUMBER 3 | |
| 78 | +#define LUA_TSTRING 4 | |
| 79 | +#define LUA_TTABLE 5 | |
| 80 | +#define LUA_TFUNCTION 6 | |
| 81 | +#define LUA_TUSERDATA 7 | |
| 82 | +#define LUA_TTHREAD 8 | |
| 84 | 83 | |
| 85 | 84 | |
| 86 | −/* first index for arrays */ | |
| 87 | −#define LUA_FIRSTINDEX 1 | |
| 88 | − | |
| 89 | 85 | |
| 90 | 86 | /* minimum Lua stack available to a C function */ |
| 91 | 87 | #define LUA_MINSTACK 20 |
| @@ -94,7 +90,7 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); · 2 unmodified lines | ||
| 94 | 90 | /* |
| 95 | 91 | ** generic extra include file |
| 96 | 92 | */ |
| 97 | −#ifdef LUA_USER_H | |
| 93 | +#if defined(LUA_USER_H) | |
| 98 | 94 | #include LUA_USER_H |
| 99 | 95 | #endif |
| 100 | 96 | |
| @@ -150,7 +146,7 @@ LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); · 49 unmodified lines | ||
| 150 | 146 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); |
| 151 | 147 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); |
| 152 | 148 | LUA_API int (lua_toboolean) (lua_State *L, int idx); |
| 153 | −LUA_API const char *(lua_tostring) (lua_State *L, int idx); | |
| 149 | +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); | |
| 154 | 150 | LUA_API size_t (lua_objsize) (lua_State *L, int idx); |
| 155 | 151 | LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); |
| 156 | 152 | LUA_API void *(lua_touserdata) (lua_State *L, int idx); |
| @@ -204,11 +200,11 @@ LUA_API int (lua_setfenv) (lua_State *L, int idx); · 47 unmodified lines | ||
| 204 | 200 | */ |
| 205 | 201 | LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); |
| 206 | 202 | LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); |
| 207 | −LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); | |
| 208 | −LUA_API int (lua_load) (lua_State *L, lua_Chunkreader reader, void *dt, | |
| 203 | +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); | |
| 204 | +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, | |
| 209 | 205 | const char *chunkname); |
| 210 | 206 | |
| 211 | −LUA_API int (lua_dump) (lua_State *L, lua_Chunkwriter writer, void *data); | |
| 207 | +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); | |
| 212 | 208 | |
| 213 | 209 | |
| 214 | 210 | /* |
| @@ -227,7 +223,7 @@ LUA_API int (lua_status) (lua_State *L); · 12 unmodified lines | ||
| 227 | 223 | #define LUA_GCCOLLECT 2 |
| 228 | 224 | #define LUA_GCCOUNT 3 |
| 229 | 225 | #define LUA_GCSTEP 4 |
| 230 | −#define LUA_GCSETPACE 5 | |
| 226 | +#define LUA_GCSETPAUSE 5 | |
| 231 | 227 | #define LUA_GCSETSTEPMUL 6 |
| 232 | 228 | |
| 233 | 229 | LUA_API int (lua_gc) (lua_State *L, int what, int data); |
| @@ -278,6 +274,8 @@ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); · 44 unmodified lines | ||
| 278 | 274 | #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) |
| 279 | 275 | #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) |
| 280 | 276 | |
| 277 | +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) | |
| 278 | + | |
| 281 | 279 | |
| 282 | 280 | |
| 283 | 281 | /* |
| @@ -290,7 +288,8 @@ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); · 6 unmodified lines | ||
| 290 | 288 | |
| 291 | 289 | #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) |
| 292 | 290 | |
| 293 | − | |
| 291 | +#define lua_Chunkreader lua_Reader | |
| 292 | +#define lua_Chunkwriter lua_Writer | |
| 294 | 293 | |
| 295 | 294 | |
| 296 | 295 | |
| @@ -321,6 +320,8 @@ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); · 24 unmodified lines | ||
| 321 | 320 | |
| 322 | 321 | typedef struct lua_Debug lua_Debug; /* activation record */ |
| 323 | 322 | |
| 323 | + | |
| 324 | +/* Functions to be called by the debuger in specific events */ | |
| 324 | 325 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); |
| 325 | 326 | |
| 326 | 327 | |
| @@ -337,8 +338,6 @@ LUA_API int lua_gethookmask (lua_State *L); · 10 unmodified lines | ||
| 337 | 338 | LUA_API int lua_gethookcount (lua_State *L); |
| 338 | 339 | |
| 339 | 340 | |
| 340 | −#define LUA_IDSIZE 60 | |
| 341 | − | |
| 342 | 341 | struct lua_Debug { |
| 343 | 342 | int event; |
| 344 | 343 | const char *name; /* (n) */ |
| @@ -348,6 +347,7 @@ struct lua_Debug { · 3 unmodified lines | ||
| 348 | 347 | int currentline; /* (l) */ |
| 349 | 348 | int nups; /* (u) number of upvalues */ |
| 350 | 349 | int linedefined; /* (S) */ |
| 350 | + int lastlinedefined; /* (S) */ | |
| 351 | 351 | char short_src[LUA_IDSIZE]; /* (S) */ |
| 352 | 352 | /* private part */ |
| 353 | 353 | int i_ci; /* active function */ |
| @@ -357,7 +357,7 @@ struct lua_Debug { · 3 unmodified lines | ||
| 357 | 357 | |
| 358 | 358 | |
| 359 | 359 | /****************************************************************************** |
| 360 | −* Copyright (C) 1994-2004 Tecgraf, PUC-Rio. All rights reserved. | |
| 360 | +* Copyright (C) 1994-2005 Tecgraf, PUC-Rio. All rights reserved. | |
| 361 | 361 | * |
| 362 | 362 | * Permission is hereby granted, free of charge, to any person obtaining |
| 363 | 363 | * a copy of this software and associated documentation files (the |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: luac.c,v 1.49 2004/09/01 21:22:34 lhf Exp $ | |
| 2 | +** $Id: luac.c,v 1.50 2005/05/12 00:26:50 lhf Exp $ | |
| 3 | 3 | ** Lua compiler (saves bytecodes to files; also list bytecodes) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -151,8 +151,6 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 145 unmodified lines | ||
| 151 | 151 | return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | −void unprint(lua_State* L, const char* name); | |
| 155 | − | |
| 156 | 154 | struct Smain { |
| 157 | 155 | int argc; |
| 158 | 156 | char **argv; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: luaconf.h,v 1.30 2005/02/28 15:59:11 roberto Exp $ | |
| 2 | +** $Id: luaconf.h,v 1.49a 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Configuration file for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -13,387 +13,658 @@ · 7 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | /* |
| 16 | −** {====================================================== | |
| 17 | −** Index (search for keyword to find corresponding entry) | |
| 18 | −** ======================================================= | |
| 16 | +** ================================================================== | |
| 17 | +** Search for "@@" to find all configurable definitions. | |
| 18 | +** =================================================================== | |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | |
| 22 | −/* }====================================================== */ | |
| 23 | − | |
| 24 | − | |
| 25 | 22 | |
| 26 | 23 | |
| 27 | 24 | /* |
| 28 | −** {====================================================== | |
| 29 | −** Generic configuration | |
| 30 | −** ======================================================= | |
| 25 | +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for | |
| 26 | +@* Lua libraries. | |
| 27 | +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for | |
| 28 | +@* C libraries. | |
| 29 | +** CHANGE them if your machine has a non-conventional directory | |
| 30 | +** hierarchy or if you want to install your libraries in | |
| 31 | +** non-conventional directories. | |
| 31 | 32 | */ |
| 32 | − | |
| 33 | −/* default path */ | |
| 34 | 33 | #if defined(_WIN32) |
| 35 | 34 | #define LUA_ROOT "C:\\Program Files\\Lua51" |
| 36 | 35 | #define LUA_LDIR LUA_ROOT "\\lua" |
| 37 | 36 | #define LUA_CDIR LUA_ROOT "\\dll" |
| 38 | 37 | #define LUA_PATH_DEFAULT \ |
| 39 | − "?.lua;" LUA_LDIR "\\?.lua;" LUA_LDIR "\\?\\init.lua" | |
| 40 | −#define LUA_CPATH_DEFAULT "?.dll;" LUA_CDIR "\\?.dll" | |
| 38 | + "?.lua;" LUA_LDIR"\\?.lua;" LUA_LDIR"\\?\\init.lua" | |
| 39 | +#define LUA_CPATH_DEFAULT \ | |
| 40 | + "?.dll;" "l?.dll;" LUA_CDIR"\\?.dll;" LUA_CDIR"\\l?.dll" | |
| 41 | 41 | |
| 42 | 42 | #else |
| 43 | 43 | #define LUA_ROOT "/usr/local" |
| 44 | 44 | #define LUA_LDIR LUA_ROOT "/share/lua/5.1" |
| 45 | 45 | #define LUA_CDIR LUA_ROOT "/lib/lua/5.1" |
| 46 | 46 | #define LUA_PATH_DEFAULT \ |
| 47 | − "./?.lua;" LUA_LDIR "/?.lua;" LUA_LDIR "/?/init.lua" | |
| 48 | −#define LUA_CPATH_DEFAULT "./?.so;" LUA_CDIR "/?.so" | |
| 47 | + "./?.lua;" LUA_LDIR"/?.lua;" LUA_LDIR"/?/init.lua" | |
| 48 | +#define LUA_CPATH_DEFAULT \ | |
| 49 | + "./?.so;" "./l?.so;" LUA_CDIR"/?.so;" LUA_CDIR"/l?.so" | |
| 49 | 50 | #endif |
| 50 | 51 | |
| 51 | 52 | |
| 53 | +/* | |
| 54 | +@@ LUA_DIRSEP is the directory separator (for submodules). | |
| 55 | +** CHANGE it if your machine does not use "/" as the directory separator | |
| 56 | +** and is not Windows. (On Windows Lua automatically uses "\".) | |
| 57 | +*/ | |
| 58 | +#if defined(_WIN32) | |
| 59 | +#define LUA_DIRSEP "\\" | |
| 60 | +#else | |
| 61 | +#define LUA_DIRSEP "/" | |
| 62 | +#endif | |
| 52 | 63 | |
| 53 | −/* type of numbers in Lua */ | |
| 54 | −#define LUA_NUMBER double | |
| 55 | 64 | |
| 56 | −/* formats for Lua numbers */ | |
| 57 | −#define LUA_NUMBER_SCAN "%lf" | |
| 58 | −#define LUA_NUMBER_FMT "%.14g" | |
| 65 | +/* | |
| 66 | +@@ LUA_PATHSEP is the character that separates templates in a path. | |
| 67 | +** CHANGE it if for some reason your system cannot use a | |
| 68 | +** semicolon. (E.g., if a semicolon is a common character in | |
| 69 | +** file/directory names.) Probably you do not need to change this. | |
| 70 | +*/ | |
| 71 | +#define LUA_PATHSEP ';' | |
| 59 | 72 | |
| 60 | 73 | |
| 61 | 74 | /* |
| 62 | −** type for integer functions | |
| 63 | −** on most machines, `ptrdiff_t' gives a reasonable size for integers | |
| 75 | +@@ LUA_PATH_MARK is the string that marks the substitution points in a | |
| 76 | +@* template. | |
| 77 | +** CHANGE it if for some reason your system cannot use an interrogation | |
| 78 | +** mark. (E.g., if an interogation mark is a common character in | |
| 79 | +** file/directory names.) Probably you do not need to change this. | |
| 80 | +*/ | |
| 81 | +#define LUA_PATH_MARK "?" | |
| 82 | + | |
| 83 | + | |
| 84 | +/* | |
| 85 | +@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. | |
| 86 | +** CHANGE that if ptrdiff_t is not adequate on your machine. (On most | |
| 87 | +** machines, ptrdiff_t gives a good choice between int or long.) | |
| 64 | 88 | */ |
| 65 | 89 | #define LUA_INTEGER ptrdiff_t |
| 66 | 90 | |
| 67 | 91 | |
| 68 | −/* mark for all API functions */ | |
| 92 | +/* | |
| 93 | +@@ LUA_API is a mark for all core API functions. | |
| 94 | +@@ LUALIB_API is a mark for all standard library functions. | |
| 95 | +** CHANGE them if you need to define those functions in some special way. | |
| 96 | +** For instance, if you want to create one Windows DLL with the core and | |
| 97 | +** the libraries, you may want to use the following definition (define | |
| 98 | +** LUA_BUILD_AS_DLL to get it). | |
| 99 | +*/ | |
| 100 | +#if defined(LUA_BUILD_AS_DLL) | |
| 101 | + | |
| 102 | +#if defined(LUA_CORE) || defined(LUA_LIB) | |
| 103 | +#define LUA_API __declspec(__dllexport) | |
| 104 | +#else | |
| 105 | +#define LUA_API __declspec(__dllimport) | |
| 106 | +#endif | |
| 107 | + | |
| 108 | +#else | |
| 109 | + | |
| 69 | 110 | #define LUA_API extern |
| 70 | 111 | |
| 71 | −/* mark for auxlib functions */ | |
| 72 | −#define LUALIB_API extern | |
| 112 | +#endif | |
| 73 | 113 | |
| 74 | −/* buffer size used by lauxlib buffer system */ | |
| 75 | −#define LUAL_BUFFERSIZE BUFSIZ | |
| 114 | +/* more often than not the libs go together with the core */ | |
| 115 | +#define LUALIB_API LUA_API | |
| 76 | 116 | |
| 77 | 117 | |
| 78 | −/* assertions in Lua (mainly for internal debugging) */ | |
| 118 | +/* | |
| 119 | +@@ LUAI_FUNC is a mark for all extern functions that are not to be | |
| 120 | +@* exported to outside modules. | |
| 121 | +** CHANGE it if you need to mark them in some special way. Gcc (versions | |
| 122 | +** 3.2 and later) mark them as "hidden" to optimize their call when Lua | |
| 123 | +** is compiled as a shared library. | |
| 124 | +*/ | |
| 125 | +#if defined(luaall_c) | |
| 126 | +#define LUAI_FUNC static | |
| 127 | +#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) | |
| 128 | +#define LUAI_FUNC __attribute__((visibility("hidden"))) | |
| 129 | +#else | |
| 130 | +#define LUAI_FUNC extern | |
| 131 | +#endif | |
| 132 | + | |
| 133 | + | |
| 134 | +/* | |
| 135 | +@@ lua_assert describes the internal assertions in Lua. | |
| 136 | +** CHANGE that only if you need to debug Lua. | |
| 137 | +*/ | |
| 79 | 138 | #define lua_assert(c) ((void)0) |
| 80 | 139 | |
| 81 | −/* }====================================================== */ | |
| 82 | 140 | |
| 141 | +/* | |
| 142 | +@@ LUA_QL describes how error messages quote program elements. | |
| 143 | +** CHANGE it if you want a different appearance. | |
| 144 | +*/ | |
| 145 | +#define LUA_QL(x) "'" x "'" | |
| 146 | +#define LUA_QS LUA_QL("%s") | |
| 83 | 147 | |
| 84 | 148 | |
| 85 | 149 | /* |
| 86 | −** {====================================================== | |
| 150 | +@@ LUA_IDSIZE gives the maximum size for the description of the source | |
| 151 | +@* of a function in debug information. | |
| 152 | +** CHANGE it if you a different size. | |
| 153 | +*/ | |
| 154 | +#define LUA_IDSIZE 60 | |
| 155 | + | |
| 156 | + | |
| 157 | +/* | |
| 158 | +** {================================================================== | |
| 87 | 159 | ** Stand-alone configuration |
| 88 | −** ======================================================= | |
| 160 | +** =================================================================== | |
| 89 | 161 | */ |
| 90 | 162 | |
| 91 | −#ifdef lua_c | |
| 163 | +#if defined(lua_c) || defined(luaall_c) | |
| 92 | 164 | |
| 93 | −/* definition of `isatty' */ | |
| 94 | −#ifdef _POSIX_C_SOURCE | |
| 165 | +/* | |
| 166 | +@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that | |
| 167 | +@* is, whether we're running lua interactively). | |
| 168 | +** CHANGE it if you have a better definition for non-POSIX/non-Windows | |
| 169 | +** systems. | |
| 170 | +*/ | |
| 171 | +#if !defined(__STRICT_ANSI__) && defined(_POSIX_C_SOURCE) | |
| 95 | 172 | #include <unistd.h> |
| 96 | −#define stdin_is_tty() isatty(0) | |
| 97 | −#elif defined(_WIN32) | |
| 173 | +#define lua_stdin_is_tty() isatty(0) | |
| 174 | +#elif !defined(__STRICT_ANSI__) && defined(_WIN32) | |
| 98 | 175 | #include <io.h> |
| 99 | 176 | #include <stdio.h> |
| 100 | −#define stdin_is_tty() _isatty(_fileno(stdin)) | |
| 177 | +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) | |
| 101 | 178 | #else |
| 102 | −#define stdin_is_tty() 1 /* assume stdin is a tty */ | |
| 179 | +#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ | |
| 103 | 180 | #endif |
| 104 | 181 | |
| 105 | 182 | |
| 106 | −#define PROMPT "> " | |
| 107 | −#define PROMPT2 ">> " | |
| 108 | −#define PROGNAME "lua" | |
| 183 | +/* | |
| 184 | +@@ LUA_PROMPT is the default prompt used by stand-alone Lua. | |
| 185 | +@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. | |
| 186 | +** CHANGE them if you want different prompts. (You can also change the | |
| 187 | +** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) | |
| 188 | +*/ | |
| 189 | +#define LUA_PROMPT "> " | |
| 190 | +#define LUA_PROMPT2 ">> " | |
| 109 | 191 | |
| 110 | 192 | |
| 193 | +/* | |
| 194 | +@@ LUA_PROGNAME is the default name for the stand-alone Lua program. | |
| 195 | +** CHANGE it if your stand-alone interpreter has a different name and | |
| 196 | +** your system is not able to detect that name automatically. | |
| 197 | +*/ | |
| 198 | +#define LUA_PROGNAME "lua" | |
| 111 | 199 | |
| 112 | 200 | |
| 113 | 201 | /* |
| 114 | −** this macro can be used by some `history' system to save lines | |
| 115 | −** read in manual input | |
| 202 | +@@ LUA_MAXINPUT is the maximum length for an input line in the | |
| 203 | +@* stand-alone interpreter. | |
| 204 | +** CHANGE it if you need longer lines. | |
| 116 | 205 | */ |
| 117 | −#define lua_saveline(L,line) /* empty */ | |
| 206 | +#define LUA_MAXINPUT 512 | |
| 118 | 207 | |
| 119 | 208 | |
| 209 | +/* | |
| 210 | +@@ lua_readline defines how to show a prompt and then read a line from | |
| 211 | +@* the standard input. | |
| 212 | +@@ lua_saveline defines how to "save" a read line in a "history". | |
| 213 | +@@ lua_freeline defines how to free a line read by lua_readline. | |
| 214 | +** CHANGE them if you want to improve this functionality (e.g., by using | |
| 215 | +** GNU readline and history facilities). | |
| 216 | +*/ | |
| 217 | +#if !defined(__STRICT_ANSI__) && defined(LUA_USE_READLINE) | |
| 218 | +#include <stdio.h> | |
| 219 | +#include <readline/readline.h> | |
| 220 | +#include <readline/history.h> | |
| 221 | +#define lua_readline(L,b,p) (((b)=readline(p)) != NULL) | |
| 222 | +#define lua_saveline(L,idx) \ | |
| 223 | + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ | |
| 224 | + add_history(lua_tostring(L, idx)); /* add it to history */ | |
| 225 | +#define lua_freeline(L,b) free(b) | |
| 226 | +#else | |
| 227 | +#define lua_readline(L,b,p) \ | |
| 228 | + (fputs(p, stdout), fflush(stdout), /* show prompt */ \ | |
| 229 | + fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ | |
| 230 | +#define lua_saveline(L,idx) ((void)0) | |
| 231 | +#define lua_freeline(L,b) ((void)0) | |
| 232 | +#endif | |
| 120 | 233 | |
| 121 | 234 | #endif |
| 122 | 235 | |
| 123 | −/* }====================================================== */ | |
| 236 | +/* }================================================================== */ | |
| 237 | + | |
| 238 | + | |
| 239 | +/* | |
| 240 | +@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles | |
| 241 | +@* as a percentage. | |
| 242 | +** CHANGE it if you want the GC to run faster or slower (higher | |
| 243 | +** values mean larger pauses which mean slower collection.) | |
| 244 | +*/ | |
| 245 | +#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ | |
| 246 | + | |
| 247 | + | |
| 248 | +/* | |
| 249 | +@@ LUAI_GCMUL defines the speed of garbage collection relative to | |
| 250 | +@* memory allocation as a percentage. | |
| 251 | +** CHANGE it if you want to change the granularity of the garbage | |
| 252 | +** collection. (Higher values mean coarser collections. 0 represents | |
| 253 | +** infinity, where each step performs a full collection.) | |
| 254 | +*/ | |
| 255 | +#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ | |
| 256 | + | |
| 124 | 257 | |
| 258 | +/* | |
| 259 | +@@ LUA_COMPAT_GETN controls compatibility with old getn behavior. | |
| 260 | +** CHANGE it to 1 if you want exact compatibility with the behavior of | |
| 261 | +** setn/getn in Lua 5.0. | |
| 262 | +*/ | |
| 263 | +#define LUA_COMPAT_GETN 0 | |
| 125 | 264 | |
| 265 | +/* | |
| 266 | +@@ LUA_COMPAT_PATH controls compatibility about LUA_PATH. | |
| 267 | +** CHANGE it to 1 if you want 'require' to look for global LUA_PATH | |
| 268 | +** before checking package.path. | |
| 269 | +*/ | |
| 270 | +#define LUA_COMPAT_PATH 0 | |
| 126 | 271 | |
| 127 | 272 | /* |
| 128 | −** {====================================================== | |
| 129 | −** Core configuration | |
| 130 | −** ======================================================= | |
| 273 | +@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. | |
| 274 | +** CHANGE it to 1 if you want a global 'loadlib' function (otherwise | |
| 275 | +** the function is only available as 'package.loadlib'). | |
| 131 | 276 | */ |
| 277 | +#define LUA_COMPAT_LOADLIB 1 | |
| 132 | 278 | |
| 133 | −#ifdef LUA_CORE | |
| 279 | +/* | |
| 280 | +@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. | |
| 281 | +** CHANGE it to 1 if you want vararg functions that do not use '...' | |
| 282 | +** to get an 'arg' table with their extra arguments. | |
| 283 | +*/ | |
| 284 | +#define LUA_COMPAT_VARARG 1 | |
| 134 | 285 | |
| 135 | −/* LUA-C API assertions */ | |
| 136 | −#define api_check(L,o) lua_assert(o) | |
| 286 | +/* | |
| 287 | +@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting | |
| 288 | +@* facility. | |
| 289 | +** CHANGE it to 2 if you want the old behaviour, or undefine it to turn | |
| 290 | +** off the advisory error when nesting [[...]]. | |
| 291 | +*/ | |
| 292 | +#define LUA_COMPAT_LSTR 1 | |
| 293 | + | |
| 294 | +/* | |
| 295 | +@@ luai_apicheck is the assert macro used by the Lua-C API. | |
| 296 | +** CHANGE luai_apicheck if you want Lua to perform some checks in the | |
| 297 | +** parameters it gets from API calls. This may slow down the interpreter | |
| 298 | +** a bit, but may be quite useful when debugging C code that interfaces | |
| 299 | +** with Lua. A useful redefinition is to use assert.h. | |
| 300 | +*/ | |
| 301 | +#if defined(LUA_USE_APICHECK) | |
| 302 | +#include <assert.h> | |
| 303 | +#define luai_apicheck(L,o) assert(o) | |
| 304 | +#else | |
| 305 | +/* (By default lua_assert is empty, so luai_apicheck is also empty.) */ | |
| 306 | +#define luai_apicheck(L,o) lua_assert(o) | |
| 307 | +#endif | |
| 137 | 308 | |
| 138 | 309 | |
| 139 | −/* number of bits in an `int' */ | |
| 310 | +/* | |
| 311 | +@@ LUAI_BITSINT defines the number of bits in an int. | |
| 312 | +** CHANGE here if Lua cannot automatically detect the number of bits of | |
| 313 | +** your machine. Probably you do not need to change this. | |
| 314 | +*/ | |
| 140 | 315 | /* avoid overflows in comparison */ |
| 141 | 316 | #if INT_MAX-20 < 32760 |
| 142 | −#define LUA_BITSINT 16 | |
| 317 | +#define LUAI_BITSINT 16 | |
| 143 | 318 | #elif INT_MAX > 2147483640L |
| 144 | −/* `int' has at least 32 bits */ | |
| 145 | −#define LUA_BITSINT 32 | |
| 319 | +/* int has at least 32 bits */ | |
| 320 | +#define LUAI_BITSINT 32 | |
| 146 | 321 | #else |
| 147 | 322 | #error "you must define LUA_BITSINT with number of bits in an integer" |
| 148 | 323 | #endif |
| 149 | 324 | |
| 150 | 325 | |
| 151 | 326 | /* |
| 152 | −** L_UINT32: unsigned integer with at least 32 bits | |
| 153 | −** L_INT32: signed integer with at least 32 bits | |
| 154 | −** LU_MEM: an unsigned integer big enough to count the total memory used by Lua | |
| 155 | −** L_MEM: a signed integer big enough to count the total memory used by Lua | |
| 327 | +@@ LUAI_UINT32 is an unsigned integer with at least 32 bits. | |
| 328 | +@@ LUAI_INT32 is an signed integer with at least 32 bits. | |
| 329 | +@@ LUAI_UMEM is an unsigned integer big enough to count the total | |
| 330 | +@* memory used by Lua. | |
| 331 | +@@ LUAI_MEM is a signed integer big enough to count the total memory | |
| 332 | +@* used by Lua. | |
| 333 | +** CHANGE here if for some weird reason the default definitions are not | |
| 334 | +** good enough for your machine. (The definitions in the 'else' | |
| 335 | +** part always works, but may waste space on machines with 64-bit | |
| 336 | +** longs.) Probably you do not need to change this. | |
| 156 | 337 | */ |
| 157 | −#if LUA_BITSINT >= 32 | |
| 158 | −#define LUA_UINT32 unsigned int | |
| 159 | −#define LUA_INT32 int | |
| 160 | −#define LUA_MAXINT32 INT_MAX | |
| 161 | −#define LU_MEM size_t | |
| 162 | −#define L_MEM ptrdiff_t | |
| 338 | +#if LUAI_BITSINT >= 32 | |
| 339 | +#define LUAI_UINT32 unsigned int | |
| 340 | +#define LUAI_INT32 int | |
| 341 | +#define LUAI_MAXINT32 INT_MAX | |
| 342 | +#define LUAI_UMEM size_t | |
| 343 | +#define LUAI_MEM ptrdiff_t | |
| 163 | 344 | #else |
| 164 | 345 | /* 16-bit ints */ |
| 165 | −#define LUA_UINT32 unsigned long | |
| 166 | −#define LUA_INT32 long | |
| 167 | −#define LUA_MAXINT32 LONG_MAX | |
| 168 | −#define LU_MEM LUA_UINT32 | |
| 169 | −#define L_MEM ptrdiff_t | |
| 346 | +#define LUAI_UINT32 unsigned long | |
| 347 | +#define LUAI_INT32 long | |
| 348 | +#define LUAI_MAXINT32 LONG_MAX | |
| 349 | +#define LUAI_UMEM unsigned long | |
| 350 | +#define LUAI_MEM long | |
| 170 | 351 | #endif |
| 171 | 352 | |
| 172 | 353 | |
| 173 | −/* maximum depth for calls (unsigned short) */ | |
| 174 | −#define LUA_MAXCALLS 10000 | |
| 175 | − | |
| 176 | 354 | /* |
| 177 | −** maximum depth for C calls (unsigned short): Not too big, or may | |
| 178 | −** overflow the C stack... | |
| 355 | +@@ LUAI_MAXCALLS limits the number of nested calls. | |
| 356 | +** CHANGE it if you need really deep recursive calls. This limit is | |
| 357 | +** arbitrary; its only purpose is to stop infinite recursion before | |
| 358 | +** exhausting memory. | |
| 179 | 359 | */ |
| 180 | −#define LUA_MAXCCALLS 200 | |
| 181 | − | |
| 182 | − | |
| 183 | −/* maximum size for the virtual stack of a C function */ | |
| 184 | −#define MAXCSTACK 2048 | |
| 360 | +#define LUAI_MAXCALLS 20000 | |
| 185 | 361 | |
| 186 | 362 | |
| 187 | 363 | /* |
| 188 | −** maximum number of syntactical nested non-terminals: Not too big, | |
| 189 | −** or may overflow the C stack... | |
| 364 | +@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function | |
| 365 | +@* can use. | |
| 366 | +** CHANGE it if you need lots of (Lua) stack space for your C | |
| 367 | +** functions. This limit is arbitrary; its only purpose is to stop C | |
| 368 | +** functions to consume unlimited stack space. | |
| 190 | 369 | */ |
| 191 | −#define LUA_MAXPARSERLEVEL 200 | |
| 370 | +#define LUAI_MAXCSTACK 2048 | |
| 192 | 371 | |
| 193 | 372 | |
| 194 | −/* maximum number of variables declared in a function */ | |
| 195 | −#define MAXVARS 200 /* <MAXSTACK */ | |
| 196 | 373 | |
| 197 | − | |
| 198 | −/* maximum number of upvalues per function */ | |
| 199 | −#define MAXUPVALUES 60 /* <MAXSTACK */ | |
| 374 | +/* | |
| 375 | +** {================================================================== | |
| 376 | +** CHANGE (to smaller values) the following definitions if your system | |
| 377 | +** has a small C stack. (Or you may want to change them to larger | |
| 378 | +** values if your system has a large C stack and these limits are | |
| 379 | +** too rigid for you.) Some of these constants control the size of | |
| 380 | +** stack-allocated arrays used by the compiler or the interpreter, while | |
| 381 | +** others limit the maximum number of recursive calls that the compiler | |
| 382 | +** or the interpreter can perform. Values too large may cause a C stack | |
| 383 | +** overflow for some forms of deep constructs. | |
| 384 | +** =================================================================== | |
| 385 | +*/ | |
| 200 | 386 | |
| 201 | 387 | |
| 202 | −/* maximum size of expressions for optimizing `while' code */ | |
| 203 | −#define MAXEXPWHILE 100 | |
| 388 | +/* | |
| 389 | +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and | |
| 390 | +@* syntactical nested non-terminals in a program. | |
| 391 | +*/ | |
| 392 | +#define LUAI_MAXCCALLS 200 | |
| 204 | 393 | |
| 205 | 394 | |
| 206 | −/* function to convert a lua_Number to int (with any rounding method) */ | |
| 207 | −#if defined(__GNUC__) && defined(__i386) | |
| 208 | −#define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st") | |
| 395 | +/* | |
| 396 | +@@ LUAI_MAXVARS is the maximum number of local variables per function | |
| 397 | +@* (must be smaller than 250). | |
| 398 | +*/ | |
| 399 | +#define LUAI_MAXVARS 200 | |
| 209 | 400 | |
| 210 | −#elif defined(_MSC_VER) && defined(_M_IX86) | |
| 211 | −#pragma warning(disable: 4514) | |
| 212 | −__inline int l_lrint (double flt) | |
| 213 | −{ int i; | |
| 214 | − _asm { | |
| 215 | − fld flt | |
| 216 | − fistp i | |
| 217 | − }; | |
| 218 | − return i; | |
| 219 | −} | |
| 220 | −#define lua_number2int(i,d) ((i)=l_lrint((d))) | |
| 221 | − | |
| 222 | −#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L) | |
| 223 | −/* on machines compliant with C99, you can try `lrint' */ | |
| 224 | −#include <math.h> | |
| 225 | −#define lua_number2int(i,d) ((i)=lrint(d)) | |
| 226 | 401 | |
| 227 | −#else | |
| 228 | −#define lua_number2int(i,d) ((i)=(int)(d)) | |
| 402 | +/* | |
| 403 | +@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function | |
| 404 | +@* (must be smaller than 250). | |
| 405 | +*/ | |
| 406 | +#define LUAI_MAXUPVALUES 60 | |
| 229 | 407 | |
| 230 | −#endif | |
| 231 | 408 | |
| 409 | +/* | |
| 410 | +@@ LUAI_MAXEXPWHILE is the maximum size of code for expressions | |
| 411 | +@* controling a 'while' loop. | |
| 412 | +*/ | |
| 413 | +#define LUAI_MAXEXPWHILE 100 | |
| 232 | 414 | |
| 233 | −/* function to convert a lua_Number to lua_Integer (with any rounding method) */ | |
| 234 | −#define lua_number2integer(i,n) lua_number2int((i), (n)) | |
| 235 | 415 | |
| 416 | +/* | |
| 417 | +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. | |
| 418 | +*/ | |
| 419 | +#define LUAL_BUFFERSIZE BUFSIZ | |
| 236 | 420 | |
| 237 | −/* function to convert a lua_Number to a string */ | |
| 238 | −#include <stdio.h> | |
| 239 | −#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) | |
| 240 | −/* maximum size of previous conversion */ | |
| 241 | −#define MAX_NUMBER2STR 32 /* 16 digits, sign, point and \0 (+ some extra) */ | |
| 421 | +/* }================================================================== */ | |
| 242 | 422 | |
| 243 | −/* function to convert a string to a lua_Number */ | |
| 244 | −#define lua_str2number(s,p) strtod((s), (p)) | |
| 245 | 423 | |
| 246 | 424 | |
| 425 | +/* | |
| 426 | +@@ lua_number2int is a macro to convert lua_Number to int. | |
| 427 | +** CHANGE that if you know a faster way to convert a lua_Number to | |
| 428 | +** int (with any rounding method and without throwing errors) in your | |
| 429 | +** system. In Pentium machines, a naive typecast from double to int | |
| 430 | +** in C is extremely slow, so any alternative is worth trying. | |
| 431 | +*/ | |
| 247 | 432 | |
| 248 | −/* result of a `usual argument conversion' over lua_Number */ | |
| 249 | −#define LUA_UACNUMBER double | |
| 433 | +/* On a gcc/Pentium, resort to assembler */ | |
| 434 | +#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__i386) | |
| 435 | +#define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st") | |
| 250 | 436 | |
| 437 | +/* On Windows/Pentium, resort to assembler */ | |
| 438 | +#elif !defined(__STRICT_ANSI__) && defined(_MSC_VER) && defined(_M_IX86) | |
| 439 | +#define lua_number2int(i,d) \ | |
| 440 | + __asm fld d \ | |
| 441 | + __asm fistp i | |
| 251 | 442 | |
| 252 | −/* primitive operators for numbers */ | |
| 253 | −#define num_add(a,b) ((a)+(b)) | |
| 254 | −#define num_sub(a,b) ((a)-(b)) | |
| 255 | −#define num_mul(a,b) ((a)*(b)) | |
| 256 | −#define num_div(a,b) ((a)/(b)) | |
| 257 | −#define num_unm(a) (-(a)) | |
| 258 | −#define num_eq(a,b) ((a)==(b)) | |
| 259 | −#define num_lt(a,b) ((a)<(b)) | |
| 260 | −#define num_le(a,b) ((a)<=(b)) | |
| 261 | −#include <math.h> | |
| 262 | −#define num_pow(a,b) pow(a,b) | |
| 263 | 443 | |
| 444 | +/* on Pentium machines compliant with C99, you can try lrint */ | |
| 445 | +#elif defined (__i386) && defined(__STDC_VERSION__) && \ | |
| 446 | + (__STDC_VERSION__ >= 199900L) | |
| 447 | +#define lua_number2int(i,d) ((i)=lrint(d)) | |
| 264 | 448 | |
| 449 | +/* this option always works, but may be slow */ | |
| 450 | +#else | |
| 451 | +#define lua_number2int(i,d) ((i)=(int)(d)) | |
| 265 | 452 | |
| 266 | −/* type to ensure maximum alignment */ | |
| 267 | −#define LUSER_ALIGNMENT_T union { double u; void *s; long l; } | |
| 453 | +#endif | |
| 268 | 454 | |
| 269 | 455 | |
| 270 | 456 | /* |
| 271 | −** exception handling: by default, Lua handles errors with longjmp/setjmp | |
| 272 | −** when compiling as C code and with exceptions when compiling as C++ code. | |
| 273 | −** Change that if you prefer to use longjmp/setjmp even with C++. | |
| 457 | +@@ lua_number2integer is a macro to convert lua_Number to lua_Integer. | |
| 458 | +** CHANGE (see lua_number2int). | |
| 274 | 459 | */ |
| 275 | −#ifndef __cplusplus | |
| 276 | −/* default handling with long jumps */ | |
| 277 | −#include <setjmp.h> | |
| 278 | −#define L_THROW(L,c) longjmp((c)->b, 1) | |
| 279 | −#define L_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } | |
| 280 | −#define l_jmpbuf jmp_buf | |
| 460 | +/* On a gcc or Windows/Pentium, resort to assembler */ | |
| 461 | +#if (defined(__GNUC__) && defined(__i386)) || \ | |
| 462 | + (defined(_MSC_VER) && defined(_M_IX86)) | |
| 463 | +#define lua_number2integer(i,n) lua_number2int(i, n) | |
| 281 | 464 | |
| 465 | +/* this option always works, but may be slow */ | |
| 282 | 466 | #else |
| 283 | −/* C++ exceptions */ | |
| 284 | −#define L_THROW(L,c) throw(c) | |
| 285 | −#define L_TRY(L,c,a) try { a } catch(...) \ | |
| 286 | − { if ((c)->status == 0) (c)->status = -1; } | |
| 287 | −#define l_jmpbuf int /* dummy variable */ | |
| 467 | +#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) | |
| 468 | + | |
| 288 | 469 | #endif |
| 289 | 470 | |
| 290 | 471 | |
| 291 | 472 | |
| 292 | 473 | /* |
| 293 | −** macros for thread synchronization inside Lua core machine: This is | |
| 294 | −** an attempt to simplify the implementation of a multithreaded version | |
| 295 | −** of Lua. Do not change that unless you know what you are doing. all | |
| 296 | −** accesses to the global state and to global objects are synchronized. | |
| 297 | −** Because threads can read the stack of other threads (when running | |
| 298 | −** garbage collection), a thread must also synchronize any write-access | |
| 299 | −** to its own stack. Unsynchronized accesses are allowed only when | |
| 300 | −** reading its own stack, or when reading immutable fields from global | |
| 301 | −** objects (such as string values and udata values). | |
| 474 | +** {================================================================== | |
| 475 | +@@ LUA_NUMBER is the type of numbers in Lua. | |
| 476 | +** CHANGE the following definitions only if you want to build Lua | |
| 477 | +** with a number type different from double. You may also need to | |
| 478 | +** change lua_number2int & lua_number2integer. | |
| 479 | +** =================================================================== | |
| 302 | 480 | */ |
| 303 | −#define lua_lock(L) ((void) 0) | |
| 304 | −#define lua_unlock(L) ((void) 0) | |
| 305 | 481 | |
| 306 | 482 | |
| 307 | 483 | /* |
| 308 | −** this macro allows a thread switch in appropriate places in the Lua | |
| 309 | −** core | |
| 484 | +@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' | |
| 485 | +@* over a number. | |
| 310 | 486 | */ |
| 311 | −#define lua_threadyield(L) {lua_unlock(L); lua_lock(L);} | |
| 487 | +#define LUA_NUMBER double | |
| 488 | +#define LUAI_UACNUMBER LUA_NUMBER | |
| 312 | 489 | |
| 313 | 490 | |
| 491 | +/* | |
| 492 | +@@ LUA_NUMBER_SCAN is the format for reading numbers. | |
| 493 | +@@ LUA_NUMBER_FMT is the format for writing numbers. | |
| 494 | +@@ lua_number2str converts a number to a string. | |
| 495 | +@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. | |
| 496 | +@@ lua_str2number converts a string to a number. | |
| 497 | +*/ | |
| 498 | +#define LUA_NUMBER_SCAN "%lf" | |
| 499 | +#define LUA_NUMBER_FMT "%.14g" | |
| 500 | +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) | |
| 501 | +#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ | |
| 502 | +#define lua_str2number(s,p) strtod((s), (p)) | |
| 314 | 503 | |
| 315 | −/* allows user-specific initialization on new threads */ | |
| 316 | −#define lua_userstateopen(L) ((void)0) | |
| 317 | 504 | |
| 505 | +/* | |
| 506 | +@@ The luai_num* macros define the primitive operations over numbers. | |
| 507 | +*/ | |
| 508 | +#define luai_numadd(a,b) ((a)+(b)) | |
| 509 | +#define luai_numsub(a,b) ((a)-(b)) | |
| 510 | +#define luai_nummul(a,b) ((a)*(b)) | |
| 511 | +#define luai_numdiv(a,b) ((a)/(b)) | |
| 512 | +#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) | |
| 513 | +#define luai_numpow(a,b) pow(a,b) | |
| 514 | +#define luai_numunm(a) (-(a)) | |
| 515 | +#define luai_numeq(a,b) ((a)==(b)) | |
| 516 | +#define luai_numlt(a,b) ((a)<(b)) | |
| 517 | +#define luai_numle(a,b) ((a)<=(b)) | |
| 318 | 518 | |
| 319 | −#endif | |
| 519 | +/* }================================================================== */ | |
| 320 | 520 | |
| 321 | −/* }====================================================== */ | |
| 322 | 521 | |
| 522 | +/* | |
| 523 | +@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. | |
| 524 | +** CHANGE it if your system requires alignments larger than double. (For | |
| 525 | +** instance, if your system supports long doubles and they must be | |
| 526 | +** aligned in 16-byte boundaries, then you should add long double in the | |
| 527 | +** union.) Probably you do not need to change this. | |
| 528 | +*/ | |
| 529 | +#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } | |
| 323 | 530 | |
| 324 | 531 | |
| 325 | 532 | /* |
| 326 | −** {====================================================== | |
| 327 | −** Library configuration | |
| 328 | −** ======================================================= | |
| 533 | +@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. | |
| 534 | +** CHANGE them if you prefer to use longjmp/setjmp even with C++ or | |
| 535 | +** if want/don't want to use _longjmp/_setjmp instead of regular | |
| 536 | +** longjmp/setjmp. By default, Lua handles errors with exceptions when | |
| 537 | +** compiling as C++ code, with _longjmp/_setjmp when compiling as C code | |
| 538 | +** in a Unix system, and with longjmp/setjmp otherwise. | |
| 329 | 539 | */ |
| 540 | +#if defined(__cplusplus) | |
| 541 | +/* C++ exceptions */ | |
| 542 | +#define LUAI_THROW(L,c) throw(c) | |
| 543 | +#define LUAI_TRY(L,c,a) try { a } catch(...) \ | |
| 544 | + { if ((c)->status == 0) (c)->status = -1; } | |
| 545 | +#define luai_jmpbuf int /* dummy variable */ | |
| 330 | 546 | |
| 331 | −#ifdef LUA_LIB | |
| 547 | +#elif !defined(__STRICT_ANSI__) && (defined(unix) || defined(__unix) || \ | |
| 548 | + defined(__unix__)) | |
| 549 | +/* in Unix, try _longjmp/_setjmp (more efficient) */ | |
| 550 | +#define LUAI_THROW(L,c) _longjmp((c)->b, 1) | |
| 551 | +#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } | |
| 552 | +#define luai_jmpbuf jmp_buf | |
| 332 | 553 | |
| 554 | +#else | |
| 555 | +/* default handling with long jumps */ | |
| 556 | +#define LUAI_THROW(L,c) longjmp((c)->b, 1) | |
| 557 | +#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } | |
| 558 | +#define luai_jmpbuf jmp_buf | |
| 333 | 559 | |
| 334 | −/* environment variables that hold the search path for packages */ | |
| 335 | −#define LUA_PATH "LUA_PATH" | |
| 336 | −#define LUA_CPATH "LUA_CPATH" | |
| 560 | +#endif | |
| 337 | 561 | |
| 338 | −/* prefix for open functions in C libraries */ | |
| 339 | −#define LUA_POF "luaopen_" | |
| 340 | 562 | |
| 341 | −/* separator for open functions in C libraries */ | |
| 342 | −#define LUA_OFSEP "_" | |
| 563 | +/* | |
| 564 | +@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern | |
| 565 | +@* can do during pattern-matching. | |
| 566 | +** CHANGE it if you need more captures. This limit is arbitrary. | |
| 567 | +*/ | |
| 568 | +#define LUA_MAXCAPTURES 32 | |
| 343 | 569 | |
| 344 | −/* directory separator (for submodules) */ | |
| 345 | −#if defined(_WIN32) | |
| 346 | −#define LUA_DIRSEP "\\" | |
| 570 | + | |
| 571 | +/* | |
| 572 | +@@ lua_tmpnam is the function that the OS library uses to create a | |
| 573 | +@* temporary name. | |
| 574 | +@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. | |
| 575 | +** CHANGE them if you have an alternative to tmpnam (which is considered | |
| 576 | +** insecure) or if you want the original tmpnam anyway. By default, Lua | |
| 577 | +** uses tmpnam except when POSIX is available, where it uses mkstemp. | |
| 578 | +*/ | |
| 579 | +#if defined(loslib_c) || defined(luaall_c) | |
| 580 | + | |
| 581 | +#if !defined(__STRICT_ANSI__) && defined(_POSIX_C_SOURCE) | |
| 582 | +#include <unistd.h> | |
| 583 | +#define LUA_TMPNAMBUFSIZE 32 | |
| 584 | +#define lua_tmpnam(b,e) { \ | |
| 585 | + strcpy(b, "/tmp/lua_XXXXXX"); \ | |
| 586 | + e = mkstemp(b); \ | |
| 587 | + if (e != -1) close(e); \ | |
| 588 | + e = (e == -1); } | |
| 347 | 589 | #else |
| 348 | −#define LUA_DIRSEP "/" | |
| 590 | +#define LUA_TMPNAMBUFSIZE L_tmpnam | |
| 591 | +#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } | |
| 349 | 592 | #endif |
| 350 | 593 | |
| 351 | −/* separator of templates in a path */ | |
| 352 | −#define LUA_PATHSEP ';' | |
| 594 | +#endif | |
| 353 | 595 | |
| 354 | −/* wild char in each template */ | |
| 355 | −#define LUA_PATH_MARK "?" | |
| 596 | +/* | |
| 597 | +@@ LUA_DL_* define which dynamic-library system Lua should use. | |
| 598 | +** CHANGE here if Lua has problems choosing the appropriate | |
| 599 | +** dynamic-library system for your platform (either Windows' DLL, Mac's | |
| 600 | +** dyld, or Unix's dlopen). If your system is some kind of Unix, there | |
| 601 | +** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for | |
| 602 | +** it. To use dlopen you also need to adapt the src/Makefile (probably | |
| 603 | +** adding -ldl to the linker options), so Lua does not select it | |
| 604 | +** automatically. (When you change the makefile to add -ldl, you must | |
| 605 | +** also add -DLUA_USE_DLOPEN.) | |
| 606 | +** If you do not want any kind of dynamic library, undefine all these | |
| 607 | +** options (or just remove these definitions). | |
| 608 | +*/ | |
| 609 | +#if !defined(__STRICT_ANSI__) | |
| 610 | +#if defined(_WIN32) | |
| 611 | +#define LUA_DL_DLL | |
| 612 | +#elif defined(__APPLE__) && defined(__MACH__) | |
| 613 | +#define LUA_DL_DYLD | |
| 614 | +#elif defined(LUA_USE_DLOPEN) | |
| 615 | +#define LUA_DL_DLOPEN | |
| 616 | +#endif | |
| 617 | +#endif | |
| 356 | 618 | |
| 357 | 619 | |
| 358 | −/* maximum number of captures in pattern-matching (arbitrary limit) */ | |
| 359 | −#define MAX_CAPTURES 32 | |
| 620 | +/* | |
| 621 | +@@ lua_lock/lua_unlock are macros for thread synchronization inside the | |
| 622 | +@* Lua core. This is an attempt to simplify the implementation of a | |
| 623 | +@* multithreaded version of Lua. | |
| 624 | +** CHANGE them only if you know what you are doing. All accesses to | |
| 625 | +** the global state and to global objects are synchronized. Because | |
| 626 | +** threads can read the stack of other threads (when running garbage | |
| 627 | +** collection), a thread must also synchronize any write-access to its | |
| 628 | +** own stack. Unsynchronized accesses are allowed only when reading its | |
| 629 | +** own stack, or when reading immutable fields from global objects (such | |
| 630 | +** as string values and udata values). | |
| 631 | +*/ | |
| 632 | +#define lua_lock(L) ((void) 0) | |
| 633 | +#define lua_unlock(L) ((void) 0) | |
| 360 | 634 | |
| 361 | 635 | |
| 362 | 636 | /* |
| 363 | −** by default, gcc does not get `os.tmpname', because it generates a warning | |
| 364 | −** when using `tmpname'. Change that if you really want (or do not want) | |
| 365 | −** `os.tmpname' available. | |
| 637 | +@@ lua_threadyield allows a thread switch in appropriate places in the core. | |
| 638 | +** CHANGE it only if you know what you are doing. (See lua_lock.) | |
| 366 | 639 | */ |
| 367 | −#ifdef __GNUC__ | |
| 368 | −#define USE_TMPNAME 0 | |
| 369 | −#else | |
| 370 | −#define USE_TMPNAME 1 | |
| 371 | −#endif | |
| 640 | +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} | |
| 372 | 641 | |
| 373 | 642 | |
| 374 | 643 | /* |
| 375 | −** Configuration for loadlib: Lua tries to guess the dynamic-library | |
| 376 | −** system that your platform uses (either Windows' DLL, Mac's dyld, or | |
| 377 | −** dlopen). If your system is some kind of Unix, there is a good chance | |
| 378 | −** that USE_DLOPEN will work for it. You may need to adapt also the | |
| 379 | −** makefile. | |
| 644 | +@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State | |
| 645 | +@* (the data goes just *before* the lua_State pointer). | |
| 646 | +** CHANGE (define) this if you really need that. This value must be | |
| 647 | +** a multiple of the maximum alignment required for your machine. | |
| 380 | 648 | */ |
| 381 | −#if defined(_WIN32) | |
| 382 | −#define USE_DLL | |
| 383 | −#elif defined(__APPLE__) && defined(__MACH__) | |
| 384 | −#define USE_DYLD | |
| 385 | −#elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD) | |
| 386 | −#define USE_DLOPEN | |
| 387 | −#endif | |
| 649 | +#define LUAI_EXTRASPACE 0 | |
| 388 | 650 | |
| 389 | 651 | |
| 390 | −#endif | |
| 652 | +/* | |
| 653 | +@@ luai_userstateopen allows user-specific initialization on new threads. | |
| 654 | +** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that | |
| 655 | +** data whenever a new lua_State is created. | |
| 656 | +*/ | |
| 657 | +#define luai_userstateopen(L) ((void)0) | |
| 658 | + | |
| 391 | 659 | |
| 392 | −/* }====================================================== */ | |
| 393 | 660 | |
| 661 | +/* =================================================================== */ | |
| 394 | 662 | |
| 663 | +/* | |
| 664 | +** Local configuration. You can use this space to add your redefinitions | |
| 665 | +** without modifying the main part of the file. | |
| 666 | +*/ | |
| 395 | 667 | |
| 396 | 668 | |
| 397 | −/* Local configuration */ | |
| 398 | 669 | |
| 399 | 670 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lualib.h,v 1.33 2005/01/10 16:31:30 roberto Exp $ | |
| 2 | +** $Id: lualib.h,v 1.34 2005/04/13 17:24:20 roberto Exp $ | |
| 3 | 3 | ** Lua standard libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -36,12 +36,12 @@ LUALIB_API int (luaopen_math) (lua_State *L); · 30 unmodified lines | ||
| 36 | 36 | #define LUA_DBLIBNAME "debug" |
| 37 | 37 | LUALIB_API int (luaopen_debug) (lua_State *L); |
| 38 | 38 | |
| 39 | − | |
| 39 | +#define LUA_LOADLIBNAME "package" | |
| 40 | 40 | LUALIB_API int (luaopen_loadlib) (lua_State *L); |
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /* open all previous libraries */ |
| 44 | −LUALIB_API int (luaopen_stdlibs) (lua_State *L); | |
| 44 | +LUALIB_API void (luaL_openlibs) (lua_State *L); | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lundump.c,v 1.54 2004/11/25 09:31:41 lhf Exp $ | |
| 2 | +** $Id: lundump.c,v 1.55 2005/05/12 00:26:50 lhf Exp $ | |
| 3 | 3 | ** load pre-compiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -206,7 +206,8 @@ static Proto* LoadFunction (LoadState* S, TString* p) · 200 unmodified lines | ||
| 206 | 206 | Proto* f=luaF_newproto(S->L); |
| 207 | 207 | setptvalue2s(S->L,S->L->top,f); incr_top(S->L); |
| 208 | 208 | f->source=LoadString(S); if (f->source==NULL) f->source=p; |
| 209 | − f->lineDefined=LoadInt(S); | |
| 209 | + f->linedefined=LoadInt(S); | |
| 210 | + f->lastlinedefined=LoadInt(S); | |
| 210 | 211 | f->nups=LoadByte(S); |
| 211 | 212 | f->numparams=LoadByte(S); |
| 212 | 213 | f->is_vararg=LoadByte(S); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lundump.h,v 1.34 2004/11/25 09:31:41 lhf Exp $ | |
| 2 | +** $Id: lundump.h,v 1.35 2005/05/12 00:26:50 lhf Exp $ | |
| 3 | 3 | ** load pre-compiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -11,16 +11,16 @@ · 5 unmodified lines | ||
| 11 | 11 | #include "lzio.h" |
| 12 | 12 | |
| 13 | 13 | /* load one chunk; from lundump.c */ |
| 14 | −Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char *name); | |
| 14 | +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char *name); | |
| 15 | 15 | |
| 16 | 16 | /* find byte order; from lundump.c */ |
| 17 | −int luaU_endianness (void); | |
| 17 | +LUAI_FUNC int luaU_endianness (void); | |
| 18 | 18 | |
| 19 | 19 | /* dump one chunk; from ldump.c */ |
| 20 | −int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int strip); | |
| 20 | +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int strip); | |
| 21 | 21 | |
| 22 | 22 | /* print one chunk; from print.c */ |
| 23 | −void luaU_print (const Proto* f, int full); | |
| 23 | +LUAI_FUNC void luaU_print (const Proto* f, int full); | |
| 24 | 24 | |
| 25 | 25 | /* for header of binary files -- this is Lua 5.1 */ |
| 26 | 26 | #define VERSION 0x51 |
| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lvm.c,v 2.26 2005/02/23 17:30:22 roberto Exp $ | |
| 2 | +** $Id: lvm.c,v 2.44 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | |
| 8 | +#include <math.h> | |
| 9 | +#include <stdio.h> | |
| 8 | 10 | #include <stdlib.h> |
| 9 | 11 | #include <string.h> |
| 10 | 12 | |
| @@ -47,8 +49,9 @@ int luaV_tostring (lua_State *L, StkId obj) { · 36 unmodified lines | ||
| 47 | 49 | if (!ttisnumber(obj)) |
| 48 | 50 | return 0; |
| 49 | 51 | else { |
| 50 | − char s[MAX_NUMBER2STR]; | |
| 51 | − lua_number2str(s, nvalue(obj)); | |
| 52 | + char s[LUAI_MAXNUMBER2STR]; | |
| 53 | + lua_Number n = nvalue(obj); | |
| 54 | + lua_number2str(s, n); | |
| 52 | 55 | setsvalue2s(L, obj, luaS_new(L, s)); |
| 53 | 56 | return 1; |
| 54 | 57 | } |
| @@ -57,9 +60,8 @@ int luaV_tostring (lua_State *L, StkId obj) { · 2 unmodified lines | ||
| 57 | 60 | |
| 58 | 61 | static void traceexec (lua_State *L, const Instruction *pc) { |
| 59 | 62 | lu_byte mask = L->hookmask; |
| 60 | − CallInfo *ci = L->ci; | |
| 61 | − const Instruction *oldpc = ci->savedpc; | |
| 62 | − ci->savedpc = pc; | |
| 63 | + const Instruction *oldpc = L->savedpc; | |
| 64 | + L->savedpc = pc; | |
| 63 | 65 | if (mask > LUA_MASKLINE) { /* instruction-hook set? */ |
| 64 | 66 | if (L->hookcount == 0) { |
| 65 | 67 | resethookcount(L); |
| @@ -68,7 +70,7 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 2 unmodified lines | ||
| 68 | 70 | } |
| 69 | 71 | } |
| 70 | 72 | if (mask & LUA_MASKLINE) { |
| 71 | − Proto *p = ci_func(ci)->l.p; | |
| 73 | + Proto *p = ci_func(L->ci)->l.p; | |
| 72 | 74 | int npc = pcRel(pc, p); |
| 73 | 75 | int newline = getline(p, npc); |
| 74 | 76 | /* call linehook when enter a new function, when jump back (loop), |
| @@ -79,16 +81,12 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 4 unmodified lines | ||
| 79 | 81 | } |
| 80 | 82 | |
| 81 | 83 | |
| 82 | −static void prepTMcall (lua_State *L, const TValue *f, | |
| 84 | +static void callTMres (lua_State *L, StkId res, const TValue *f, | |
| 83 | 85 | const TValue *p1, const TValue *p2) { |
| 86 | + ptrdiff_t result = savestack(L, res); | |
| 84 | 87 | setobj2s(L, L->top, f); /* push function */ |
| 85 | 88 | setobj2s(L, L->top+1, p1); /* 1st argument */ |
| 86 | 89 | setobj2s(L, L->top+2, p2); /* 2nd argument */ |
| 87 | −} | |
| 88 | − | |
| 89 | − | |
| 90 | −static void callTMres (lua_State *L, StkId res) { | |
| 91 | − ptrdiff_t result = savestack(L, res); | |
| 92 | 90 | luaD_checkstack(L, 3); |
| 93 | 91 | L->top += 3; |
| 94 | 92 | luaD_call(L, L->top - 3, 1); |
| @@ -99,15 +97,18 @@ static void callTMres (lua_State *L, StkId res) { · 4 unmodified lines | ||
| 99 | 97 | |
| 100 | 98 | |
| 101 | 99 | |
| 102 | −static void callTM (lua_State *L) { | |
| 100 | +static void callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3) { | |
| 101 | + setobj2s(L, L->top, f); /* push function */ | |
| 102 | + setobj2s(L, L->top+1, p1); /* 1st argument */ | |
| 103 | + setobj2s(L, L->top+2, p2); /* 2nd argument */ | |
| 104 | + setobj2s(L, L->top+3, p3); /* 3th argument */ | |
| 103 | 105 | luaD_checkstack(L, 4); |
| 104 | 106 | L->top += 4; |
| 105 | 107 | luaD_call(L, L->top - 4, 0); |
| 106 | 108 | } |
| 107 | 109 | |
| 108 | 110 | |
| 109 | −StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, | |
| 110 | − const Instruction *pc) { | |
| 111 | +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { | |
| 111 | 112 | int loop; |
| 112 | 113 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 113 | 114 | const TValue *tm; |
| @@ -117,30 +118,23 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, · 3 unmodified lines | ||
| 117 | 118 | if (!ttisnil(res) || /* result is no nil? */ |
| 118 | 119 | (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ |
| 119 | 120 | setobj2s(L, val, res); |
| 120 | − return L->base; | |
| 121 | + return; | |
| 121 | 122 | } |
| 122 | 123 | /* else will try the tag method */ |
| 123 | 124 | } |
| 124 | − else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { | |
| 125 | − L->ci->savedpc = pc; | |
| 125 | + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) | |
| 126 | 126 | luaG_typeerror(L, t, "index"); |
| 127 | − } | |
| 128 | 127 | if (ttisfunction(tm)) { |
| 129 | − L->ci->savedpc = pc; | |
| 130 | − prepTMcall(L, tm, t, key); | |
| 131 | − callTMres(L, val); | |
| 132 | − return L->base; | |
| 128 | + callTMres(L, val, tm, t, key); | |
| 129 | + return; | |
| 133 | 130 | } |
| 134 | 131 | t = tm; /* else repeat with `tm' */ |
| 135 | 132 | } |
| 136 | − L->ci->savedpc = pc; | |
| 137 | 133 | luaG_runerror(L, "loop in gettable"); |
| 138 | − return NULL; /* to avoid warnings */ | |
| 139 | 134 | } |
| 140 | 135 | |
| 141 | 136 | |
| 142 | −StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, | |
| 143 | − const Instruction *pc) { | |
| 137 | +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { | |
| 144 | 138 | int loop; |
| 145 | 139 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 146 | 140 | const TValue *tm; |
| @@ -151,26 +145,19 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, · 4 unmodified lines | ||
| 151 | 145 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ |
| 152 | 146 | setobj2t(L, oldval, val); |
| 153 | 147 | luaC_barriert(L, h, val); |
| 154 | − return L->base; | |
| 148 | + return; | |
| 155 | 149 | } |
| 156 | 150 | /* else will try the tag method */ |
| 157 | 151 | } |
| 158 | − else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) { | |
| 159 | − L->ci->savedpc = pc; | |
| 152 | + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) | |
| 160 | 153 | luaG_typeerror(L, t, "index"); |
| 161 | − } | |
| 162 | 154 | if (ttisfunction(tm)) { |
| 163 | − L->ci->savedpc = pc; | |
| 164 | − prepTMcall(L, tm, t, key); | |
| 165 | − setobj2s(L, L->top+3, val); /* 3th argument */ | |
| 166 | − callTM(L); | |
| 167 | − return L->base; | |
| 155 | + callTM(L, tm, t, key, val); | |
| 156 | + return; | |
| 168 | 157 | } |
| 169 | 158 | t = tm; /* else repeat with `tm' */ |
| 170 | 159 | } |
| 171 | − L->ci->savedpc = pc; | |
| 172 | 160 | luaG_runerror(L, "loop in settable"); |
| 173 | − return NULL; /* to avoid warnings */ | |
| 174 | 161 | } |
| 175 | 162 | |
| 176 | 163 | |
| @@ -180,8 +167,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, · 3 unmodified lines | ||
| 180 | 167 | if (ttisnil(tm)) |
| 181 | 168 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ |
| 182 | 169 | if (!ttisfunction(tm)) return 0; |
| 183 | − prepTMcall(L, tm, p1, p2); | |
| 184 | − callTMres(L, res); | |
| 170 | + callTMres(L, res, tm, p1, p2); | |
| 185 | 171 | return 1; |
| 186 | 172 | } |
| 187 | 173 | |
| @@ -208,8 +194,7 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, · 20 unmodified lines | ||
| 208 | 194 | tm2 = luaT_gettmbyobj(L, p2, event); |
| 209 | 195 | if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ |
| 210 | 196 | return -1; |
| 211 | − prepTMcall(L, tm1, p1, p2); | |
| 212 | − callTMres(L, L->top); | |
| 197 | + callTMres(L, L->top, tm1, p1, p2); | |
| 213 | 198 | return !l_isfalse(L->top); |
| 214 | 199 | } |
| 215 | 200 | |
| @@ -241,7 +226,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 25 unmodified lines | ||
| 241 | 226 | if (ttype(l) != ttype(r)) |
| 242 | 227 | return luaG_ordererror(L, l, r); |
| 243 | 228 | else if (ttisnumber(l)) |
| 244 | − return num_lt(nvalue(l), nvalue(r)); | |
| 229 | + return luai_numlt(nvalue(l), nvalue(r)); | |
| 245 | 230 | else if (ttisstring(l)) |
| 246 | 231 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
| 247 | 232 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) |
| @@ -255,7 +240,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { · 7 unmodified lines | ||
| 255 | 240 | if (ttype(l) != ttype(r)) |
| 256 | 241 | return luaG_ordererror(L, l, r); |
| 257 | 242 | else if (ttisnumber(l)) |
| 258 | − return num_le(nvalue(l), nvalue(r)); | |
| 243 | + return luai_numle(nvalue(l), nvalue(r)); | |
| 259 | 244 | else if (ttisstring(l)) |
| 260 | 245 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
| 261 | 246 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ |
| @@ -271,7 +256,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { · 9 unmodified lines | ||
| 271 | 256 | lua_assert(ttype(t1) == ttype(t2)); |
| 272 | 257 | switch (ttype(t1)) { |
| 273 | 258 | case LUA_TNIL: return 1; |
| 274 | − case LUA_TNUMBER: return num_eq(nvalue(t1), nvalue(t2)); | |
| 259 | + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); | |
| 275 | 260 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ |
| 276 | 261 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
| 277 | 262 | case LUA_TUSERDATA: { |
| @@ -288,8 +273,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { · 10 unmodified lines | ||
| 288 | 273 | default: return gcvalue(t1) == gcvalue(t2); |
| 289 | 274 | } |
| 290 | 275 | if (tm == NULL) return 0; /* no TM? */ |
| 291 | − prepTMcall(L, tm, t1, t2); | |
| 292 | − callTMres(L, L->top); /* call TM */ | |
| 276 | + callTMres(L, L->top, tm, t1, t2); /* call TM */ | |
| 293 | 277 | return !l_isfalse(L->top); |
| 294 | 278 | } |
| 295 | 279 | |
| @@ -328,18 +312,19 @@ void luaV_concat (lua_State *L, int total, int last) { · 32 unmodified lines | ||
| 328 | 312 | |
| 329 | 313 | |
| 330 | 314 | static StkId Arith (lua_State *L, StkId ra, const TValue *rb, |
| 331 | − const TValue *rc, TMS op, const Instruction *pc) { | |
| 315 | + const TValue *rc, TMS op) { | |
| 332 | 316 | TValue tempb, tempc; |
| 333 | 317 | const TValue *b, *c; |
| 334 | − L->ci->savedpc = pc; | |
| 335 | 318 | if ((b = luaV_tonumber(rb, &tempb)) != NULL && |
| 336 | 319 | (c = luaV_tonumber(rc, &tempc)) != NULL) { |
| 320 | + lua_Number nb = nvalue(b), nc = nvalue(c); | |
| 337 | 321 | switch (op) { |
| 338 | − case TM_ADD: setnvalue(ra, num_add(nvalue(b), nvalue(c))); break; | |
| 339 | − case TM_SUB: setnvalue(ra, num_sub(nvalue(b), nvalue(c))); break; | |
| 340 | − case TM_MUL: setnvalue(ra, num_mul(nvalue(b), nvalue(c))); break; | |
| 341 | − case TM_DIV: setnvalue(ra, num_div(nvalue(b), nvalue(c))); break; | |
| 342 | − case TM_POW: setnvalue(ra, num_pow(nvalue(b), nvalue(c))); break; | |
| 322 | + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; | |
| 323 | + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; | |
| 324 | + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; | |
| 325 | + case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; | |
| 326 | + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; | |
| 327 | + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; | |
| 343 | 328 | default: lua_assert(0); break; |
| 344 | 329 | } |
| 345 | 330 | } |
| @@ -354,7 +339,7 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, · 8 unmodified lines | ||
| 354 | 339 | ** some macros for common tasks in `luaV_execute' |
| 355 | 340 | */ |
| 356 | 341 | |
| 357 | −#define runtime_check(L, c) { if (!(c)) return 0; } | |
| 342 | +#define runtime_check(L, c) { if (!(c)) break; } | |
| 358 | 343 | |
| 359 | 344 | #define RA(i) (base+GETARG_A(i)) |
| 360 | 345 | /* to be used after possible stack reallocation */ |
| @@ -367,19 +352,22 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, · 6 unmodified lines | ||
| 367 | 352 | #define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) |
| 368 | 353 | |
| 369 | 354 | |
| 370 | −#define dojump(L,pc,i) {(pc) += (i); lua_threadyield(L);} | |
| 355 | +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} | |
| 356 | + | |
| 357 | + | |
| 358 | +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } | |
| 371 | 359 | |
| 372 | 360 | |
| 373 | 361 | StkId luaV_execute (lua_State *L, int nexeccalls) { |
| 374 | 362 | LClosure *cl; |
| 375 | − TValue *k; | |
| 376 | 363 | StkId base; |
| 364 | + TValue *k; | |
| 377 | 365 | const Instruction *pc; |
| 378 | 366 | callentry: /* entry point when calling new functions */ |
| 379 | 367 | if (L->hookmask & LUA_MASKCALL) |
| 380 | 368 | luaD_callhook(L, LUA_HOOKCALL, -1); |
| 381 | 369 | retentry: /* entry point when returning to old functions */ |
| 382 | − pc = L->ci->savedpc; | |
| 370 | + pc = L->savedpc; | |
| 383 | 371 | cl = &clvalue(L->ci->func)->l; |
| 384 | 372 | base = L->base; |
| 385 | 373 | k = cl->p->k; |
| @@ -389,16 +377,16 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines | ||
| 389 | 377 | StkId ra; |
| 390 | 378 | if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && |
| 391 | 379 | (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { |
| 392 | − traceexec(L, pc); /***/ | |
| 380 | + traceexec(L, pc); | |
| 393 | 381 | if (L->status == LUA_YIELD) { /* did hook yield? */ |
| 394 | − L->ci->savedpc = pc - 1; | |
| 382 | + L->savedpc = pc - 1; | |
| 395 | 383 | return NULL; |
| 396 | 384 | } |
| 397 | 385 | base = L->base; |
| 398 | 386 | } |
| 399 | 387 | /* warning!! several calls may realloc the stack and invalidate `ra' */ |
| 400 | 388 | ra = RA(i); |
| 401 | − lua_assert(base == L->ci->base && base == L->base); | |
| 389 | + lua_assert(base == L->base && L->base == L->ci->base); | |
| 402 | 390 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); |
| 403 | 391 | lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); |
| 404 | 392 | switch (GET_OPCODE(i)) { |
| @@ -432,18 +420,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 27 unmodified lines | ||
| 432 | 420 | TValue *rb = KBx(i); |
| 433 | 421 | sethvalue(L, &g, cl->env); |
| 434 | 422 | lua_assert(ttisstring(rb)); |
| 435 | − base = luaV_gettable(L, &g, rb, ra, pc); /***/ | |
| 423 | + Protect(luaV_gettable(L, &g, rb, ra)); | |
| 436 | 424 | continue; |
| 437 | 425 | } |
| 438 | 426 | case OP_GETTABLE: { |
| 439 | − base = luaV_gettable(L, RB(i), RKC(i), ra, pc); /***/ | |
| 427 | + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); | |
| 440 | 428 | continue; |
| 441 | 429 | } |
| 442 | 430 | case OP_SETGLOBAL: { |
| 443 | 431 | TValue g; |
| 444 | 432 | sethvalue(L, &g, cl->env); |
| 445 | 433 | lua_assert(ttisstring(KBx(i))); |
| 446 | − base = luaV_settable(L, &g, KBx(i), ra, pc); /***/ | |
| 434 | + Protect(luaV_settable(L, &g, KBx(i), ra)); | |
| 447 | 435 | continue; |
| 448 | 436 | } |
| 449 | 437 | case OP_SETUPVAL: { |
| @@ -453,86 +441,101 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines | ||
| 453 | 441 | continue; |
| 454 | 442 | } |
| 455 | 443 | case OP_SETTABLE: { |
| 456 | − base = luaV_settable(L, ra, RKB(i), RKC(i), pc); /***/ | |
| 444 | + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); | |
| 457 | 445 | continue; |
| 458 | 446 | } |
| 459 | 447 | case OP_NEWTABLE: { |
| 460 | 448 | int b = GETARG_B(i); |
| 461 | 449 | int c = GETARG_C(i); |
| 462 | 450 | sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); |
| 463 | − L->ci->savedpc = pc; | |
| 464 | − luaC_checkGC(L); /***/ | |
| 465 | − base = L->base; | |
| 451 | + Protect(luaC_checkGC(L)); | |
| 466 | 452 | continue; |
| 467 | 453 | } |
| 468 | 454 | case OP_SELF: { |
| 469 | 455 | StkId rb = RB(i); |
| 470 | 456 | setobjs2s(L, ra+1, rb); |
| 471 | − base = luaV_gettable(L, rb, RKC(i), ra, pc); /***/ | |
| 457 | + Protect(luaV_gettable(L, rb, RKC(i), ra)); | |
| 472 | 458 | continue; |
| 473 | 459 | } |
| 474 | 460 | case OP_ADD: { |
| 475 | 461 | TValue *rb = RKB(i); |
| 476 | 462 | TValue *rc = RKC(i); |
| 477 | 463 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 478 | − setnvalue(ra, num_add(nvalue(rb), nvalue(rc))); | |
| 464 | + lua_Number nb = nvalue(rb), nc = nvalue(rc); | |
| 465 | + setnvalue(ra, luai_numadd(nb, nc)); | |
| 479 | 466 | } |
| 480 | 467 | else |
| 481 | − base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ | |
| 468 | + Protect(Arith(L, ra, rb, rc, TM_ADD)); | |
| 482 | 469 | continue; |
| 483 | 470 | } |
| 484 | 471 | case OP_SUB: { |
| 485 | 472 | TValue *rb = RKB(i); |
| 486 | 473 | TValue *rc = RKC(i); |
| 487 | 474 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 488 | − setnvalue(ra, num_sub(nvalue(rb), nvalue(rc))); | |
| 475 | + lua_Number nb = nvalue(rb), nc = nvalue(rc); | |
| 476 | + setnvalue(ra, luai_numsub(nb, nc)); | |
| 489 | 477 | } |
| 490 | 478 | else |
| 491 | − base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ | |
| 479 | + Protect(Arith(L, ra, rb, rc, TM_SUB)); | |
| 492 | 480 | continue; |
| 493 | 481 | } |
| 494 | 482 | case OP_MUL: { |
| 495 | 483 | TValue *rb = RKB(i); |
| 496 | 484 | TValue *rc = RKC(i); |
| 497 | 485 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 498 | − setnvalue(ra, num_mul(nvalue(rb), nvalue(rc))); | |
| 486 | + lua_Number nb = nvalue(rb), nc = nvalue(rc); | |
| 487 | + setnvalue(ra, luai_nummul(nb, nc)); | |
| 499 | 488 | } |
| 500 | 489 | else |
| 501 | − base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ | |
| 490 | + Protect(Arith(L, ra, rb, rc, TM_MUL)); | |
| 502 | 491 | continue; |
| 503 | 492 | } |
| 504 | 493 | case OP_DIV: { |
| 505 | 494 | TValue *rb = RKB(i); |
| 506 | 495 | TValue *rc = RKC(i); |
| 507 | 496 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 508 | − setnvalue(ra, num_div(nvalue(rb), nvalue(rc))); | |
| 497 | + lua_Number nb = nvalue(rb), nc = nvalue(rc); | |
| 498 | + setnvalue(ra, luai_numdiv(nb, nc)); | |
| 499 | + } | |
| 500 | + else | |
| 501 | + Protect(Arith(L, ra, rb, rc, TM_DIV)); | |
| 502 | + continue; | |
| 503 | + } | |
| 504 | + case OP_MOD: { | |
| 505 | + TValue *rb = RKB(i); | |
| 506 | + TValue *rc = RKC(i); | |
| 507 | + if (ttisnumber(rb) && ttisnumber(rc)) { | |
| 508 | + lua_Number nb = nvalue(rb), nc = nvalue(rc); | |
| 509 | + setnvalue(ra, luai_nummod(nb, nc)); | |
| 509 | 510 | } |
| 510 | 511 | else |
| 511 | − base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ | |
| 512 | + Protect(Arith(L, ra, rb, rc, TM_MOD)); | |
| 512 | 513 | continue; |
| 513 | 514 | } |
| 514 | 515 | case OP_POW: { |
| 515 | 516 | TValue *rb = RKB(i); |
| 516 | 517 | TValue *rc = RKC(i); |
| 517 | 518 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 518 | − setnvalue(ra, num_pow(nvalue(rb), nvalue(rc))); | |
| 519 | + lua_Number nb = nvalue(rb), nc = nvalue(rc); | |
| 520 | + setnvalue(ra, luai_numpow(nb, nc)); | |
| 519 | 521 | } |
| 520 | 522 | else |
| 521 | − base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ | |
| 523 | + Protect(Arith(L, ra, rb, rc, TM_POW)); | |
| 522 | 524 | continue; |
| 523 | 525 | } |
| 524 | 526 | case OP_UNM: { |
| 525 | 527 | const TValue *rb = RB(i); |
| 526 | 528 | TValue temp; |
| 527 | 529 | if (tonumber(rb, &temp)) { |
| 528 | − setnvalue(ra, num_unm(nvalue(rb))); | |
| 530 | + lua_Number nb = nvalue(rb); | |
| 531 | + setnvalue(ra, luai_numunm(nb)); | |
| 529 | 532 | } |
| 530 | 533 | else { |
| 531 | − setnilvalue(&temp); | |
| 532 | − L->ci->savedpc = pc; | |
| 533 | − if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/ | |
| 534 | − luaG_aritherror(L, RB(i), &temp); | |
| 535 | − base = L->base; | |
| 534 | + rb = RB(i); /* `tonumber' erased `rb' */ | |
| 535 | + Protect( | |
| 536 | + if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_UNM)) | |
| 537 | + luaG_aritherror(L, rb, &luaO_nilobject); | |
| 538 | + ) | |
| 536 | 539 | } |
| 537 | 540 | continue; |
| 538 | 541 | } |
| @@ -541,13 +544,23 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 2 unmodified lines | ||
| 541 | 544 | setbvalue(ra, res); |
| 542 | 545 | continue; |
| 543 | 546 | } |
| 547 | + case OP_SIZ: { | |
| 548 | + const TValue *rb = RB(i); | |
| 549 | + if (ttype(rb) == LUA_TTABLE) { | |
| 550 | + setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); | |
| 551 | + } | |
| 552 | + else { /* try metamethod */ | |
| 553 | + Protect( | |
| 554 | + if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_SIZ)) | |
| 555 | + luaG_typeerror(L, rb, "get size of"); | |
| 556 | + ) | |
| 557 | + } | |
| 558 | + continue; | |
| 559 | + } | |
| 544 | 560 | case OP_CONCAT: { |
| 545 | 561 | int b = GETARG_B(i); |
| 546 | 562 | int c = GETARG_C(i); |
| 547 | − L->ci->savedpc = pc; | |
| 548 | − luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ | |
| 549 | − luaC_checkGC(L); /***/ | |
| 550 | − base = L->base; | |
| 563 | + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); | |
| 551 | 564 | setobjs2s(L, RA(i), base+b); |
| 552 | 565 | continue; |
| 553 | 566 | } |
| @@ -556,24 +569,27 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 2 unmodified lines | ||
| 556 | 569 | continue; |
| 557 | 570 | } |
| 558 | 571 | case OP_EQ: { |
| 559 | − L->ci->savedpc = pc; | |
| 560 | − if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | |
| 561 | − else dojump(L, pc, GETARG_sBx(*pc) + 1); | |
| 562 | − base = L->base; | |
| 572 | + Protect( | |
| 573 | + if (equalobj(L, RKB(i), RKC(i)) == GETARG_A(i)) | |
| 574 | + dojump(L, pc, GETARG_sBx(*pc)); | |
| 575 | + ) | |
| 576 | + pc++; | |
| 563 | 577 | continue; |
| 564 | 578 | } |
| 565 | 579 | case OP_LT: { |
| 566 | − L->ci->savedpc = pc; | |
| 567 | − if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | |
| 568 | − else dojump(L, pc, GETARG_sBx(*pc) + 1); | |
| 569 | − base = L->base; | |
| 580 | + Protect( | |
| 581 | + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) | |
| 582 | + dojump(L, pc, GETARG_sBx(*pc)); | |
| 583 | + ) | |
| 584 | + pc++; | |
| 570 | 585 | continue; |
| 571 | 586 | } |
| 572 | 587 | case OP_LE: { |
| 573 | − L->ci->savedpc = pc; | |
| 574 | − if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | |
| 575 | − else dojump(L, pc, GETARG_sBx(*pc) + 1); | |
| 576 | − base = L->base; | |
| 588 | + Protect( | |
| 589 | + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) | |
| 590 | + dojump(L, pc, GETARG_sBx(*pc)); | |
| 591 | + ) | |
| 592 | + pc++; | |
| 577 | 593 | continue; |
| 578 | 594 | } |
| 579 | 595 | case OP_TEST: { |
| @@ -585,75 +601,71 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 5 unmodified lines | ||
| 585 | 601 | } |
| 586 | 602 | continue; |
| 587 | 603 | } |
| 588 | − case OP_CALL: { /***/ | |
| 589 | − int pcr; | |
| 604 | + case OP_CALL: { | |
| 590 | 605 | int b = GETARG_B(i); |
| 591 | 606 | int nresults = GETARG_C(i) - 1; |
| 592 | 607 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
| 593 | − L->ci->savedpc = pc; | |
| 594 | − pcr = luaD_precall(L, ra, nresults); | |
| 595 | − if (pcr == PCRLUA) { | |
| 596 | − nexeccalls++; | |
| 597 | − goto callentry; /* restart luaV_execute over new Lua function */ | |
| 598 | − } | |
| 599 | − else if (pcr == PCRC) { | |
| 600 | − /* it was a C function (`precall' called it); adjust results */ | |
| 601 | − if (nresults >= 0) L->top = L->ci->top; | |
| 602 | − base = L->base; | |
| 603 | − continue; | |
| 604 | − } | |
| 605 | − else { | |
| 606 | − lua_assert(pcr == PCRYIELD); | |
| 607 | − return NULL; | |
| 608 | + L->savedpc = pc; | |
| 609 | + switch (luaD_precall(L, ra, nresults)) { | |
| 610 | + case PCRLUA: { | |
| 611 | + nexeccalls++; | |
| 612 | + goto callentry; /* restart luaV_execute over new Lua function */ | |
| 613 | + } | |
| 614 | + case PCRC: { | |
| 615 | + /* it was a C function (`precall' called it); adjust results */ | |
| 616 | + if (nresults >= 0) L->top = L->ci->top; | |
| 617 | + base = L->base; | |
| 618 | + continue; | |
| 619 | + } | |
| 620 | + default: { | |
| 621 | + return NULL; | |
| 622 | + } | |
| 608 | 623 | } |
| 609 | 624 | } |
| 610 | − case OP_TAILCALL: { /***/ | |
| 611 | − int pcr; | |
| 625 | + case OP_TAILCALL: { | |
| 612 | 626 | int b = GETARG_B(i); |
| 613 | 627 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
| 614 | − L->ci->savedpc = pc; | |
| 628 | + L->savedpc = pc; | |
| 615 | 629 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); |
| 616 | − pcr = luaD_precall(L, ra, LUA_MULTRET); | |
| 617 | − if (pcr == PCRLUA) { | |
| 618 | − /* tail call: put new frame in place of previous one */ | |
| 619 | − CallInfo *ci = L->ci - 1; /* previous frame */ | |
| 620 | − int aux; | |
| 621 | − StkId func = ci->func; | |
| 622 | − StkId pfunc = (ci+1)->func; /* previous function index */ | |
| 623 | − if (L->openupval) luaF_close(L, base); | |
| 624 | − base = ci->base = ci->func + ((ci+1)->base - pfunc); | |
| 625 | − L->base = base; | |
| 626 | − for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ | |
| 627 | − setobjs2s(L, func+aux, pfunc+aux); | |
| 628 | − ci->top = L->top = func+aux; /* correct top */ | |
| 629 | − lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); | |
| 630 | − ci->savedpc = L->ci->savedpc; | |
| 631 | − ci->tailcalls++; /* one more call lost */ | |
| 632 | − L->ci--; /* remove new frame */ | |
| 633 | − goto callentry; | |
| 634 | − } | |
| 635 | − else if (pcr == PCRC) { | |
| 636 | − /* it was a C function (`precall' called it) */ | |
| 637 | − base = L->base; | |
| 638 | − continue; | |
| 639 | − } | |
| 640 | − else { | |
| 641 | − lua_assert(pcr == PCRYIELD); | |
| 642 | − return NULL; | |
| 630 | + switch (luaD_precall(L, ra, LUA_MULTRET)) { | |
| 631 | + case PCRLUA: { | |
| 632 | + /* tail call: put new frame in place of previous one */ | |
| 633 | + CallInfo *ci = L->ci - 1; /* previous frame */ | |
| 634 | + int aux; | |
| 635 | + StkId func = ci->func; | |
| 636 | + StkId pfunc = (ci+1)->func; /* previous function index */ | |
| 637 | + if (L->openupval) luaF_close(L, ci->base); | |
| 638 | + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); | |
| 639 | + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ | |
| 640 | + setobjs2s(L, func+aux, pfunc+aux); | |
| 641 | + ci->top = L->top = func+aux; /* correct top */ | |
| 642 | + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); | |
| 643 | + ci->savedpc = L->savedpc; | |
| 644 | + ci->tailcalls++; /* one more call lost */ | |
| 645 | + L->ci--; /* remove new frame */ | |
| 646 | + goto callentry; | |
| 647 | + } | |
| 648 | + case PCRC: { | |
| 649 | + /* it was a C function (`precall' called it) */ | |
| 650 | + base = L->base; | |
| 651 | + continue; | |
| 652 | + } | |
| 653 | + default: { | |
| 654 | + return NULL; | |
| 655 | + } | |
| 643 | 656 | } |
| 644 | 657 | } |
| 645 | 658 | case OP_RETURN: { |
| 646 | − CallInfo *ci = L->ci - 1; /* previous function frame */ | |
| 647 | 659 | int b = GETARG_B(i); |
| 648 | 660 | if (b != 0) L->top = ra+b-1; |
| 649 | 661 | if (L->openupval) luaF_close(L, base); |
| 650 | − L->ci->savedpc = pc; | |
| 662 | + L->savedpc = pc; | |
| 651 | 663 | if (--nexeccalls == 0) /* was previous function running `here'? */ |
| 652 | 664 | return ra; /* no: return */ |
| 653 | 665 | else { /* yes: continue its execution */ |
| 654 | − int nresults = (ci+1)->nresults; | |
| 655 | − lua_assert(isLua(ci)); | |
| 656 | − lua_assert(GET_OPCODE(*(ci->savedpc - 1)) == OP_CALL); | |
| 666 | + int nresults = L->ci->nresults; | |
| 667 | + lua_assert(isLua(L->ci - 1)); | |
| 668 | + lua_assert(GET_OPCODE(*((L->ci - 1)->savedpc - 1)) == OP_CALL); | |
| 657 | 669 | luaD_poscall(L, nresults, ra); |
| 658 | 670 | if (nresults >= 0) L->top = L->ci->top; |
| 659 | 671 | goto retentry; |
| @@ -661,27 +673,27 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 1 unmodified line | ||
| 661 | 673 | } |
| 662 | 674 | case OP_FORLOOP: { |
| 663 | 675 | lua_Number step = nvalue(ra+2); |
| 664 | − lua_Number idx = num_add(nvalue(ra), step); /* increment index */ | |
| 676 | + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ | |
| 665 | 677 | lua_Number limit = nvalue(ra+1); |
| 666 | − if (step > 0 ? num_le(idx, limit) : num_le(limit, idx)) { | |
| 678 | + if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) { | |
| 667 | 679 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ |
| 668 | 680 | setnvalue(ra, idx); /* update internal index... */ |
| 669 | 681 | setnvalue(ra+3, idx); /* ...and external index */ |
| 670 | 682 | } |
| 671 | 683 | continue; |
| 672 | 684 | } |
| 673 | − case OP_FORPREP: { /***/ | |
| 685 | + case OP_FORPREP: { | |
| 674 | 686 | const TValue *init = ra; |
| 675 | 687 | const TValue *plimit = ra+1; |
| 676 | 688 | const TValue *pstep = ra+2; |
| 677 | − L->ci->savedpc = pc; | |
| 689 | + L->savedpc = pc; /* next steps may throw errors */ | |
| 678 | 690 | if (!tonumber(init, ra)) |
| 679 | − luaG_runerror(L, "`for' initial value must be a number"); | |
| 691 | + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); | |
| 680 | 692 | else if (!tonumber(plimit, ra+1)) |
| 681 | − luaG_runerror(L, "`for' limit must be a number"); | |
| 693 | + luaG_runerror(L, LUA_QL("for") " limit must be a number"); | |
| 682 | 694 | else if (!tonumber(pstep, ra+2)) |
| 683 | − luaG_runerror(L, "`for' step must be a number"); | |
| 684 | − setnvalue(ra, num_sub(nvalue(ra), nvalue(pstep))); | |
| 695 | + luaG_runerror(L, LUA_QL("for") " step must be a number"); | |
| 696 | + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); | |
| 685 | 697 | dojump(L, pc, GETARG_sBx(i)); |
| 686 | 698 | continue; |
| 687 | 699 | } |
| @@ -691,10 +703,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines | ||
| 691 | 703 | setobjs2s(L, cb+1, ra+1); |
| 692 | 704 | setobjs2s(L, cb, ra); |
| 693 | 705 | L->top = cb+3; /* func. + 2 args (state and index) */ |
| 694 | − L->ci->savedpc = pc; | |
| 695 | − luaD_call(L, cb, GETARG_C(i)); /***/ | |
| 706 | + Protect(luaD_call(L, cb, GETARG_C(i))); | |
| 696 | 707 | L->top = L->ci->top; |
| 697 | − base = L->base; | |
| 698 | 708 | cb = RA(i) + 3; /* previous call may change the stack */ |
| 699 | 709 | if (ttisnil(cb)) /* break loop? */ |
| 700 | 710 | pc++; /* skip jump (break loop) */ |
| @@ -704,27 +714,19 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines | ||
| 704 | 714 | } |
| 705 | 715 | continue; |
| 706 | 716 | } |
| 707 | − case OP_TFORPREP: { /* for compatibility only */ | |
| 708 | − if (ttistable(ra)) { | |
| 709 | − setobjs2s(L, ra+1, ra); | |
| 710 | − setobj2s(L, ra, luaH_getstr(hvalue(gt(L)), luaS_new(L, "next"))); | |
| 711 | − } | |
| 712 | − dojump(L, pc, GETARG_sBx(i)); | |
| 713 | − continue; | |
| 714 | − } | |
| 715 | 717 | case OP_SETLIST: { |
| 716 | 718 | int n = GETARG_B(i); |
| 717 | 719 | int c = GETARG_C(i); |
| 718 | 720 | int last; |
| 719 | 721 | Table *h; |
| 720 | − runtime_check(L, ttistable(ra)); | |
| 721 | − h = hvalue(ra); | |
| 722 | 722 | if (n == 0) { |
| 723 | 723 | n = L->top - ra - 1; |
| 724 | 724 | L->top = L->ci->top; |
| 725 | 725 | } |
| 726 | 726 | if (c == 0) c = cast(int, *pc++); |
| 727 | − last = ((c-1)*LFIELDS_PER_FLUSH) + n + LUA_FIRSTINDEX - 1; | |
| 727 | + runtime_check(L, ttistable(ra)); | |
| 728 | + h = hvalue(ra); | |
| 729 | + last = ((c-1)*LFIELDS_PER_FLUSH) + n; | |
| 728 | 730 | if (last > h->sizearray) /* needs more space? */ |
| 729 | 731 | luaH_resizearray(L, h, last); /* pre-alloc it at once */ |
| 730 | 732 | for (; n > 0; n--) { |
| @@ -755,9 +757,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 24 unmodified lines | ||
| 755 | 757 | } |
| 756 | 758 | } |
| 757 | 759 | setclvalue(L, ra, ncl); |
| 758 | − L->ci->savedpc = pc; | |
| 759 | − luaC_checkGC(L); /***/ | |
| 760 | − base = L->base; | |
| 760 | + Protect(luaC_checkGC(L)); | |
| 761 | 761 | continue; |
| 762 | 762 | } |
| 763 | 763 | case OP_VARARG: { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lvm.h,v 2.2 2004/05/14 19:25:09 roberto Exp $ | |
| 2 | +** $Id: lvm.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ | |
| 3 | 3 | ** Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -22,15 +22,15 @@ · 16 unmodified lines | ||
| 22 | 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) |
| 23 | 23 | |
| 24 | 24 | |
| 25 | −int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | |
| 26 | −int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); | |
| 27 | −const TValue *luaV_tonumber (const TValue *obj, TValue *n); | |
| 28 | −int luaV_tostring (lua_State *L, StkId obj); | |
| 29 | −StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, | |
| 30 | − const Instruction *pc); | |
| 31 | −StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, | |
| 32 | − const Instruction *pc); | |
| 33 | −StkId luaV_execute (lua_State *L, int nexeccalls); | |
| 34 | −void luaV_concat (lua_State *L, int total, int last); | |
| 25 | +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | |
| 26 | +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); | |
| 27 | +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); | |
| 28 | +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); | |
| 29 | +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, | |
| 30 | + StkId val); | |
| 31 | +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, | |
| 32 | + StkId val); | |
| 33 | +LUAI_FUNC StkId luaV_execute (lua_State *L, int nexeccalls); | |
| 34 | +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); | |
| 35 | 35 | |
| 36 | 36 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lzio.c,v 1.29 2004/04/30 20:13:38 roberto Exp $ | |
| 2 | +** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** a generic input stream interface |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -43,7 +43,7 @@ int luaZ_lookahead (ZIO *z) { · 37 unmodified lines | ||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | −void luaZ_init (lua_State *L, ZIO *z, lua_Chunkreader reader, void *data) { | |
| 46 | +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { | |
| 47 | 47 | z->L = L; |
| 48 | 48 | z->reader = reader; |
| 49 | 49 | z->data = data; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lzio.h,v 1.19 2003/10/03 16:05:34 roberto Exp $ | |
| 2 | +** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $ | |
| 3 | 3 | ** Buffered streams |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -17,26 +17,16 @@ · 11 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | typedef struct Zio ZIO; |
| 19 | 19 | |
| 20 | − | |
| 21 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) |
| 22 | 21 | |
| 23 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) |
| 24 | 23 | |
| 25 | −void luaZ_init (lua_State *L, ZIO *z, lua_Chunkreader reader, void *data); | |
| 26 | −size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ | |
| 27 | −int luaZ_lookahead (ZIO *z); | |
| 28 | − | |
| 29 | − | |
| 30 | − | |
| 31 | 24 | typedef struct Mbuffer { |
| 32 | 25 | char *buffer; |
| 33 | 26 | size_t n; |
| 34 | 27 | size_t buffsize; |
| 35 | 28 | } Mbuffer; |
| 36 | 29 | |
| 37 | − | |
| 38 | −char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); | |
| 39 | − | |
| 40 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) |
| 41 | 31 | |
| 42 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) |
| @@ -53,18 +43,25 @@ char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); · 10 unmodified lines | ||
| 53 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) |
| 54 | 44 | |
| 55 | 45 | |
| 46 | +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); | |
| 47 | +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, | |
| 48 | + void *data); | |
| 49 | +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ | |
| 50 | +LUAI_FUNC int luaZ_lookahead (ZIO *z); | |
| 51 | + | |
| 52 | + | |
| 56 | 53 | |
| 57 | 54 | /* --------- Private Part ------------------ */ |
| 58 | 55 | |
| 59 | 56 | struct Zio { |
| 60 | 57 | size_t n; /* bytes still unread */ |
| 61 | 58 | const char *p; /* current position in buffer */ |
| 62 | − lua_Chunkreader reader; | |
| 59 | + lua_Reader reader; | |
| 63 | 60 | void* data; /* additional data */ |
| 64 | 61 | lua_State *L; /* Lua state (for reader) */ |
| 65 | 62 | }; |
| 66 | 63 | |
| 67 | 64 | |
| 68 | −int luaZ_fill (ZIO *z); | |
| 65 | +LUAI_FUNC int luaZ_fill (ZIO *z); | |
| 69 | 66 | |
| 70 | 67 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: print.c,v 1.49 2004/11/25 09:31:41 lhf Exp $ | |
| 2 | +** $Id: print.c,v 1.50 2005/05/12 00:26:50 lhf Exp $ | |
| 3 | 3 | ** print bytecodes |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -76,9 +76,6 @@ static void PrintCode(const Proto* f) · 70 unmodified lines | ||
| 76 | 76 | int bx=GETARG_Bx(i); |
| 77 | 77 | int sbx=GETARG_sBx(i); |
| 78 | 78 | int line=getline(f,pc); |
| 79 | −#if 0 | |
| 80 | − printf("%0*lX",Sizeof(i)*2,i); | |
| 81 | −#endif | |
| 82 | 79 | printf("\t%d\t",pc+1); |
| 83 | 80 | if (line>0) printf("[%d]\t",line); else printf("[-]\t"); |
| 84 | 81 | printf("%-9s\t",luaP_opnames[o]); |
| @@ -133,7 +130,6 @@ static void PrintCode(const Proto* f) · 48 unmodified lines | ||
| 133 | 130 | case OP_JMP: |
| 134 | 131 | case OP_FORLOOP: |
| 135 | 132 | case OP_FORPREP: |
| 136 | − case OP_TFORPREP: | |
| 137 | 133 | printf("\t; to %d",sbx+pc+2); |
| 138 | 134 | break; |
| 139 | 135 | case OP_CLOSURE: |
| @@ -146,28 +142,25 @@ static void PrintCode(const Proto* f) · 6 unmodified lines | ||
| 146 | 142 | } |
| 147 | 143 | } |
| 148 | 144 | |
| 149 | −static const char* Source(const Proto* f) | |
| 150 | −{ | |
| 151 | − const char* s=getstr(f->source); | |
| 152 | − if (*s=='@' || *s=='=') | |
| 153 | − return s+1; | |
| 154 | − else if (*s==LUA_SIGNATURE[0]) | |
| 155 | − return "(bstring)"; | |
| 156 | − else | |
| 157 | − return "(string)"; | |
| 158 | −} | |
| 159 | − | |
| 160 | 145 | #define SS(x) (x==1)?"":"s" |
| 161 | 146 | #define S(x) x,SS(x) |
| 162 | 147 | |
| 163 | 148 | static void PrintHeader(const Proto* f) |
| 164 | 149 | { |
| 165 | − printf("\n%s <%s:%d> (%d instruction%s, %d bytes at %p)\n", | |
| 166 | − (f->lineDefined==0)?"main":"function",Source(f),f->lineDefined, | |
| 150 | + const char* s=getstr(f->source); | |
| 151 | + if (*s=='@' || *s=='=') | |
| 152 | + s++; | |
| 153 | + else if (*s==LUA_SIGNATURE[0]) | |
| 154 | + s="(bstring)"; | |
| 155 | + else | |
| 156 | + s="(string)"; | |
| 157 | + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", | |
| 158 | + (f->linedefined==0)?"main":"function",s, | |
| 159 | + f->linedefined,f->lastlinedefined, | |
| 167 | 160 | S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); |
| 168 | 161 | printf("%d%s param%s, %d stack%s, %d upvalue%s, ", |
| 169 | − f->numparams,f->is_vararg?"+":"",SS(f->numparams),S(f->maxstacksize), | |
| 170 | − S(f->nups)); | |
| 162 | + f->numparams,f->is_vararg?"+":"",SS(f->numparams), | |
| 163 | + S(f->maxstacksize),S(f->nups)); | |
| 171 | 164 | printf("%d local%s, %d constant%s, %d function%s\n", |
| 172 | 165 | S(f->sizelocvars),S(f->sizek),S(f->sizep)); |
| 173 | 166 | } |
| @@ -22,6 +22,5 @@ Here is a one-line summary of each program: · 21 unmodified lines | ||
| 22 | 22 | table.lua make table, grouping all data for the same item |
| 23 | 23 | trace-calls.lua trace calls |
| 24 | 24 | trace-globals.lua trace assigments to global variables |
| 25 | − undefined.lua catch "undefined" global variables | |
| 26 | 25 | xd.lua hex dump |
| 27 | 26 | |
| @@ -3,5 +3,5 @@ · 2 unmodified lines | ||
| 3 | 3 | |
| 4 | 4 | assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua") |
| 5 | 5 | f=assert(io.open("luac.out","wb")) |
| 6 | −f:write(string.dump(assert(loadfile(arg[1])))) | |
| 7 | −io.close(f) | |
| 6 | +assert(f:write(string.dump(assert(loadfile(arg[1]))))) | |
| 7 | +assert(io.close(f)) | |
| @@ -1,9 +0,0 @@ | ||
| 1 | −-- catch "undefined" global variables | |
| 2 | − | |
| 3 | −local f=function (t,i) error("undefined global variable `"..i.."'",2) end | |
| 4 | −setmetatable(getfenv(),{__index=f}) | |
| 5 | − | |
| 6 | −-- an example | |
| 7 | −a=1 | |
| 8 | −c=3 | |
| 9 | −print(a,b,c) -- `b' is undefined | |