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