Unified · Split
| @@ -32,7 +32,7 @@ This is Lua 5.1 (work). · 31 unmodified lines | ||
| 32 | 32 | |
| 33 | 33 | * If you have problems (and solutions!) |
| 34 | 34 | ------------------------------------- |
| 35 | − If "make" fails, please let us know (lua@tecgraf.puc-rio.br). | |
| 35 | + If "make" fails, please let us know. | |
| 36 | 36 | If you make changes to "config" or to the Makefiles, please send them to us. |
| 37 | 37 | |
| 38 | 38 | * Shared libraries |
| @@ -1,114 +1,115 @@ | ||
| 1 | −MANIFEST contents of Lua 5.1 (work2) distribution on Mon Sep 20 21:28:06 BRT 2004 | |
| 2 | −lua-5.1-work2 | |
| 3 | −lua-5.1-work2/COPYRIGHT | |
| 4 | −lua-5.1-work2/HISTORY | |
| 5 | −lua-5.1-work2/INSTALL | |
| 6 | −lua-5.1-work2/MANIFEST | |
| 7 | −lua-5.1-work2/Makefile | |
| 8 | −lua-5.1-work2/README | |
| 9 | −lua-5.1-work2/bin | |
| 10 | −lua-5.1-work2/build | |
| 11 | −lua-5.1-work2/config | |
| 12 | −lua-5.1-work2/etc | |
| 13 | −lua-5.1-work2/etc/Makefile | |
| 14 | −lua-5.1-work2/etc/README | |
| 15 | −lua-5.1-work2/etc/all.c | |
| 16 | −lua-5.1-work2/etc/lua.ico | |
| 17 | −lua-5.1-work2/etc/min.c | |
| 18 | −lua-5.1-work2/etc/noparser.c | |
| 19 | −lua-5.1-work2/etc/saconfig.c | |
| 20 | −lua-5.1-work2/include | |
| 21 | −lua-5.1-work2/include/Makefile | |
| 22 | −lua-5.1-work2/include/lauxlib.h | |
| 23 | −lua-5.1-work2/include/lua.h | |
| 24 | −lua-5.1-work2/include/luaconf.h | |
| 25 | −lua-5.1-work2/include/lualib.h | |
| 26 | −lua-5.1-work2/lib | |
| 27 | −lua-5.1-work2/src | |
| 28 | −lua-5.1-work2/src/Makefile | |
| 29 | −lua-5.1-work2/src/README | |
| 30 | −lua-5.1-work2/src/lapi.c | |
| 31 | −lua-5.1-work2/src/lapi.h | |
| 32 | −lua-5.1-work2/src/lcode.c | |
| 33 | −lua-5.1-work2/src/lcode.h | |
| 34 | −lua-5.1-work2/src/ldebug.c | |
| 35 | −lua-5.1-work2/src/ldebug.h | |
| 36 | −lua-5.1-work2/src/ldo.c | |
| 37 | −lua-5.1-work2/src/ldo.h | |
| 38 | −lua-5.1-work2/src/ldump.c | |
| 39 | −lua-5.1-work2/src/lfunc.c | |
| 40 | −lua-5.1-work2/src/lfunc.h | |
| 41 | −lua-5.1-work2/src/lgc.c | |
| 42 | −lua-5.1-work2/src/lgc.h | |
| 43 | −lua-5.1-work2/src/lib | |
| 44 | −lua-5.1-work2/src/lib/Makefile | |
| 45 | −lua-5.1-work2/src/lib/README | |
| 46 | −lua-5.1-work2/src/lib/lauxlib.c | |
| 47 | −lua-5.1-work2/src/lib/lbaselib.c | |
| 48 | −lua-5.1-work2/src/lib/ldblib.c | |
| 49 | −lua-5.1-work2/src/lib/linit.c | |
| 50 | −lua-5.1-work2/src/lib/liolib.c | |
| 51 | −lua-5.1-work2/src/lib/lmathlib.c | |
| 52 | −lua-5.1-work2/src/lib/loadlib.c | |
| 53 | −lua-5.1-work2/src/lib/loslib.c | |
| 54 | −lua-5.1-work2/src/lib/lstrlib.c | |
| 55 | −lua-5.1-work2/src/lib/ltablib.c | |
| 56 | −lua-5.1-work2/src/llex.c | |
| 57 | −lua-5.1-work2/src/llex.h | |
| 58 | −lua-5.1-work2/src/llimits.h | |
| 59 | −lua-5.1-work2/src/lmem.c | |
| 60 | −lua-5.1-work2/src/lmem.h | |
| 61 | −lua-5.1-work2/src/lobject.c | |
| 62 | −lua-5.1-work2/src/lobject.h | |
| 63 | −lua-5.1-work2/src/lopcodes.c | |
| 64 | −lua-5.1-work2/src/lopcodes.h | |
| 65 | −lua-5.1-work2/src/lparser.c | |
| 66 | −lua-5.1-work2/src/lparser.h | |
| 67 | −lua-5.1-work2/src/lstate.c | |
| 68 | −lua-5.1-work2/src/lstate.h | |
| 69 | −lua-5.1-work2/src/lstring.c | |
| 70 | −lua-5.1-work2/src/lstring.h | |
| 71 | −lua-5.1-work2/src/ltable.c | |
| 72 | −lua-5.1-work2/src/ltable.h | |
| 73 | −lua-5.1-work2/src/ltm.c | |
| 74 | −lua-5.1-work2/src/ltm.h | |
| 75 | −lua-5.1-work2/src/lua | |
| 76 | −lua-5.1-work2/src/lua/Makefile | |
| 77 | −lua-5.1-work2/src/lua/README | |
| 78 | −lua-5.1-work2/src/lua/lua.c | |
| 79 | −lua-5.1-work2/src/luac | |
| 80 | −lua-5.1-work2/src/luac/Makefile | |
| 81 | −lua-5.1-work2/src/luac/README | |
| 82 | −lua-5.1-work2/src/luac/luac.c | |
| 83 | −lua-5.1-work2/src/luac/print.c | |
| 84 | −lua-5.1-work2/src/lundump.c | |
| 85 | −lua-5.1-work2/src/lundump.h | |
| 86 | −lua-5.1-work2/src/lvm.c | |
| 87 | −lua-5.1-work2/src/lvm.h | |
| 88 | −lua-5.1-work2/src/lzio.c | |
| 89 | −lua-5.1-work2/src/lzio.h | |
| 90 | −lua-5.1-work2/test | |
| 91 | −lua-5.1-work2/test/README | |
| 92 | −lua-5.1-work2/test/bisect.lua | |
| 93 | −lua-5.1-work2/test/cf.lua | |
| 94 | −lua-5.1-work2/test/echo.lua | |
| 95 | −lua-5.1-work2/test/env.lua | |
| 96 | −lua-5.1-work2/test/factorial.lua | |
| 97 | −lua-5.1-work2/test/fib.lua | |
| 98 | −lua-5.1-work2/test/fibfor.lua | |
| 99 | −lua-5.1-work2/test/globals.lua | |
| 100 | −lua-5.1-work2/test/hello.lua | |
| 101 | −lua-5.1-work2/test/life.lua | |
| 102 | −lua-5.1-work2/test/lua | |
| 103 | −lua-5.1-work2/test/luac | |
| 104 | −lua-5.1-work2/test/luac.lua | |
| 105 | −lua-5.1-work2/test/printf.lua | |
| 106 | −lua-5.1-work2/test/readonly.lua | |
| 107 | −lua-5.1-work2/test/sieve.lua | |
| 108 | −lua-5.1-work2/test/sort.lua | |
| 109 | −lua-5.1-work2/test/table.lua | |
| 110 | −lua-5.1-work2/test/trace-calls.lua | |
| 111 | −lua-5.1-work2/test/trace-globals.lua | |
| 112 | −lua-5.1-work2/test/undefined.lua | |
| 113 | −lua-5.1-work2/test/xd.lua | |
| 1 | +MANIFEST contents of Lua 5.1 (work3) distribution on Mon Dec 6 23:00:22 BRST 2004 | |
| 2 | +lua-5.1-work3 | |
| 3 | +lua-5.1-work3/COPYRIGHT | |
| 4 | +lua-5.1-work3/HISTORY | |
| 5 | +lua-5.1-work3/INSTALL | |
| 6 | +lua-5.1-work3/MANIFEST | |
| 7 | +lua-5.1-work3/Makefile | |
| 8 | +lua-5.1-work3/README | |
| 9 | +lua-5.1-work3/bin | |
| 10 | +lua-5.1-work3/build | |
| 11 | +lua-5.1-work3/config | |
| 12 | +lua-5.1-work3/etc | |
| 13 | +lua-5.1-work3/etc/Makefile | |
| 14 | +lua-5.1-work3/etc/README | |
| 15 | +lua-5.1-work3/etc/all.c | |
| 16 | +lua-5.1-work3/etc/lua.hpp | |
| 17 | +lua-5.1-work3/etc/lua.ico | |
| 18 | +lua-5.1-work3/etc/min.c | |
| 19 | +lua-5.1-work3/etc/noparser.c | |
| 20 | +lua-5.1-work3/etc/saconfig.c | |
| 21 | +lua-5.1-work3/include | |
| 22 | +lua-5.1-work3/include/Makefile | |
| 23 | +lua-5.1-work3/include/lauxlib.h | |
| 24 | +lua-5.1-work3/include/lua.h | |
| 25 | +lua-5.1-work3/include/luaconf.h | |
| 26 | +lua-5.1-work3/include/lualib.h | |
| 27 | +lua-5.1-work3/lib | |
| 28 | +lua-5.1-work3/src | |
| 29 | +lua-5.1-work3/src/Makefile | |
| 30 | +lua-5.1-work3/src/README | |
| 31 | +lua-5.1-work3/src/lapi.c | |
| 32 | +lua-5.1-work3/src/lapi.h | |
| 33 | +lua-5.1-work3/src/lcode.c | |
| 34 | +lua-5.1-work3/src/lcode.h | |
| 35 | +lua-5.1-work3/src/ldebug.c | |
| 36 | +lua-5.1-work3/src/ldebug.h | |
| 37 | +lua-5.1-work3/src/ldo.c | |
| 38 | +lua-5.1-work3/src/ldo.h | |
| 39 | +lua-5.1-work3/src/ldump.c | |
| 40 | +lua-5.1-work3/src/lfunc.c | |
| 41 | +lua-5.1-work3/src/lfunc.h | |
| 42 | +lua-5.1-work3/src/lgc.c | |
| 43 | +lua-5.1-work3/src/lgc.h | |
| 44 | +lua-5.1-work3/src/lib | |
| 45 | +lua-5.1-work3/src/lib/Makefile | |
| 46 | +lua-5.1-work3/src/lib/README | |
| 47 | +lua-5.1-work3/src/lib/lauxlib.c | |
| 48 | +lua-5.1-work3/src/lib/lbaselib.c | |
| 49 | +lua-5.1-work3/src/lib/ldblib.c | |
| 50 | +lua-5.1-work3/src/lib/linit.c | |
| 51 | +lua-5.1-work3/src/lib/liolib.c | |
| 52 | +lua-5.1-work3/src/lib/lmathlib.c | |
| 53 | +lua-5.1-work3/src/lib/loadlib.c | |
| 54 | +lua-5.1-work3/src/lib/loslib.c | |
| 55 | +lua-5.1-work3/src/lib/lstrlib.c | |
| 56 | +lua-5.1-work3/src/lib/ltablib.c | |
| 57 | +lua-5.1-work3/src/llex.c | |
| 58 | +lua-5.1-work3/src/llex.h | |
| 59 | +lua-5.1-work3/src/llimits.h | |
| 60 | +lua-5.1-work3/src/lmem.c | |
| 61 | +lua-5.1-work3/src/lmem.h | |
| 62 | +lua-5.1-work3/src/lobject.c | |
| 63 | +lua-5.1-work3/src/lobject.h | |
| 64 | +lua-5.1-work3/src/lopcodes.c | |
| 65 | +lua-5.1-work3/src/lopcodes.h | |
| 66 | +lua-5.1-work3/src/lparser.c | |
| 67 | +lua-5.1-work3/src/lparser.h | |
| 68 | +lua-5.1-work3/src/lstate.c | |
| 69 | +lua-5.1-work3/src/lstate.h | |
| 70 | +lua-5.1-work3/src/lstring.c | |
| 71 | +lua-5.1-work3/src/lstring.h | |
| 72 | +lua-5.1-work3/src/ltable.c | |
| 73 | +lua-5.1-work3/src/ltable.h | |
| 74 | +lua-5.1-work3/src/ltm.c | |
| 75 | +lua-5.1-work3/src/ltm.h | |
| 76 | +lua-5.1-work3/src/lua | |
| 77 | +lua-5.1-work3/src/lua/Makefile | |
| 78 | +lua-5.1-work3/src/lua/README | |
| 79 | +lua-5.1-work3/src/lua/lua.c | |
| 80 | +lua-5.1-work3/src/luac | |
| 81 | +lua-5.1-work3/src/luac/Makefile | |
| 82 | +lua-5.1-work3/src/luac/README | |
| 83 | +lua-5.1-work3/src/luac/luac.c | |
| 84 | +lua-5.1-work3/src/luac/print.c | |
| 85 | +lua-5.1-work3/src/lundump.c | |
| 86 | +lua-5.1-work3/src/lundump.h | |
| 87 | +lua-5.1-work3/src/lvm.c | |
| 88 | +lua-5.1-work3/src/lvm.h | |
| 89 | +lua-5.1-work3/src/lzio.c | |
| 90 | +lua-5.1-work3/src/lzio.h | |
| 91 | +lua-5.1-work3/test | |
| 92 | +lua-5.1-work3/test/README | |
| 93 | +lua-5.1-work3/test/bisect.lua | |
| 94 | +lua-5.1-work3/test/cf.lua | |
| 95 | +lua-5.1-work3/test/echo.lua | |
| 96 | +lua-5.1-work3/test/env.lua | |
| 97 | +lua-5.1-work3/test/factorial.lua | |
| 98 | +lua-5.1-work3/test/fib.lua | |
| 99 | +lua-5.1-work3/test/fibfor.lua | |
| 100 | +lua-5.1-work3/test/globals.lua | |
| 101 | +lua-5.1-work3/test/hello.lua | |
| 102 | +lua-5.1-work3/test/life.lua | |
| 103 | +lua-5.1-work3/test/lua | |
| 104 | +lua-5.1-work3/test/luac | |
| 105 | +lua-5.1-work3/test/luac.lua | |
| 106 | +lua-5.1-work3/test/printf.lua | |
| 107 | +lua-5.1-work3/test/readonly.lua | |
| 108 | +lua-5.1-work3/test/sieve.lua | |
| 109 | +lua-5.1-work3/test/sort.lua | |
| 110 | +lua-5.1-work3/test/table.lua | |
| 111 | +lua-5.1-work3/test/trace-calls.lua | |
| 112 | +lua-5.1-work3/test/trace-globals.lua | |
| 113 | +lua-5.1-work3/test/undefined.lua | |
| 114 | +lua-5.1-work3/test/xd.lua | |
| 114 | 115 | END OF MANIFEST |
| @@ -14,8 +14,6 @@ all clean co klean: · 13 unmodified lines | ||
| 14 | 14 | cd src/luac; $(MAKE) $@ |
| 15 | 15 | cd src/lua; $(MAKE) $@ |
| 16 | 16 | |
| 17 | −clean klean: soclean | |
| 18 | − | |
| 19 | 17 | # in case they were not created during unpacking |
| 20 | 18 | all: bin lib |
| 21 | 19 | |
| @@ -38,27 +36,6 @@ install: all strip · 16 unmodified lines | ||
| 38 | 36 | $(INSTALL_DATA) lib/*.a $(INSTALL_LIB) |
| 39 | 37 | $(INSTALL_DATA) doc/*.1 $(INSTALL_MAN) |
| 40 | 38 | |
| 41 | −# shared libraries (for Linux) | |
| 42 | −so: | |
| 43 | − ld -o lib/liblua.so.$V -shared src/*.o | |
| 44 | − ld -o lib/liblualib.so.$V -shared src/lib/*.o | |
| 45 | − cd lib; ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so | |
| 46 | − | |
| 47 | −# binaries using shared libraries | |
| 48 | −sobin: | |
| 49 | − rm -f bin/lua* | |
| 50 | − cd src/lua; $(MAKE) | |
| 51 | − cd src/luac; $(MAKE) | |
| 52 | − | |
| 53 | −# install shared libraries | |
| 54 | −soinstall: | |
| 55 | − $(INSTALL_EXEC) lib/*.so.* $(INSTALL_LIB) | |
| 56 | − cd $(INSTALL_LIB); ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so | |
| 57 | − | |
| 58 | −# clean shared libraries | |
| 59 | −soclean: | |
| 60 | − rm -f lib/*.so* bin/lua* | |
| 61 | − | |
| 62 | 39 | # echo config parameters |
| 63 | 40 | echo: |
| 64 | 41 | @echo "" |
| @@ -98,7 +75,7 @@ lecho: · 33 unmodified lines | ||
| 98 | 75 | @make echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' |
| 99 | 76 | @echo "-- EOF" |
| 100 | 77 | |
| 101 | −# (end of Makefile) | |
| 102 | − | |
| 103 | 78 | newer: |
| 104 | 79 | @find . -newer MANIFEST -type f |
| 80 | + | |
| 81 | +# (end of Makefile) | |
| @@ -29,9 +29,10 @@ See HISTORY for a summary of changes since the last released version. · 28 unmodified lines | ||
| 29 | 29 | |
| 30 | 30 | * Contacting the authors |
| 31 | 31 | ---------------------- |
| 32 | − Send your comments, questions, and bug reports to lua@tecgraf.puc-rio.br. | |
| 32 | + Send your comments, questions, and bug reports to | |
| 33 | + lua-team AT tecgraf.puc-rio.br. | |
| 33 | 34 | For more information about the authors, see http://www.lua.org/authors.html . |
| 34 | − For reporting bugs, try also the mailing list: lua-l@tecgraf.puc-rio.br. | |
| 35 | + For reporting bugs, try also the mailing list: lua@bazar2.conectiva.com.br . | |
| 35 | 36 | For more information about this list, including instructions on how to |
| 36 | 37 | subscribe and access the archives, see http://www.lua.org/lua-l.html . |
| 37 | 38 | |
| @@ -21,15 +21,15 @@ USERCONF= · 20 unmodified lines | ||
| 21 | 21 | # interface (e.g., Linux, Solaris, IRIX, BSD, AIX, HPUX, and probably others), |
| 22 | 22 | # uncomment the next two lines. Also read the next paragraph. |
| 23 | 23 | # |
| 24 | −#LOADLIB= -DUSE_DLOPEN=1 | |
| 25 | −#DLLIB= -ldl | |
| 24 | +LOADLIB= -DUSE_DLOPEN=1 | |
| 25 | +DLLIB= -ldl | |
| 26 | 26 | # |
| 27 | 27 | # In Linux with gcc, you should also uncomment the next definition for |
| 28 | 28 | # MYLDFLAGS, which passes -E (= -export-dynamic) to the linker. This option |
| 29 | 29 | # allows dynamic libraries to link back to the `lua' program, so that they do |
| 30 | 30 | # not need the Lua libraries. (Other systems may have an equivalent facility.) |
| 31 | 31 | # |
| 32 | −#MYLDFLAGS= -Wl,-E | |
| 32 | +MYLDFLAGS= -Wl,-E | |
| 33 | 33 | # |
| 34 | 34 | # On Windows systems. support for dynamic loading is enabled by default. |
| 35 | 35 | # To disable this support, uncomment the next line. |
| @@ -33,7 +33,6 @@ · 32 unmodified lines | ||
| 33 | 33 | #include "linit.c" |
| 34 | 34 | #include "lmathlib.c" |
| 35 | 35 | #include "loadlib.c" |
| 36 | −#define pushresult pushresult2 | |
| 37 | 36 | #include "loslib.c" |
| 38 | 37 | #include "lstrlib.c" |
| 39 | 38 | #include "ltablib.c" |
| @@ -0,0 +1,8 @@ | ||
| 1 | +// lua.hpp | |
| 2 | +// Lua header files for C++ | |
| 3 | + | |
| 4 | +extern "C" { | |
| 5 | +#include "lua.h" | |
| 6 | +#include "lualib.h" | |
| 7 | +#include "lauxlib.h" | |
| 8 | +} | |
| @@ -43,5 +43,6 @@ int main(void) · 42 unmodified lines | ||
| 43 | 43 | lua_register(L,"print",print); |
| 44 | 44 | if (lua_load(L,getF,stdin,"=stdin") || lua_pcall(L,0,0,0)) |
| 45 | 45 | fprintf(stderr,"%s\n",lua_tostring(L,-1)); |
| 46 | + lua_close(L); | |
| 46 | 47 | return 0; |
| 47 | 48 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lauxlib.h,v 1.70 2004/07/09 18:23:17 roberto Exp $ | |
| 2 | +** $Id: lauxlib.h,v 1.73 2004/10/18 12:51:44 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -70,6 +70,12 @@ LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t sz, · 64 unmodified lines | ||
| 70 | 70 | LUALIB_API lua_State *(luaL_newstate) (void); |
| 71 | 71 | |
| 72 | 72 | |
| 73 | +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, | |
| 74 | + const char *r); | |
| 75 | +LUALIB_API const char *luaL_getfield (lua_State *L, int idx, const char *fname); | |
| 76 | +LUALIB_API const char *luaL_setfield (lua_State *L, int idx, const char *fname); | |
| 77 | + | |
| 78 | + | |
| 73 | 79 | |
| 74 | 80 | /* |
| 75 | 81 | ** =============================================================== |
| @@ -78,15 +84,15 @@ LUALIB_API lua_State *(luaL_newstate) (void); · 2 unmodified lines | ||
| 78 | 84 | */ |
| 79 | 85 | |
| 80 | 86 | #define luaL_argcheck(L, cond,numarg,extramsg) \ |
| 81 | − ((void)((cond) || luaL_argerror(L, numarg,extramsg))) | |
| 87 | + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) | |
| 82 | 88 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
| 83 | 89 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) |
| 84 | −#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, n)) | |
| 85 | −#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, n,d)) | |
| 86 | −#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, n)) | |
| 87 | −#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, n,d)) | |
| 90 | +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) | |
| 91 | +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | |
| 92 | +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) | |
| 93 | +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) | |
| 88 | 94 | |
| 89 | −#define luaL_typename(L,i) lua_typename(L,lua_type(L,(i))) | |
| 95 | +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) | |
| 90 | 96 | |
| 91 | 97 | /* |
| 92 | 98 | ** {====================================================== |
| @@ -131,7 +137,7 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B); · 38 unmodified lines | ||
| 131 | 137 | |
| 132 | 138 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) |
| 133 | 139 | |
| 134 | −#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, ref) | |
| 140 | +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) | |
| 135 | 141 | |
| 136 | 142 | |
| 137 | 143 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.h,v 1.193 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: lua.h,v 1.196 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Lua - An Extensible Extension Language |
| 4 | 4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil |
| 5 | 5 | ** http://www.lua.org mailto:info@lua.org |
| @@ -17,7 +17,7 @@ · 11 unmodified lines | ||
| 17 | 17 | #include "luaconf.h" |
| 18 | 18 | |
| 19 | 19 | |
| 20 | −#define LUA_VERSION "Lua 5.1 (work2)" | |
| 20 | +#define LUA_VERSION "Lua 5.1 (work3)" | |
| 21 | 21 | #define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio" |
| 22 | 22 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" |
| 23 | 23 | |
| @@ -81,6 +81,10 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); · 57 unmodified lines | ||
| 81 | 81 | #define LUA_TTHREAD 8 |
| 82 | 82 | |
| 83 | 83 | |
| 84 | +/* first index for arrays */ | |
| 85 | +#define LUA_FIRSTINDEX 1 | |
| 86 | + | |
| 87 | + | |
| 84 | 88 | /* minimum Lua stack available to a C function */ |
| 85 | 89 | #define LUA_MINSTACK 20 |
| 86 | 90 | |
| @@ -216,11 +220,13 @@ LUA_API int lua_threadstatus (lua_State *L); · 129 unmodified lines | ||
| 216 | 220 | ** garbage-collection function and options |
| 217 | 221 | */ |
| 218 | 222 | |
| 219 | −#define LUA_GCSTOP 0 | |
| 220 | −#define LUA_GCRESTART 1 | |
| 221 | −#define LUA_GCCOLLECT 2 | |
| 222 | −#define LUA_GCCOUNT 3 | |
| 223 | −#define LUA_GCSTEP 4 | |
| 223 | +#define LUA_GCSTOP 0 | |
| 224 | +#define LUA_GCRESTART 1 | |
| 225 | +#define LUA_GCCOLLECT 2 | |
| 226 | +#define LUA_GCCOUNT 3 | |
| 227 | +#define LUA_GCSTEP 4 | |
| 228 | +#define LUA_GCSETSTEPMUL 5 | |
| 229 | +#define LUA_GCSETINCMODE 6 | |
| 224 | 230 | |
| 225 | 231 | LUA_API int lua_gc (lua_State *L, int what, int data); |
| 226 | 232 | |
| @@ -251,26 +257,26 @@ LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud); · 24 unmodified lines | ||
| 251 | 257 | |
| 252 | 258 | #define lua_newtable(L) lua_createtable(L, 0, 0) |
| 253 | 259 | |
| 254 | −#define lua_register(L,n,f) (lua_pushcfunction(L,f), lua_setglobal(L,n)) | |
| 260 | +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) | |
| 255 | 261 | |
| 256 | −#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) | |
| 262 | +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) | |
| 257 | 263 | |
| 258 | −#define lua_strlen(L,i) lua_objsize(L,i) | |
| 264 | +#define lua_strlen(L,i) lua_objsize(L, (i)) | |
| 259 | 265 | |
| 260 | −#define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION) | |
| 261 | −#define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) | |
| 262 | −#define lua_islightuserdata(L,n) (lua_type(L,n) == LUA_TLIGHTUSERDATA) | |
| 263 | −#define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) | |
| 264 | −#define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN) | |
| 265 | −#define lua_isthread(L,n) (lua_type(L,n) == LUA_TTHREAD) | |
| 266 | −#define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE) | |
| 267 | −#define lua_isnoneornil(L, n) (lua_type(L,n) <= 0) | |
| 266 | +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) | |
| 267 | +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) | |
| 268 | +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) | |
| 269 | +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) | |
| 270 | +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) | |
| 271 | +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) | |
| 272 | +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) | |
| 273 | +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) | |
| 268 | 274 | |
| 269 | 275 | #define lua_pushliteral(L, s) \ |
| 270 | 276 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) |
| 271 | 277 | |
| 272 | −#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, s) | |
| 273 | −#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, s) | |
| 278 | +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) | |
| 279 | +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) | |
| 274 | 280 | |
| 275 | 281 | |
| 276 | 282 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: luaconf.h,v 1.12 2004/09/10 17:30:46 roberto Exp $ | |
| 2 | +** $Id: luaconf.h,v 1.20 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Configuration file for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -31,7 +31,11 @@ · 25 unmodified lines | ||
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | 33 | /* default path */ |
| 34 | −#define LUA_PATH_DEFAULT "?;?.lua" | |
| 34 | +#define LUA_PATH_DEFAULT \ | |
| 35 | + "./?.lua;/usr/local/share/lua/5.0/?.lua;/usr/local/share/lua/5.0/?/init.lua" | |
| 36 | +#define LUA_CPATH_DEFAULT \ | |
| 37 | + "./?.so;/usr/local/lib/lua/5.0/?.so;/usr/local/lib/lua/5.0/lib?.so" | |
| 38 | + | |
| 35 | 39 | |
| 36 | 40 | |
| 37 | 41 | /* type of numbers in Lua */ |
| @@ -42,8 +46,11 @@ · 4 unmodified lines | ||
| 42 | 46 | #define LUA_NUMBER_FMT "%.14g" |
| 43 | 47 | |
| 44 | 48 | |
| 45 | −/* type for integer functions */ | |
| 46 | −#define LUA_INTEGER long | |
| 49 | +/* | |
| 50 | +** type for integer functions | |
| 51 | +** on most machines, `ptrdiff_t' gives a reasonable size for integers | |
| 52 | +*/ | |
| 53 | +#define LUA_INTEGER ptrdiff_t | |
| 47 | 54 | |
| 48 | 55 | |
| 49 | 56 | /* mark for all API functions */ |
| @@ -56,9 +63,6 @@ · 6 unmodified lines | ||
| 56 | 63 | #define LUAL_BUFFERSIZE BUFSIZ |
| 57 | 64 | |
| 58 | 65 | |
| 59 | −/* first index for arrays */ | |
| 60 | −#define LUA_FIRSTINDEX 1 | |
| 61 | − | |
| 62 | 66 | /* assertions in Lua (mainly for internal debugging) */ |
| 63 | 67 | #define lua_assert(c) ((void)0) |
| 64 | 68 | |
| @@ -123,19 +127,45 @@ · 58 unmodified lines | ||
| 123 | 127 | #ifdef LUA_CORE |
| 124 | 128 | |
| 125 | 129 | /* LUA-C API assertions */ |
| 126 | −#define api_check(L, o) lua_assert(o) | |
| 130 | +#define api_check(L,o) lua_assert(o) | |
| 127 | 131 | |
| 128 | 132 | |
| 129 | −/* an unsigned integer with at least 32 bits */ | |
| 130 | −#define LUA_UINT32 unsigned long | |
| 133 | +/* number of bits in an `int' */ | |
| 134 | +/* avoid overflows in comparison */ | |
| 135 | +#if INT_MAX-20 < 32760 | |
| 136 | +#define LUA_BITSINT 16 | |
| 137 | +#elif INT_MAX > 2147483640L | |
| 138 | +/* `int' has at least 32 bits */ | |
| 139 | +#define LUA_BITSINT 32 | |
| 140 | +#else | |
| 141 | +#error "you must define LUA_BITSINT with number of bits in an integer" | |
| 142 | +#endif | |
| 143 | + | |
| 131 | 144 | |
| 132 | −/* a signed integer with at least 32 bits */ | |
| 145 | +/* | |
| 146 | +** L_UINT32: unsigned integer with at least 32 bits | |
| 147 | +** L_INT32: signed integer with at least 32 bits | |
| 148 | +** LU_MEM: an unsigned integer big enough to count the total memory used by Lua | |
| 149 | +** L_MEM: a signed integer big enough to count the total memory used by Lua | |
| 150 | +*/ | |
| 151 | +#if LUA_BITSINT >= 32 | |
| 152 | +#define LUA_UINT32 unsigned int | |
| 153 | +#define LUA_INT32 int | |
| 154 | +#define LUA_MAXINT32 INT_MAX | |
| 155 | +#define LU_MEM size_t | |
| 156 | +#define L_MEM ptrdiff_t | |
| 157 | +#else | |
| 158 | +/* 16-bit ints */ | |
| 159 | +#define LUA_UINT32 unsigned long | |
| 133 | 160 | #define LUA_INT32 long |
| 134 | 161 | #define LUA_MAXINT32 LONG_MAX |
| 162 | +#define LU_MEM LUA_UINT32 | |
| 163 | +#define L_MEM ptrdiff_t | |
| 164 | +#endif | |
| 135 | 165 | |
| 136 | 166 | |
| 137 | 167 | /* maximum depth for calls (unsigned short) */ |
| 138 | −#define LUA_MAXCALLS 4096 | |
| 168 | +#define LUA_MAXCALLS 10000 | |
| 139 | 169 | |
| 140 | 170 | /* |
| 141 | 171 | ** maximum depth for C calls (unsigned short): Not too big, or may |
| @@ -160,7 +190,7 @@ · 18 unmodified lines | ||
| 160 | 190 | |
| 161 | 191 | |
| 162 | 192 | /* maximum number of upvalues per function */ |
| 163 | −#define MAXUPVALUES 32 /* <MAXSTACK */ | |
| 193 | +#define MAXUPVALUES 60 /* <MAXSTACK */ | |
| 164 | 194 | |
| 165 | 195 | |
| 166 | 196 | /* maximum size of expressions for optimizing `while' code */ |
| @@ -170,7 +200,7 @@ · 3 unmodified lines | ||
| 170 | 200 | /* function to convert a lua_Number to int (with any rounding method) */ |
| 171 | 201 | #if defined(__GNUC__) && defined(__i386) |
| 172 | 202 | #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st") |
| 173 | −#elif 0 | |
| 203 | +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L) | |
| 174 | 204 | /* on machines compliant with C99, you can try `lrint' */ |
| 175 | 205 | #include <math.h> |
| 176 | 206 | #define lua_number2int(i,d) ((i)=lrint(d)) |
| @@ -179,7 +209,7 @@ · 2 unmodified lines | ||
| 179 | 209 | #endif |
| 180 | 210 | |
| 181 | 211 | /* function to convert a lua_Number to lua_Integer (with any rounding method) */ |
| 182 | −#define lua_number2integer(i,n) lua_number2int(i,n) | |
| 212 | +#define lua_number2integer(i,n) lua_number2int((i), (n)) | |
| 183 | 213 | |
| 184 | 214 | |
| 185 | 215 | /* function to convert a lua_Number to a string */ |
| @@ -195,17 +225,6 @@ · 9 unmodified lines | ||
| 195 | 225 | #define LUA_UACNUMBER double |
| 196 | 226 | |
| 197 | 227 | |
| 198 | −/* number of bits in an `int' */ | |
| 199 | −/* avoid overflows in comparison */ | |
| 200 | −#if INT_MAX-20 < 32760 | |
| 201 | −#define LUA_BITSINT 16 | |
| 202 | −#elif INT_MAX > 2147483640L | |
| 203 | −/* machine has at least 32 bits */ | |
| 204 | −#define LUA_BITSINT 32 | |
| 205 | −#else | |
| 206 | −#error "you must define LUA_BITSINT with number of bits in an integer" | |
| 207 | −#endif | |
| 208 | − | |
| 209 | 228 | |
| 210 | 229 | /* type to ensure maximum alignment */ |
| 211 | 230 | #define LUSER_ALIGNMENT_T union { double u; void *s; long l; } |
| @@ -215,14 +234,14 @@ · 3 unmodified lines | ||
| 215 | 234 | #ifndef __cplusplus |
| 216 | 235 | /* default handling with long jumps */ |
| 217 | 236 | #include <setjmp.h> |
| 218 | −#define L_THROW(c) longjmp((c)->b, 1) | |
| 219 | −#define L_TRY(c,a) if (setjmp((c)->b) == 0) { a } | |
| 237 | +#define L_THROW(L,c) longjmp((c)->b, 1) | |
| 238 | +#define L_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } | |
| 220 | 239 | #define l_jmpbuf jmp_buf |
| 221 | 240 | |
| 222 | 241 | #else |
| 223 | 242 | /* C++ exceptions */ |
| 224 | −#define L_THROW(c) throw(c) | |
| 225 | −#define L_TRY(c,a) try { a } catch(...) \ | |
| 243 | +#define L_THROW(L,c) throw(c) | |
| 244 | +#define L_TRY(L,c,a) try { a } catch(...) \ | |
| 226 | 245 | { if ((c)->status == 0) (c)->status = -1; } |
| 227 | 246 | #define l_jmpbuf int /* dummy variable */ |
| 228 | 247 | #endif |
| @@ -251,9 +270,12 @@ · 22 unmodified lines | ||
| 251 | 270 | |
| 252 | 271 | |
| 253 | 272 | /* allows user-specific initialization on new threads */ |
| 254 | −#define lua_userstateopen(l) /* empty */ | |
| 273 | +#define lua_userstateopen(L) /* empty */ | |
| 255 | 274 | |
| 256 | 275 | |
| 276 | +/* initial GC parameters */ | |
| 277 | +#define STEPMUL 4 | |
| 278 | + | |
| 257 | 279 | #endif |
| 258 | 280 | |
| 259 | 281 | /* }====================================================== */ |
| @@ -272,8 +294,19 @@ · 12 unmodified lines | ||
| 272 | 294 | |
| 273 | 295 | /* `assert' options */ |
| 274 | 296 | |
| 275 | −/* environment variable that holds the search path for packages */ | |
| 297 | +/* environment variables that hold the search path for packages */ | |
| 276 | 298 | #define LUA_PATH "LUA_PATH" |
| 299 | +#define LUA_CPATH "LUA_CPATH" | |
| 300 | + | |
| 301 | +/* prefix for open functions in C libraries */ | |
| 302 | +#if defined(__APPLE__) && defined(__MACH__) | |
| 303 | +#define LUA_POF "_luaopen_" | |
| 304 | +#else | |
| 305 | +#define LUA_POF "luaopen_" | |
| 306 | +#endif | |
| 307 | + | |
| 308 | +/* directory separator (for submodules) */ | |
| 309 | +#define LUA_DIRSEP "/" | |
| 277 | 310 | |
| 278 | 311 | /* separator of templates in a path */ |
| 279 | 312 | #define LUA_PATH_SEP ';' |
| @@ -288,7 +321,7 @@ · 8 unmodified lines | ||
| 288 | 321 | |
| 289 | 322 | /* |
| 290 | 323 | ** by default, gcc does not get `tmpname' |
| 291 | −*/ | |
| 324 | +*/ | |
| 292 | 325 | #ifdef __GNUC__ |
| 293 | 326 | #define USE_TMPNAME 0 |
| 294 | 327 | #else |
| @@ -296,6 +329,17 @@ · 1 unmodified line | ||
| 296 | 329 | #endif |
| 297 | 330 | |
| 298 | 331 | |
| 332 | +/* | |
| 333 | +** Configuration for loadlib | |
| 334 | +*/ | |
| 335 | +#if defined(__linux) || defined(sun) || defined(sgi) || defined(BSD) | |
| 336 | +#define USE_DLOPEN | |
| 337 | +#elif defined(_WIN32) | |
| 338 | +#define USE_DLL | |
| 339 | +#elif defined(__APPLE__) && defined(__MACH__) | |
| 340 | +#define USE_DYLD | |
| 341 | +#endif | |
| 342 | + | |
| 299 | 343 | |
| 300 | 344 | #endif |
| 301 | 345 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lapi.c,v 2.19 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: lapi.c,v 2.22 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Lua API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -45,7 +45,7 @@ const char lua_ident[] = · 39 unmodified lines | ||
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | |
| 48 | −static TValue *luaA_index (lua_State *L, int idx) { | |
| 48 | +static TValue *index2adr (lua_State *L, int idx) { | |
| 49 | 49 | if (idx > 0) { |
| 50 | 50 | TValue *o = L->base + (idx - 1); |
| 51 | 51 | api_check(L, idx <= L->ci->top - L->base); |
| @@ -160,7 +160,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { · 108 unmodified lines | ||
| 160 | 160 | LUA_API void lua_remove (lua_State *L, int idx) { |
| 161 | 161 | StkId p; |
| 162 | 162 | lua_lock(L); |
| 163 | − p = luaA_index(L, idx); | |
| 163 | + p = index2adr(L, idx); | |
| 164 | 164 | api_checkvalidindex(L, p); |
| 165 | 165 | while (++p < L->top) setobjs2s(L, p-1, p); |
| 166 | 166 | L->top--; |
| @@ -172,7 +172,7 @@ LUA_API void lua_insert (lua_State *L, int idx) { · 5 unmodified lines | ||
| 172 | 172 | StkId p; |
| 173 | 173 | StkId q; |
| 174 | 174 | lua_lock(L); |
| 175 | − p = luaA_index(L, idx); | |
| 175 | + p = index2adr(L, idx); | |
| 176 | 176 | api_checkvalidindex(L, p); |
| 177 | 177 | for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); |
| 178 | 178 | setobjs2s(L, p, L->top); |
| @@ -184,7 +184,7 @@ LUA_API void lua_replace (lua_State *L, int idx) { · 5 unmodified lines | ||
| 184 | 184 | StkId o; |
| 185 | 185 | lua_lock(L); |
| 186 | 186 | api_checknelems(L, 1); |
| 187 | − o = luaA_index(L, idx); | |
| 187 | + o = index2adr(L, idx); | |
| 188 | 188 | api_checkvalidindex(L, o); |
| 189 | 189 | setobj(L, o, L->top - 1); |
| 190 | 190 | if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ |
| @@ -196,7 +196,7 @@ LUA_API void lua_replace (lua_State *L, int idx) { · 5 unmodified lines | ||
| 196 | 196 | |
| 197 | 197 | LUA_API void lua_pushvalue (lua_State *L, int idx) { |
| 198 | 198 | lua_lock(L); |
| 199 | − setobj2s(L, L->top, luaA_index(L, idx)); | |
| 199 | + setobj2s(L, L->top, index2adr(L, idx)); | |
| 200 | 200 | api_incr_top(L); |
| 201 | 201 | lua_unlock(L); |
| 202 | 202 | } |
| @@ -209,7 +209,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 6 unmodified lines | ||
| 209 | 209 | |
| 210 | 210 | |
| 211 | 211 | LUA_API int lua_type (lua_State *L, int idx) { |
| 212 | − StkId o = luaA_index(L, idx); | |
| 212 | + StkId o = index2adr(L, idx); | |
| 213 | 213 | return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o); |
| 214 | 214 | } |
| 215 | 215 | |
| @@ -221,14 +221,14 @@ LUA_API const char *lua_typename (lua_State *L, int t) { · 5 unmodified lines | ||
| 221 | 221 | |
| 222 | 222 | |
| 223 | 223 | LUA_API int lua_iscfunction (lua_State *L, int idx) { |
| 224 | − StkId o = luaA_index(L, idx); | |
| 224 | + StkId o = index2adr(L, idx); | |
| 225 | 225 | return iscfunction(o); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | LUA_API int lua_isnumber (lua_State *L, int idx) { |
| 230 | 230 | TValue n; |
| 231 | − const TValue *o = luaA_index(L, idx); | |
| 231 | + const TValue *o = index2adr(L, idx); | |
| 232 | 232 | return tonumber(o, &n); |
| 233 | 233 | } |
| 234 | 234 | |
| @@ -240,14 +240,14 @@ LUA_API int lua_isstring (lua_State *L, int idx) { · 5 unmodified lines | ||
| 240 | 240 | |
| 241 | 241 | |
| 242 | 242 | LUA_API int lua_isuserdata (lua_State *L, int idx) { |
| 243 | − const TValue *o = luaA_index(L, idx); | |
| 243 | + const TValue *o = index2adr(L, idx); | |
| 244 | 244 | return (ttisuserdata(o) || ttislightuserdata(o)); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { |
| 249 | − StkId o1 = luaA_index(L, index1); | |
| 250 | − StkId o2 = luaA_index(L, index2); | |
| 249 | + StkId o1 = index2adr(L, index1); | |
| 250 | + StkId o2 = index2adr(L, index2); | |
| 251 | 251 | return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0 |
| 252 | 252 | : luaO_rawequalObj(o1, o2); |
| 253 | 253 | } |
| @@ -257,8 +257,8 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { · 3 unmodified lines | ||
| 257 | 257 | StkId o1, o2; |
| 258 | 258 | int i; |
| 259 | 259 | lua_lock(L); /* may call tag method */ |
| 260 | − o1 = luaA_index(L, index1); | |
| 261 | − o2 = luaA_index(L, index2); | |
| 260 | + o1 = index2adr(L, index1); | |
| 261 | + o2 = index2adr(L, index2); | |
| 262 | 262 | i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0 |
| 263 | 263 | : equalobj(L, o1, o2); |
| 264 | 264 | lua_unlock(L); |
| @@ -270,8 +270,8 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 5 unmodified lines | ||
| 270 | 270 | StkId o1, o2; |
| 271 | 271 | int i; |
| 272 | 272 | lua_lock(L); /* may call tag method */ |
| 273 | − o1 = luaA_index(L, index1); | |
| 274 | − o2 = luaA_index(L, index2); | |
| 273 | + o1 = index2adr(L, index1); | |
| 274 | + o2 = index2adr(L, index2); | |
| 275 | 275 | i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0 |
| 276 | 276 | : luaV_lessthan(L, o1, o2); |
| 277 | 277 | lua_unlock(L); |
| @@ -282,7 +282,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 4 unmodified lines | ||
| 282 | 282 | |
| 283 | 283 | LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { |
| 284 | 284 | TValue n; |
| 285 | − const TValue *o = luaA_index(L, idx); | |
| 285 | + const TValue *o = index2adr(L, idx); | |
| 286 | 286 | if (tonumber(o, &n)) |
| 287 | 287 | return nvalue(o); |
| 288 | 288 | else |
| @@ -292,7 +292,7 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { · 3 unmodified lines | ||
| 292 | 292 | |
| 293 | 293 | LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { |
| 294 | 294 | TValue n; |
| 295 | − const TValue *o = luaA_index(L, idx); | |
| 295 | + const TValue *o = index2adr(L, idx); | |
| 296 | 296 | if (tonumber(o, &n)) { |
| 297 | 297 | lua_Integer res; |
| 298 | 298 | lua_number2integer(res, nvalue(o)); |
| @@ -304,13 +304,13 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { · 5 unmodified lines | ||
| 304 | 304 | |
| 305 | 305 | |
| 306 | 306 | LUA_API int lua_toboolean (lua_State *L, int idx) { |
| 307 | − const TValue *o = luaA_index(L, idx); | |
| 307 | + const TValue *o = index2adr(L, idx); | |
| 308 | 308 | return !l_isfalse(o); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
| 312 | 312 | LUA_API const char *lua_tostring (lua_State *L, int idx) { |
| 313 | − StkId o = luaA_index(L, idx); | |
| 313 | + StkId o = index2adr(L, idx); | |
| 314 | 314 | if (ttisstring(o)) |
| 315 | 315 | return svalue(o); |
| 316 | 316 | else { |
| @@ -325,7 +325,7 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) { · 8 unmodified lines | ||
| 325 | 325 | |
| 326 | 326 | |
| 327 | 327 | LUA_API size_t lua_objsize (lua_State *L, int idx) { |
| 328 | − StkId o = luaA_index(L, idx); | |
| 328 | + StkId o = index2adr(L, idx); | |
| 329 | 329 | if (ttisstring(o)) |
| 330 | 330 | return tsvalue(o)->len; |
| 331 | 331 | else if (ttisuserdata(o)) |
| @@ -341,13 +341,13 @@ LUA_API size_t lua_objsize (lua_State *L, int idx) { · 9 unmodified lines | ||
| 341 | 341 | |
| 342 | 342 | |
| 343 | 343 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { |
| 344 | − StkId o = luaA_index(L, idx); | |
| 344 | + StkId o = index2adr(L, idx); | |
| 345 | 345 | return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | |
| 349 | 349 | LUA_API void *lua_touserdata (lua_State *L, int idx) { |
| 350 | − StkId o = luaA_index(L, idx); | |
| 350 | + StkId o = index2adr(L, idx); | |
| 351 | 351 | switch (ttype(o)) { |
| 352 | 352 | case LUA_TUSERDATA: return (rawuvalue(o) + 1); |
| 353 | 353 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
| @@ -357,13 +357,13 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { · 3 unmodified lines | ||
| 357 | 357 | |
| 358 | 358 | |
| 359 | 359 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { |
| 360 | − StkId o = luaA_index(L, idx); | |
| 360 | + StkId o = index2adr(L, idx); | |
| 361 | 361 | return (!ttisthread(o)) ? NULL : thvalue(o); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
| 365 | 365 | LUA_API const void *lua_topointer (lua_State *L, int idx) { |
| 366 | − StkId o = luaA_index(L, idx); | |
| 366 | + StkId o = index2adr(L, idx); | |
| 367 | 367 | switch (ttype(o)) { |
| 368 | 368 | case LUA_TTABLE: return hvalue(o); |
| 369 | 369 | case LUA_TFUNCTION: return clvalue(o); |
| @@ -498,7 +498,7 @@ LUA_API int lua_pushthread (lua_State *L) { · 128 unmodified lines | ||
| 498 | 498 | LUA_API void lua_gettable (lua_State *L, int idx) { |
| 499 | 499 | StkId t; |
| 500 | 500 | lua_lock(L); |
| 501 | − t = luaA_index(L, idx); | |
| 501 | + t = index2adr(L, idx); | |
| 502 | 502 | api_checkvalidindex(L, t); |
| 503 | 503 | luaV_gettable(L, t, L->top - 1, L->top - 1, NULL); |
| 504 | 504 | lua_unlock(L); |
| @@ -509,7 +509,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { · 4 unmodified lines | ||
| 509 | 509 | StkId t; |
| 510 | 510 | TValue key; |
| 511 | 511 | lua_lock(L); |
| 512 | − t = luaA_index(L, idx); | |
| 512 | + t = index2adr(L, idx); | |
| 513 | 513 | api_checkvalidindex(L, t); |
| 514 | 514 | setsvalue(L, &key, luaS_new(L, k)); |
| 515 | 515 | luaV_gettable(L, t, &key, L->top, NULL); |
| @@ -521,7 +521,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { · 5 unmodified lines | ||
| 521 | 521 | LUA_API void lua_rawget (lua_State *L, int idx) { |
| 522 | 522 | StkId t; |
| 523 | 523 | lua_lock(L); |
| 524 | − t = luaA_index(L, idx); | |
| 524 | + t = index2adr(L, idx); | |
| 525 | 525 | api_check(L, ttistable(t)); |
| 526 | 526 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
| 527 | 527 | lua_unlock(L); |
| @@ -531,7 +531,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) { · 3 unmodified lines | ||
| 531 | 531 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { |
| 532 | 532 | StkId o; |
| 533 | 533 | lua_lock(L); |
| 534 | − o = luaA_index(L, idx); | |
| 534 | + o = index2adr(L, idx); | |
| 535 | 535 | api_check(L, ttistable(o)); |
| 536 | 536 | setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); |
| 537 | 537 | api_incr_top(L); |
| @@ -553,7 +553,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { · 15 unmodified lines | ||
| 553 | 553 | Table *mt = NULL; |
| 554 | 554 | int res; |
| 555 | 555 | lua_lock(L); |
| 556 | − obj = luaA_index(L, objindex); | |
| 556 | + obj = index2adr(L, objindex); | |
| 557 | 557 | switch (ttype(obj)) { |
| 558 | 558 | case LUA_TTABLE: |
| 559 | 559 | mt = hvalue(obj)->metatable; |
| @@ -577,7 +577,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { · 17 unmodified lines | ||
| 577 | 577 | LUA_API void lua_getfenv (lua_State *L, int idx) { |
| 578 | 578 | StkId o; |
| 579 | 579 | lua_lock(L); |
| 580 | − o = luaA_index(L, idx); | |
| 580 | + o = index2adr(L, idx); | |
| 581 | 581 | api_checkvalidindex(L, o); |
| 582 | 582 | setobj2s(L, L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L)); |
| 583 | 583 | api_incr_top(L); |
| @@ -594,7 +594,7 @@ LUA_API void lua_settable (lua_State *L, int idx) { · 10 unmodified lines | ||
| 594 | 594 | StkId t; |
| 595 | 595 | lua_lock(L); |
| 596 | 596 | api_checknelems(L, 2); |
| 597 | − t = luaA_index(L, idx); | |
| 597 | + t = index2adr(L, idx); | |
| 598 | 598 | api_checkvalidindex(L, t); |
| 599 | 599 | luaV_settable(L, t, L->top - 2, L->top - 1, NULL); |
| 600 | 600 | L->top -= 2; /* pop index and value */ |
| @@ -607,7 +607,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { · 6 unmodified lines | ||
| 607 | 607 | TValue key; |
| 608 | 608 | lua_lock(L); |
| 609 | 609 | api_checknelems(L, 1); |
| 610 | − t = luaA_index(L, idx); | |
| 610 | + t = index2adr(L, idx); | |
| 611 | 611 | api_checkvalidindex(L, t); |
| 612 | 612 | setsvalue(L, &key, luaS_new(L, k)); |
| 613 | 613 | luaV_settable(L, t, &key, L->top - 1, NULL); |
| @@ -620,7 +620,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { · 6 unmodified lines | ||
| 620 | 620 | StkId t; |
| 621 | 621 | lua_lock(L); |
| 622 | 622 | api_checknelems(L, 2); |
| 623 | − t = luaA_index(L, idx); | |
| 623 | + t = index2adr(L, idx); | |
| 624 | 624 | api_check(L, ttistable(t)); |
| 625 | 625 | setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); |
| 626 | 626 | luaC_barriert(L, hvalue(t), L->top-1); |
| @@ -633,7 +633,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { · 6 unmodified lines | ||
| 633 | 633 | StkId o; |
| 634 | 634 | lua_lock(L); |
| 635 | 635 | api_checknelems(L, 1); |
| 636 | − o = luaA_index(L, idx); | |
| 636 | + o = index2adr(L, idx); | |
| 637 | 637 | api_check(L, ttistable(o)); |
| 638 | 638 | setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); |
| 639 | 639 | luaC_barriert(L, hvalue(o), L->top-1); |
| @@ -648,7 +648,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { · 8 unmodified lines | ||
| 648 | 648 | int res = 1; |
| 649 | 649 | lua_lock(L); |
| 650 | 650 | api_checknelems(L, 1); |
| 651 | − obj = luaA_index(L, objindex); | |
| 651 | + obj = index2adr(L, objindex); | |
| 652 | 652 | api_checkvalidindex(L, obj); |
| 653 | 653 | if (ttisnil(L->top - 1)) |
| 654 | 654 | mt = NULL; |
| @@ -685,7 +685,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { · 30 unmodified lines | ||
| 685 | 685 | int res = 0; |
| 686 | 686 | lua_lock(L); |
| 687 | 687 | api_checknelems(L, 1); |
| 688 | − o = luaA_index(L, idx); | |
| 688 | + o = index2adr(L, idx); | |
| 689 | 689 | api_checkvalidindex(L, o); |
| 690 | 690 | api_check(L, ttistable(L->top - 1)); |
| 691 | 691 | if (isLfunction(o)) { |
| @@ -751,7 +751,7 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { · 59 unmodified lines | ||
| 751 | 751 | if (errfunc == 0) |
| 752 | 752 | func = 0; |
| 753 | 753 | else { |
| 754 | − StkId o = luaA_index(L, errfunc); | |
| 754 | + StkId o = index2adr(L, errfunc); | |
| 755 | 755 | api_checkvalidindex(L, o); |
| 756 | 756 | func = savestack(L, o); |
| 757 | 757 | } |
| @@ -842,7 +842,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 84 unmodified lines | ||
| 842 | 842 | g = G(L); |
| 843 | 843 | switch (what) { |
| 844 | 844 | case LUA_GCSTOP: { |
| 845 | − g->GCthreshold = MAXLMEM; | |
| 845 | + g->GCthreshold = MAX_LUMEM; | |
| 846 | 846 | break; |
| 847 | 847 | } |
| 848 | 848 | case LUA_GCRESTART: { |
| @@ -867,6 +867,16 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 18 unmodified lines | ||
| 867 | 867 | luaC_step(L); |
| 868 | 868 | break; |
| 869 | 869 | } |
| 870 | + case LUA_GCSETSTEPMUL: { | |
| 871 | + res = g->stepmul; | |
| 872 | + g->stepmul = data; | |
| 873 | + break; | |
| 874 | + } | |
| 875 | + case LUA_GCSETINCMODE: { | |
| 876 | + res = g->incgc; | |
| 877 | + g->incgc = data; | |
| 878 | + break; | |
| 879 | + } | |
| 870 | 880 | default: res = -1; /* invalid option */ |
| 871 | 881 | } |
| 872 | 882 | lua_unlock(L); |
| @@ -898,7 +908,7 @@ LUA_API int lua_next (lua_State *L, int idx) { · 25 unmodified lines | ||
| 898 | 908 | StkId t; |
| 899 | 909 | int more; |
| 900 | 910 | lua_lock(L); |
| 901 | − t = luaA_index(L, idx); | |
| 911 | + t = index2adr(L, idx); | |
| 902 | 912 | api_check(L, ttistable(t)); |
| 903 | 913 | more = luaH_next(L, hvalue(t), L->top - 1); |
| 904 | 914 | if (more) { |
| @@ -970,7 +980,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { · 65 unmodified lines | ||
| 970 | 980 | const char *name; |
| 971 | 981 | TValue *val; |
| 972 | 982 | lua_lock(L); |
| 973 | − name = aux_upvalue(L, luaA_index(L, funcindex), n, &val); | |
| 983 | + name = aux_upvalue(L, index2adr(L, funcindex), n, &val); | |
| 974 | 984 | if (name) { |
| 975 | 985 | setobj2s(L, L->top, val); |
| 976 | 986 | api_incr_top(L); |
| @@ -985,7 +995,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { · 8 unmodified lines | ||
| 985 | 995 | TValue *val; |
| 986 | 996 | StkId fi; |
| 987 | 997 | lua_lock(L); |
| 988 | − fi = luaA_index(L, funcindex); | |
| 998 | + fi = index2adr(L, funcindex); | |
| 989 | 999 | api_checknelems(L, 1); |
| 990 | 1000 | name = aux_upvalue(L, fi, n, &val); |
| 991 | 1001 | if (name) { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.6 2004/08/24 20:09:11 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.8 2004/12/03 20:35:33 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -53,13 +53,13 @@ int luaK_jump (FuncState *fs) { · 47 unmodified lines | ||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | −static int luaK_condjump (FuncState *fs, OpCode op, int A, int B, int C) { | |
| 56 | +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { | |
| 57 | 57 | luaK_codeABC(fs, op, A, B, C); |
| 58 | 58 | return luaK_jump(fs); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
| 62 | −static void luaK_fixjump (FuncState *fs, int pc, int dest) { | |
| 62 | +static void fixjump (FuncState *fs, int pc, int dest) { | |
| 63 | 63 | Instruction *jmp = &fs->f->code[pc]; |
| 64 | 64 | int offset = dest-(pc+1); |
| 65 | 65 | lua_assert(dest != NO_JUMP); |
| @@ -79,7 +79,7 @@ int luaK_getlabel (FuncState *fs) { · 13 unmodified lines | ||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
| 82 | −static int luaK_getjump (FuncState *fs, int pc) { | |
| 82 | +static int getjump (FuncState *fs, int pc) { | |
| 83 | 83 | int offset = GETARG_sBx(fs->f->code[pc]); |
| 84 | 84 | if (offset == NO_JUMP) /* point to itself represents end of list */ |
| 85 | 85 | return NO_JUMP; /* end of list */ |
| @@ -102,7 +102,7 @@ static Instruction *getjumpcontrol (FuncState *fs, int pc) { · 16 unmodified lines | ||
| 102 | 102 | ** (or produce an inverted value) |
| 103 | 103 | */ |
| 104 | 104 | static int need_value (FuncState *fs, int list, int cond) { |
| 105 | − for (; list != NO_JUMP; list = luaK_getjump(fs, list)) { | |
| 105 | + for (; list != NO_JUMP; list = getjump(fs, list)) { | |
| 106 | 106 | Instruction i = *getjumpcontrol(fs, list); |
| 107 | 107 | if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1; |
| 108 | 108 | } |
| @@ -116,25 +116,25 @@ static void patchtestreg (Instruction *i, int reg) { · 7 unmodified lines | ||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
| 119 | −static void luaK_patchlistaux (FuncState *fs, int list, | |
| 119 | +static void patchlistaux (FuncState *fs, int list, | |
| 120 | 120 | int ttarget, int treg, int ftarget, int freg, int dtarget) { |
| 121 | 121 | while (list != NO_JUMP) { |
| 122 | − int next = luaK_getjump(fs, list); | |
| 122 | + int next = getjump(fs, list); | |
| 123 | 123 | Instruction *i = getjumpcontrol(fs, list); |
| 124 | 124 | if (GET_OPCODE(*i) != OP_TEST) { |
| 125 | 125 | lua_assert(dtarget != NO_JUMP); |
| 126 | − luaK_fixjump(fs, list, dtarget); /* jump to default target */ | |
| 126 | + fixjump(fs, list, dtarget); /* jump to default target */ | |
| 127 | 127 | } |
| 128 | 128 | else { |
| 129 | 129 | if (GETARG_C(*i)) { |
| 130 | 130 | lua_assert(ttarget != NO_JUMP); |
| 131 | 131 | patchtestreg(i, treg); |
| 132 | − luaK_fixjump(fs, list, ttarget); | |
| 132 | + fixjump(fs, list, ttarget); | |
| 133 | 133 | } |
| 134 | 134 | else { |
| 135 | 135 | lua_assert(ftarget != NO_JUMP); |
| 136 | 136 | patchtestreg(i, freg); |
| 137 | − luaK_fixjump(fs, list, ftarget); | |
| 137 | + fixjump(fs, list, ftarget); | |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | list = next; |
| @@ -142,8 +142,8 @@ static void luaK_patchlistaux (FuncState *fs, int list, · 1 unmodified line | ||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
| 145 | −static void luaK_dischargejpc (FuncState *fs) { | |
| 146 | − luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc); | |
| 145 | +static void dischargejpc (FuncState *fs) { | |
| 146 | + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc); | |
| 147 | 147 | fs->jpc = NO_JUMP; |
| 148 | 148 | } |
| 149 | 149 | |
| @@ -153,7 +153,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) { · 3 unmodified lines | ||
| 153 | 153 | luaK_patchtohere(fs, list); |
| 154 | 154 | else { |
| 155 | 155 | lua_assert(target < fs->pc); |
| 156 | − luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); | |
| 156 | + patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); | |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| @@ -171,9 +171,9 @@ void luaK_concat (FuncState *fs, int *l1, int l2) { · 11 unmodified lines | ||
| 171 | 171 | else { |
| 172 | 172 | int list = *l1; |
| 173 | 173 | int next; |
| 174 | − while ((next = luaK_getjump(fs, list)) != NO_JUMP) /* find last element */ | |
| 174 | + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ | |
| 175 | 175 | list = next; |
| 176 | − luaK_fixjump(fs, list, l2); | |
| 176 | + fixjump(fs, list, l2); | |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| @@ -243,7 +243,14 @@ int luaK_numberK (FuncState *fs, lua_Number r) { · 63 unmodified lines | ||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
| 246 | −static int nil_constant (FuncState *fs) { | |
| 246 | +static int boolK (FuncState *fs, int b) { | |
| 247 | + TValue o; | |
| 248 | + setbvalue(&o, b); | |
| 249 | + return addk(fs, &o, &o); | |
| 250 | +} | |
| 251 | + | |
| 252 | + | |
| 253 | +static int nilK (FuncState *fs) { | |
| 247 | 254 | TValue k, v; |
| 248 | 255 | setnilvalue(&v); |
| 249 | 256 | /* cannot use nil as key; instead use table itself to represent nil */ |
| @@ -358,7 +365,7 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { · 108 unmodified lines | ||
| 358 | 365 | } |
| 359 | 366 | |
| 360 | 367 | |
| 361 | −static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { | |
| 368 | +static void exp2reg (FuncState *fs, expdesc *e, int reg) { | |
| 362 | 369 | discharge2reg(fs, e, reg); |
| 363 | 370 | if (e->k == VJMP) |
| 364 | 371 | luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */ |
| @@ -375,8 +382,8 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { · 10 unmodified lines | ||
| 375 | 382 | luaK_patchtohere(fs, fj); |
| 376 | 383 | } |
| 377 | 384 | final = luaK_getlabel(fs); |
| 378 | − luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); | |
| 379 | − luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t); | |
| 385 | + patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); | |
| 386 | + patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t); | |
| 380 | 387 | } |
| 381 | 388 | e->f = e->t = NO_JUMP; |
| 382 | 389 | e->info = reg; |
| @@ -388,7 +395,7 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { · 5 unmodified lines | ||
| 388 | 395 | luaK_dischargevars(fs, e); |
| 389 | 396 | freeexp(fs, e); |
| 390 | 397 | luaK_reserveregs(fs, 1); |
| 391 | − luaK_exp2reg(fs, e, fs->freereg - 1); | |
| 398 | + exp2reg(fs, e, fs->freereg - 1); | |
| 392 | 399 | } |
| 393 | 400 | |
| 394 | 401 | |
| @@ -397,7 +404,7 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) { · 2 unmodified lines | ||
| 397 | 404 | if (e->k == VNONRELOC) { |
| 398 | 405 | if (!hasjumps(e)) return e->info; /* exp is already in a register */ |
| 399 | 406 | if (e->info >= fs->nactvar) { /* reg. is not a local? */ |
| 400 | − luaK_exp2reg(fs, e, e->info); /* put value on it */ | |
| 407 | + exp2reg(fs, e, e->info); /* put value on it */ | |
| 401 | 408 | return e->info; |
| 402 | 409 | } |
| 403 | 410 | } |
| @@ -417,9 +424,11 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { · 13 unmodified lines | ||
| 417 | 424 | int luaK_exp2RK (FuncState *fs, expdesc *e) { |
| 418 | 425 | luaK_exp2val(fs, e); |
| 419 | 426 | switch (e->k) { |
| 427 | + case VTRUE: | |
| 428 | + case VFALSE: | |
| 420 | 429 | case VNIL: { |
| 421 | 430 | if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ |
| 422 | − e->info = nil_constant(fs); | |
| 431 | + e->info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE)); | |
| 423 | 432 | e->k = VK; |
| 424 | 433 | return RKASK(e->info); |
| 425 | 434 | } |
| @@ -441,7 +450,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { · 15 unmodified lines | ||
| 441 | 450 | switch (var->k) { |
| 442 | 451 | case VLOCAL: { |
| 443 | 452 | freeexp(fs, ex); |
| 444 | − luaK_exp2reg(fs, ex, var->info); | |
| 453 | + exp2reg(fs, ex, var->info); | |
| 445 | 454 | return; |
| 446 | 455 | } |
| 447 | 456 | case VUPVAL: { |
| @@ -493,13 +502,13 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) { · 45 unmodified lines | ||
| 493 | 502 | Instruction ie = getcode(fs, e); |
| 494 | 503 | if (GET_OPCODE(ie) == OP_NOT) { |
| 495 | 504 | fs->pc--; /* remove previous OP_NOT */ |
| 496 | − return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond); | |
| 505 | + return condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond); | |
| 497 | 506 | } |
| 498 | 507 | /* else go through */ |
| 499 | 508 | } |
| 500 | 509 | discharge2anyreg(fs, e); |
| 501 | 510 | freeexp(fs, e); |
| 502 | − return luaK_condjump(fs, OP_TEST, NO_REG, e->info, cond); | |
| 511 | + return condjump(fs, OP_TEST, NO_REG, e->info, cond); | |
| 503 | 512 | } |
| 504 | 513 | |
| 505 | 514 | |
| @@ -651,7 +660,7 @@ static void codebinop (FuncState *fs, expdesc *res, BinOpr op, · 145 unmodified lines | ||
| 651 | 660 | temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ |
| 652 | 661 | } |
| 653 | 662 | else if (op == OPR_NE) cond = 0; |
| 654 | − res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2); | |
| 663 | + res->info = condjump(fs, ops[op - OPR_NE], cond, o1, o2); | |
| 655 | 664 | res->k = VJMP; |
| 656 | 665 | } |
| 657 | 666 | } |
| @@ -708,7 +717,7 @@ void luaK_fixline (FuncState *fs, int line) { · 50 unmodified lines | ||
| 708 | 717 | |
| 709 | 718 | int luaK_code (FuncState *fs, Instruction i, int line) { |
| 710 | 719 | Proto *f = fs->f; |
| 711 | − luaK_dischargejpc(fs); /* `pc' will change */ | |
| 720 | + dischargejpc(fs); /* `pc' will change */ | |
| 712 | 721 | /* put new instruction in code array */ |
| 713 | 722 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
| 714 | 723 | MAX_INT, "code size overflow"); |
| @@ -735,3 +744,17 @@ int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { · 20 unmodified lines | ||
| 735 | 744 | return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); |
| 736 | 745 | } |
| 737 | 746 | |
| 747 | + | |
| 748 | +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { | |
| 749 | + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; | |
| 750 | + int b = (tostore == LUA_MULTRET) ? 0 : tostore; | |
| 751 | + lua_assert(tostore != 0); | |
| 752 | + if (c <= MAXARG_C) | |
| 753 | + luaK_codeABC(fs, OP_SETLIST, base, b, c); | |
| 754 | + else { | |
| 755 | + luaK_codeABC(fs, OP_SETLIST, base, b, 0); | |
| 756 | + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); | |
| 757 | + } | |
| 758 | + fs->freereg = base + 1; /* free registers with list values */ | |
| 759 | +} | |
| 760 | + | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.h,v 1.39 2004/05/31 18:51:50 roberto Exp $ | |
| 2 | +** $Id: lcode.h,v 1.40 2004/10/04 19:01:53 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -72,6 +72,7 @@ int luaK_getlabel (FuncState *fs); · 66 unmodified lines | ||
| 72 | 72 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); |
| 73 | 73 | void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); |
| 74 | 74 | void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); |
| 75 | +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); | |
| 75 | 76 | |
| 76 | 77 | |
| 77 | 78 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldebug.c,v 2.8 2004/09/01 13:47:31 roberto Exp $ | |
| 2 | +** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp $ | |
| 3 | 3 | ** Debug Interface |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -261,11 +261,11 @@ int luaG_checkopenop (Instruction i) { · 255 unmodified lines | ||
| 261 | 261 | switch (GET_OPCODE(i)) { |
| 262 | 262 | case OP_CALL: |
| 263 | 263 | case OP_TAILCALL: |
| 264 | − case OP_RETURN: { | |
| 264 | + case OP_RETURN: | |
| 265 | + case OP_SETLIST: { | |
| 265 | 266 | check(GETARG_B(i) == 0); |
| 266 | 267 | return 1; |
| 267 | 268 | } |
| 268 | − case OP_SETLISTO: return 1; | |
| 269 | 269 | default: return 0; /* invalid instruction after an open call */ |
| 270 | 270 | } |
| 271 | 271 | } |
| @@ -284,7 +284,7 @@ static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { · 12 unmodified lines | ||
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
| 287 | −static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { | |
| 287 | +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { | |
| 288 | 288 | int pc; |
| 289 | 289 | int last; /* stores position of last instruction that changed `reg' */ |
| 290 | 290 | last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ |
| @@ -315,6 +315,11 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 24 unmodified lines | ||
| 315 | 315 | if (getBMode(op) == OpArgR) { |
| 316 | 316 | int dest = pc+1+b; |
| 317 | 317 | check(0 <= dest && dest < pt->sizecode); |
| 318 | + if (dest > 0) { | |
| 319 | + /* cannot jump to a setlist count */ | |
| 320 | + const Instruction d = pt->code[dest-1]; | |
| 321 | + check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)); | |
| 322 | + } | |
| 318 | 323 | } |
| 319 | 324 | break; |
| 320 | 325 | } |
| @@ -356,7 +361,8 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 35 unmodified lines | ||
| 356 | 361 | break; |
| 357 | 362 | } |
| 358 | 363 | case OP_TFORLOOP: { |
| 359 | − checkreg(pt, a+5); /* space for control variables */ | |
| 364 | + check(c >= 1); /* at least one result (control variable) */ | |
| 365 | + checkreg(pt, a+3+c); /* space for results */ | |
| 360 | 366 | if (reg >= a+3) last = pc; /* affect all regs above its call base */ |
| 361 | 367 | break; |
| 362 | 368 | } |
| @@ -392,7 +398,8 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 29 unmodified lines | ||
| 392 | 398 | break; |
| 393 | 399 | } |
| 394 | 400 | case OP_SETLIST: { |
| 395 | − checkreg(pt, a + (b&(LFIELDS_PER_FLUSH-1)) + 1); | |
| 401 | + if (b > 0) checkreg(pt, a + b); | |
| 402 | + if (c == 0) pc++; | |
| 396 | 403 | break; |
| 397 | 404 | } |
| 398 | 405 | case OP_CLOSURE: { |
| @@ -427,7 +434,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 28 unmodified lines | ||
| 427 | 434 | |
| 428 | 435 | |
| 429 | 436 | int luaG_checkcode (const Proto *pt) { |
| 430 | − return (luaG_symbexec(pt, pt->sizecode, NO_REG) != 0); | |
| 437 | + return (symbexec(pt, pt->sizecode, NO_REG) != 0); | |
| 431 | 438 | } |
| 432 | 439 | |
| 433 | 440 | |
| @@ -447,7 +454,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { · 13 unmodified lines | ||
| 447 | 454 | *name = luaF_getlocalname(p, stackpos+1, pc); |
| 448 | 455 | if (*name) /* is a local? */ |
| 449 | 456 | return "local"; |
| 450 | − i = luaG_symbexec(p, pc, stackpos); /* try symbolic execution */ | |
| 457 | + i = symbexec(p, pc, stackpos); /* try symbolic execution */ | |
| 451 | 458 | lua_assert(pc != -1); |
| 452 | 459 | switch (GET_OPCODE(i)) { |
| 453 | 460 | case OP_GETGLOBAL: { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldo.c,v 2.10 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: ldo.c,v 2.13 2004/12/03 20:35:33 roberto Exp $ | |
| 3 | 3 | ** Stack and Call structure of Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -70,7 +70,7 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 64 unmodified lines | ||
| 70 | 70 | void luaD_throw (lua_State *L, int errcode) { |
| 71 | 71 | if (L->errorJmp) { |
| 72 | 72 | L->errorJmp->status = errcode; |
| 73 | − L_THROW(L->errorJmp); | |
| 73 | + L_THROW(L, L->errorJmp); | |
| 74 | 74 | } |
| 75 | 75 | else { |
| 76 | 76 | if (G(L)->panic) G(L)->panic(L); |
| @@ -84,7 +84,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 7 unmodified lines | ||
| 84 | 84 | lj.status = 0; |
| 85 | 85 | lj.previous = L->errorJmp; /* chain new error handler */ |
| 86 | 86 | L->errorJmp = &lj; |
| 87 | − L_TRY(&lj, | |
| 87 | + L_TRY(L, &lj, | |
| 88 | 88 | (*f)(L, ud); |
| 89 | 89 | ); |
| 90 | 90 | L->errorJmp = lj.previous; /* restore old error handler */ |
| @@ -147,7 +147,7 @@ void luaD_growstack (lua_State *L, int n) { · 56 unmodified lines | ||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
| 150 | −static CallInfo *luaD_growCI (lua_State *L) { | |
| 150 | +static CallInfo *growCI (lua_State *L) { | |
| 151 | 151 | if (L->size_ci > LUA_MAXCALLS) /* overflow while handling overflow? */ |
| 152 | 152 | luaD_throw(L, LUA_ERRERR); |
| 153 | 153 | else { |
| @@ -238,7 +238,7 @@ static StkId tryfuncTM (lua_State *L, StkId func) { · 84 unmodified lines | ||
| 238 | 238 | |
| 239 | 239 | |
| 240 | 240 | #define inc_ci(L) \ |
| 241 | − ((L->ci == L->end_ci) ? luaD_growCI(L) : \ | |
| 241 | + ((L->ci == L->end_ci) ? growCI(L) : \ | |
| 242 | 242 | (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) |
| 243 | 243 | |
| 244 | 244 | |
| @@ -391,7 +391,6 @@ static int resume_error (lua_State *L, const char *msg) { · 146 unmodified lines | ||
| 391 | 391 | |
| 392 | 392 | LUA_API int lua_resume (lua_State *L, int nargs) { |
| 393 | 393 | int status; |
| 394 | − lu_byte old_allowhooks; | |
| 395 | 394 | lua_lock(L); |
| 396 | 395 | lua_assert(L->errfunc == 0 && L->nCcalls == 0); |
| 397 | 396 | if (L->status != LUA_YIELD) { |
| @@ -400,7 +399,6 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 2 unmodified lines | ||
| 400 | 399 | else if (L->ci != L->base_ci) |
| 401 | 400 | return resume_error(L, "cannot resume non-suspended coroutine"); |
| 402 | 401 | } |
| 403 | − old_allowhooks = L->allowhook; | |
| 404 | 402 | status = luaD_rawrunprotected(L, resume, &nargs); |
| 405 | 403 | if (status != 0) { /* error? */ |
| 406 | 404 | L->status = status; /* mark thread as `dead' */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldump.c,v 1.8 2004/09/01 21:22:34 lhf Exp $ | |
| 2 | +** $Id: ldump.c,v 1.9 2004/11/25 09:31:41 lhf Exp $ | |
| 3 | 3 | ** save pre-compiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -113,14 +113,17 @@ static void DumpConstants(const Proto* f, DumpState* D) · 107 unmodified lines | ||
| 113 | 113 | DumpByte(ttype(o),D); |
| 114 | 114 | switch (ttype(o)) |
| 115 | 115 | { |
| 116 | + case LUA_TNIL: | |
| 117 | + break; | |
| 118 | + case LUA_TBOOLEAN: | |
| 119 | + DumpByte(bvalue(o),D); | |
| 120 | + break; | |
| 116 | 121 | case LUA_TNUMBER: |
| 117 | 122 | DumpNumber(nvalue(o),D); |
| 118 | 123 | break; |
| 119 | 124 | case LUA_TSTRING: |
| 120 | 125 | DumpString(rawtsvalue(o),D); |
| 121 | 126 | break; |
| 122 | − case LUA_TNIL: | |
| 123 | − break; | |
| 124 | 127 | default: |
| 125 | 128 | lua_assert(0); /* cannot happen */ |
| 126 | 129 | break; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lfunc.c,v 2.4 2004/04/30 20:13:38 roberto Exp $ | |
| 2 | +** $Id: lfunc.c,v 2.5 2004/11/24 19:20:21 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -75,7 +75,7 @@ void luaF_close (lua_State *L, StkId level) { · 69 unmodified lines | ||
| 75 | 75 | lua_assert(!isblack(o)); |
| 76 | 76 | L->openupval = uv->next; /* remove from `open' list */ |
| 77 | 77 | if (isdead(g, o)) |
| 78 | − luaM_freelem(L, uv); /* free upvalue */ | |
| 78 | + luaM_free(L, uv); /* free upvalue */ | |
| 79 | 79 | else { |
| 80 | 80 | setobj(L, &uv->value, uv->v); |
| 81 | 81 | uv->v = &uv->value; /* now current value lives here */ |
| @@ -117,14 +117,14 @@ void luaF_freeproto (lua_State *L, Proto *f) { · 35 unmodified lines | ||
| 117 | 117 | luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); |
| 118 | 118 | luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); |
| 119 | 119 | luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); |
| 120 | − luaM_freelem(L, f); | |
| 120 | + luaM_free(L, f); | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | void luaF_freeclosure (lua_State *L, Closure *c) { |
| 125 | 125 | int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : |
| 126 | 126 | sizeLclosure(c->l.nupvalues); |
| 127 | − luaM_free(L, c, size); | |
| 127 | + luaM_freemem(L, c, size); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lgc.c,v 2.12 2004/09/15 20:38:15 roberto Exp $ | |
| 2 | +** $Id: lgc.c,v 2.18 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Garbage Collector |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -24,7 +24,6 @@ · 18 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | #define GCSTEPSIZE 1000 |
| 27 | −#define STEPMUL 2 | |
| 28 | 27 | #define GCSWEEPMAX 10 |
| 29 | 28 | #define GCSWEEPCOST 30 |
| 30 | 29 | #define GCFINALIZECOST 100 |
| @@ -65,7 +64,7 @@ · 34 unmodified lines | ||
| 65 | 64 | static void removeentry (Node *n) { |
| 66 | 65 | setnilvalue(gval(n)); /* remove corresponding value ... */ |
| 67 | 66 | if (iscollectable(gkey(n))) |
| 68 | − setttype(gkey(n), LUA_TNONE); /* dead key; remove it */ | |
| 67 | + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ | |
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | |
| @@ -139,7 +138,7 @@ size_t luaC_separateudata (lua_State *L, int all) { · 67 unmodified lines | ||
| 139 | 138 | p = &curr->gch.next; |
| 140 | 139 | } |
| 141 | 140 | else { /* must call its gc method */ |
| 142 | − deadmem += sizeudata(gco2u(curr)->len); | |
| 141 | + deadmem += sizeudata(gco2u(curr)); | |
| 143 | 142 | markfinalized(gco2u(curr)); |
| 144 | 143 | *p = curr->gch.next; |
| 145 | 144 | curr->gch.next = NULL; /* link `curr' at the end of `collected' list */ |
| @@ -184,6 +183,7 @@ static int traversetable (global_State *g, Table *h) { · 38 unmodified lines | ||
| 184 | 183 | i = sizenode(h); |
| 185 | 184 | while (i--) { |
| 186 | 185 | Node *n = gnode(h, i); |
| 186 | + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); | |
| 187 | 187 | if (ttisnil(gval(n))) |
| 188 | 188 | removeentry(n); /* remove empty entries */ |
| 189 | 189 | else { |
| @@ -367,7 +367,7 @@ static void cleartable (GCObject *l) { · 177 unmodified lines | ||
| 367 | 367 | while (i--) { |
| 368 | 368 | Node *n = gnode(h, i); |
| 369 | 369 | if (!ttisnil(gval(n)) && /* non-empty entry? */ |
| 370 | − (iscleared(gkey(n), 1) || iscleared(gval(n), 0))) | |
| 370 | + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) | |
| 371 | 371 | removeentry(n); /* remove entry from table */ |
| 372 | 372 | } |
| 373 | 373 | l = h->gclist; |
| @@ -379,7 +379,7 @@ static void freeobj (lua_State *L, GCObject *o) { · 5 unmodified lines | ||
| 379 | 379 | switch (o->gch.tt) { |
| 380 | 380 | case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; |
| 381 | 381 | case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; |
| 382 | − case LUA_TUPVAL: luaM_freelem(L, gco2uv(o)); break; | |
| 382 | + case LUA_TUPVAL: luaM_free(L, gco2uv(o)); break; | |
| 383 | 383 | case LUA_TTABLE: luaH_free(L, gco2h(o)); break; |
| 384 | 384 | case LUA_TTHREAD: { |
| 385 | 385 | lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); |
| @@ -388,11 +388,11 @@ static void freeobj (lua_State *L, GCObject *o) { · 2 unmodified lines | ||
| 388 | 388 | } |
| 389 | 389 | case LUA_TSTRING: { |
| 390 | 390 | G(L)->strt.nuse--; |
| 391 | − luaM_free(L, o, sizestring(gco2ts(o)->len)); | |
| 391 | + luaM_freemem(L, o, sizestring(gco2ts(o))); | |
| 392 | 392 | break; |
| 393 | 393 | } |
| 394 | 394 | case LUA_TUSERDATA: { |
| 395 | − luaM_free(L, o, sizeudata(gco2u(o)->len)); | |
| 395 | + luaM_freemem(L, o, sizeudata(gco2u(o))); | |
| 396 | 396 | break; |
| 397 | 397 | } |
| 398 | 398 | default: lua_assert(0); |
| @@ -529,6 +529,7 @@ static void remarkupvals (global_State *g) { · 130 unmodified lines | ||
| 529 | 529 | |
| 530 | 530 | static void atomic (lua_State *L) { |
| 531 | 531 | global_State *g = G(L); |
| 532 | + size_t udsize; /* total size of userdata to be finalized */ | |
| 532 | 533 | int aux; |
| 533 | 534 | /* remark objects cautch by write barrier */ |
| 534 | 535 | propagateall(g); |
| @@ -544,7 +545,7 @@ static void atomic (lua_State *L) { · 9 unmodified lines | ||
| 544 | 545 | g->gray = g->grayagain; |
| 545 | 546 | g->grayagain = NULL; |
| 546 | 547 | propagateall(g); |
| 547 | − luaC_separateudata(L, 0); /* separate userdata to be preserved */ | |
| 548 | + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ | |
| 548 | 549 | marktmu(g); /* mark `preserved' userdata */ |
| 549 | 550 | propagateall(g); /* remark, to propagate `preserveness' */ |
| 550 | 551 | cleartable(g->weak); /* remove collected objects from weak tables */ |
| @@ -554,10 +555,10 @@ static void atomic (lua_State *L) { · 3 unmodified lines | ||
| 554 | 555 | g->sweepgc = &g->rootgc; |
| 555 | 556 | g->gcstate = GCSsweepstring; |
| 556 | 557 | aux = g->gcgenerational; |
| 557 | − g->gcgenerational = (g->estimate <= 4*g->prevestimate/2); | |
| 558 | + g->gcgenerational = g->incgc && (g->estimate/2 <= g->prevestimate); | |
| 558 | 559 | if (!aux) /* last collection was full? */ |
| 559 | 560 | g->prevestimate = g->estimate; /* keep estimate of last full collection */ |
| 560 | − g->estimate = g->totalbytes; /* first estimate */ | |
| 561 | + g->estimate = g->totalbytes - udsize; /* first estimate */ | |
| 561 | 562 | } |
| 562 | 563 | |
| 563 | 564 | |
| @@ -586,6 +587,7 @@ static l_mem singlestep (lua_State *L) { · 22 unmodified lines | ||
| 586 | 587 | sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); |
| 587 | 588 | if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ |
| 588 | 589 | g->gcstate = GCSsweep; /* end sweep-string phase */ |
| 590 | + lua_assert(old >= g->totalbytes); | |
| 589 | 591 | g->estimate -= old - g->totalbytes; |
| 590 | 592 | return GCSWEEPCOST; |
| 591 | 593 | } |
| @@ -596,12 +598,15 @@ static l_mem singlestep (lua_State *L) { · 4 unmodified lines | ||
| 596 | 598 | checkSizes(L); |
| 597 | 599 | g->gcstate = GCSfinalize; /* end sweep phase */ |
| 598 | 600 | } |
| 601 | + lua_assert(old >= g->totalbytes); | |
| 599 | 602 | g->estimate -= old - g->totalbytes; |
| 600 | 603 | return GCSWEEPMAX*GCSWEEPCOST; |
| 601 | 604 | } |
| 602 | 605 | case GCSfinalize: { |
| 603 | 606 | if (g->tmudata) { |
| 607 | + g->GCthreshold += GCFINALIZECOST; /* avoid GC steps inside method */ | |
| 604 | 608 | GCTM(L); |
| 609 | + g->GCthreshold -= GCFINALIZECOST; /* correct threshold */ | |
| 605 | 610 | return GCFINALIZECOST; |
| 606 | 611 | } |
| 607 | 612 | else { |
| @@ -616,23 +621,18 @@ static l_mem singlestep (lua_State *L) { · 8 unmodified lines | ||
| 616 | 621 | |
| 617 | 622 | void luaC_step (lua_State *L) { |
| 618 | 623 | global_State *g = G(L); |
| 619 | − l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * STEPMUL; | |
| 620 | −/*printf("step(%c): ", g->gcgenerational?'g':' ');*/ | |
| 624 | + l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * g->stepmul; | |
| 621 | 625 | do { |
| 622 | − /*printf("%c", "_pswf"[g->gcstate]);*/ | |
| 623 | 626 | lim -= singlestep(L); |
| 624 | 627 | if (g->gcstate == GCSpause) |
| 625 | 628 | break; |
| 626 | − } while (lim > 0); | |
| 627 | −/*printf("\n");*/ | |
| 628 | − if (g->gcstate != GCSpause) | |
| 629 | + } while (lim > 0 || !g->incgc); | |
| 630 | + if (g->incgc) | |
| 629 | 631 | g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */ |
| 630 | 632 | else { |
| 631 | −/*printf("---\n");*/ | |
| 632 | 633 | lua_assert(g->totalbytes >= g->estimate); |
| 634 | + lua_assert(g->gcstate == GCSpause); | |
| 633 | 635 | g->GCthreshold = 2*g->estimate; |
| 634 | − if (g->GCthreshold < g->totalbytes + GCSTEPSIZE) | |
| 635 | − g->GCthreshold = g->totalbytes + GCSTEPSIZE; | |
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | |
| @@ -657,20 +657,19 @@ void luaC_fullgc (lua_State *L) { · 18 unmodified lines | ||
| 657 | 657 | } |
| 658 | 658 | markroot(L); |
| 659 | 659 | lua_assert(!g->gcgenerational); |
| 660 | − while (g->gcstate != GCSfinalize) { | |
| 660 | + while (g->gcstate != GCSpause) { | |
| 661 | 661 | singlestep(L); |
| 662 | 662 | g->gcgenerational = 0; /* keep it in this mode */ |
| 663 | 663 | } |
| 664 | − lua_assert(g->estimate == g->totalbytes); | |
| 665 | 664 | g->GCthreshold = 2*g->estimate; |
| 666 | − luaC_callGCTM(L); /* call finalizers */ | |
| 667 | 665 | } |
| 668 | 666 | |
| 669 | 667 | |
| 670 | 668 | void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { |
| 671 | 669 | global_State *g = G(L); |
| 672 | 670 | lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); |
| 673 | − lua_assert(g->gcgenerational || g->gcstate != GCSfinalize); | |
| 671 | + lua_assert(g->gcgenerational || | |
| 672 | + (g->gcstate != GCSfinalize && g->gcstate != GCSpause)); | |
| 674 | 673 | lua_assert(ttype(&o->gch) != LUA_TTABLE); |
| 675 | 674 | /* must keep invariant? */ |
| 676 | 675 | if (g->gcstate == GCSpropagate || g->gcgenerational) |
| @@ -683,7 +682,8 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { · 6 unmodified lines | ||
| 683 | 682 | void luaC_barrierback (lua_State *L, GCObject *o, GCObject *v) { |
| 684 | 683 | global_State *g = G(L); |
| 685 | 684 | lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); |
| 686 | − lua_assert(g->gcgenerational || g->gcstate != GCSfinalize); | |
| 685 | + lua_assert(g->gcgenerational || | |
| 686 | + (g->gcstate != GCSfinalize && g->gcstate != GCSpause)); | |
| 687 | 687 | black2gray(o); /* make table gray (again) */ |
| 688 | 688 | gco2h(o)->gclist = g->grayagain; |
| 689 | 689 | g->grayagain = o; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lauxlib.c,v 1.124 2004/09/03 13:17:14 roberto Exp $ | |
| 2 | +** $Id: lauxlib.c,v 1.126 2004/09/29 21:03:14 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -239,16 +239,22 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, · 233 unmodified lines | ||
| 239 | 239 | const luaL_reg *l, int nup) { |
| 240 | 240 | if (libname) { |
| 241 | 241 | /* check whether lib already exists */ |
| 242 | − lua_getglobal(L, libname); | |
| 243 | − if (lua_isnil(L, -1)) { /* no? */ | |
| 244 | − lua_pop(L, 1); | |
| 242 | + luaL_getfield(L, LUA_GLOBALSINDEX, libname); | |
| 243 | + if (lua_isnil(L, -1)) { /* not found? */ | |
| 244 | + lua_pop(L, 1); /* remove previous result */ | |
| 245 | 245 | lua_newtable(L); /* create it */ |
| 246 | 246 | if (lua_getmetatable(L, LUA_GLOBALSINDEX)) |
| 247 | 247 | lua_setmetatable(L, -2); /* share metatable with global table */ |
| 248 | − lua_pushvalue(L, -1); | |
| 249 | 248 | /* register it with given name */ |
| 250 | − lua_setglobal(L, libname); | |
| 249 | + lua_pushvalue(L, -1); | |
| 250 | + luaL_setfield(L, LUA_GLOBALSINDEX, libname); | |
| 251 | 251 | } |
| 252 | + else if (!lua_istable(L, -1)) | |
| 253 | + luaL_error(L, "name conflict for library `%s'", libname); | |
| 254 | + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 255 | + lua_pushvalue(L, -2); | |
| 256 | + lua_setfield(L, -2, libname); /* _LOADED[modname] = new table */ | |
| 257 | + lua_pop(L, 1); /* remove _LOADED table */ | |
| 252 | 258 | lua_insert(L, -(nup+1)); /* move library table to below upvalues */ |
| 253 | 259 | } |
| 254 | 260 | for (; l->name; l++) { |
| @@ -352,8 +358,8 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { · 97 unmodified lines | ||
| 352 | 358 | } |
| 353 | 359 | |
| 354 | 360 | |
| 355 | −static const char *luaL_gsub (lua_State *L, const char *s, | |
| 356 | − const char *p, const char *r) { | |
| 361 | +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, | |
| 362 | + const char *r) { | |
| 357 | 363 | const char *wild; |
| 358 | 364 | int l = strlen(p); |
| 359 | 365 | luaL_Buffer b; |
| @@ -381,16 +387,68 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, · 21 unmodified lines | ||
| 381 | 387 | } |
| 382 | 388 | fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); |
| 383 | 389 | lua_remove(L, -2); /* remove path template */ |
| 384 | − f = fopen(fname, "r"); /* try to read it */ | |
| 390 | + f = fopen(fname, "r"); /* try to open it */ | |
| 385 | 391 | if (f) { |
| 392 | + int err; | |
| 393 | + getc(f); /* try to read file */ | |
| 394 | + err = ferror(f); | |
| 386 | 395 | fclose(f); |
| 387 | − return fname; | |
| 396 | + if (err == 0) /* open and read sucessful? */ | |
| 397 | + return fname; /* return that file name */ | |
| 388 | 398 | } |
| 389 | 399 | lua_pop(L, 1); /* remove file name */ |
| 390 | 400 | } |
| 391 | 401 | } |
| 392 | 402 | |
| 393 | 403 | |
| 404 | +LUALIB_API const char *luaL_getfield (lua_State *L, int idx, | |
| 405 | + const char *fname) { | |
| 406 | + const char *e; | |
| 407 | + lua_pushvalue(L, idx); | |
| 408 | + while ((e = strchr(fname, '.')) != NULL) { | |
| 409 | + lua_pushlstring(L, fname, e - fname); | |
| 410 | + lua_rawget(L, -2); | |
| 411 | + lua_remove(L, -2); /* remove previous table */ | |
| 412 | + fname = e + 1; | |
| 413 | + if (!lua_istable(L, -1)) return fname; | |
| 414 | + } | |
| 415 | + lua_pushstring(L, fname); | |
| 416 | + lua_rawget(L, -2); /* get last field */ | |
| 417 | + lua_remove(L, -2); /* remove previous table */ | |
| 418 | + return NULL; | |
| 419 | +} | |
| 420 | + | |
| 421 | + | |
| 422 | +LUALIB_API const char *luaL_setfield (lua_State *L, int idx, | |
| 423 | + const char *fname) { | |
| 424 | + const char *e; | |
| 425 | + lua_pushvalue(L, idx); | |
| 426 | + while ((e = strchr(fname, '.')) != NULL) { | |
| 427 | + lua_pushlstring(L, fname, e - fname); | |
| 428 | + lua_rawget(L, -2); | |
| 429 | + if (lua_isnil(L, -1)) { /* no such field? */ | |
| 430 | + lua_pop(L, 1); /* remove this nil */ | |
| 431 | + lua_newtable(L); /* create a new table for field */ | |
| 432 | + lua_pushlstring(L, fname, e - fname); | |
| 433 | + lua_pushvalue(L, -2); | |
| 434 | + lua_settable(L, -4); /* set new table into field */ | |
| 435 | + } | |
| 436 | + lua_remove(L, -2); /* remove previous table */ | |
| 437 | + fname = e + 1; | |
| 438 | + if (!lua_istable(L, -1)) { | |
| 439 | + lua_pop(L, 2); /* remove table and value */ | |
| 440 | + return fname; | |
| 441 | + } | |
| 442 | + } | |
| 443 | + lua_pushstring(L, fname); | |
| 444 | + lua_pushvalue(L, -3); /* move value to the top */ | |
| 445 | + lua_rawset(L, -3); /* set last field */ | |
| 446 | + lua_pop(L, 2); /* remove value and table */ | |
| 447 | + return NULL; | |
| 448 | +} | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 394 | 452 | /* |
| 395 | 453 | ** {====================================================== |
| 396 | 454 | ** Generic Buffer manipulation |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lbaselib.c,v 1.158 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: lbaselib.c,v 1.161 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Basic library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -181,10 +181,10 @@ static int luaB_gcinfo (lua_State *L) { · 175 unmodified lines | ||
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | static int luaB_collectgarbage (lua_State *L) { |
| 184 | − static const char *const opts[] = {"stop", "restart", "collect", "count", | |
| 185 | − "step", NULL}; | |
| 186 | − static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, | |
| 187 | − LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCSTEP}; | |
| 184 | + static const char *const opts[] = {"stop", "restart", "collect", | |
| 185 | + "count", "step", "setstepmul", "setincmode", NULL}; | |
| 186 | + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, | |
| 187 | + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETSTEPMUL, LUA_GCSETINCMODE}; | |
| 188 | 188 | int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); |
| 189 | 189 | int ex = luaL_optint(L, 2, 0); |
| 190 | 190 | luaL_argcheck(L, o >= 0, 1, "invalid option"); |
| @@ -440,50 +440,6 @@ static int luaB_newproxy (lua_State *L) { · 249 unmodified lines | ||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | |
| 443 | −/* | |
| 444 | −** {====================================================== | |
| 445 | −** `require' function | |
| 446 | −** ======================================================= | |
| 447 | −*/ | |
| 448 | − | |
| 449 | − | |
| 450 | −static const char *getpath (lua_State *L) { | |
| 451 | − /* try first `LUA_PATH' for compatibility */ | |
| 452 | − lua_getfield(L, LUA_GLOBALSINDEX, "LUA_PATH"); | |
| 453 | − if (!lua_isstring(L, -1)) { | |
| 454 | − lua_pop(L, 1); | |
| 455 | − lua_getfield(L, LUA_GLOBALSINDEX, "_PATH"); | |
| 456 | − } | |
| 457 | − if (!lua_isstring(L, -1)) | |
| 458 | − luaL_error(L, "global _PATH must be a string"); | |
| 459 | − return lua_tostring(L, -1); | |
| 460 | −} | |
| 461 | − | |
| 462 | − | |
| 463 | −static int luaB_require (lua_State *L) { | |
| 464 | − const char *name = luaL_checkstring(L, 1); | |
| 465 | − const char *fname; | |
| 466 | − lua_getfield(L, lua_upvalueindex(1), name); | |
| 467 | − if (lua_toboolean(L, -1)) /* is it there? */ | |
| 468 | − return 1; /* package is already loaded; return its result */ | |
| 469 | − /* else must load it; first mark it as loaded */ | |
| 470 | − lua_pushboolean(L, 1); | |
| 471 | − lua_setfield(L, lua_upvalueindex(1), name); /* _LOADED[name] = true */ | |
| 472 | − fname = luaL_searchpath(L, name, getpath(L)); | |
| 473 | − if (fname == NULL || luaL_loadfile(L, fname) != 0) | |
| 474 | − return luaL_error(L, "error loading package `%s' (%s)", name, | |
| 475 | − lua_tostring(L, -1)); | |
| 476 | − lua_pushvalue(L, 1); /* pass name as argument to module */ | |
| 477 | − lua_call(L, 1, 1); /* run loaded module */ | |
| 478 | − if (!lua_isnil(L, -1)) /* nil return? */ | |
| 479 | − lua_setfield(L, lua_upvalueindex(1), name); | |
| 480 | − lua_getfield(L, lua_upvalueindex(1), name); /* return _LOADED[name] */ | |
| 481 | − return 1; | |
| 482 | −} | |
| 483 | − | |
| 484 | −/* }====================================================== */ | |
| 485 | − | |
| 486 | − | |
| 487 | 443 | static const luaL_reg base_funcs[] = { |
| 488 | 444 | {"error", luaB_error}, |
| 489 | 445 | {"getmetatable", luaB_getmetatable}, |
| @@ -656,11 +612,10 @@ static void auxopen (lua_State *L, const char *name, · 166 unmodified lines | ||
| 656 | 612 | |
| 657 | 613 | |
| 658 | 614 | static void base_open (lua_State *L) { |
| 659 | − const char *path; | |
| 660 | 615 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 661 | 616 | luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */ |
| 662 | 617 | lua_pushliteral(L, LUA_VERSION); |
| 663 | − lua_setfield(L, LUA_GLOBALSINDEX, "_VERSION"); /* set global _VERSION */ | |
| 618 | + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ | |
| 664 | 619 | /* `ipairs' and `pairs' need auxliliary functions as upvalues */ |
| 665 | 620 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); |
| 666 | 621 | auxopen(L, "pairs", luaB_pairs, luaB_next); |
| @@ -671,21 +626,16 @@ static void base_open (lua_State *L) { · 4 unmodified lines | ||
| 671 | 626 | lua_pushliteral(L, "kv"); |
| 672 | 627 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ |
| 673 | 628 | lua_pushcclosure(L, luaB_newproxy, 1); |
| 674 | − lua_setfield(L, LUA_GLOBALSINDEX, "newproxy"); /* set global `newproxy' */ | |
| 675 | − /* `require' needs a table to keep loaded chunks */ | |
| 629 | + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ | |
| 630 | + /* create register._LOADED to track loaded modules */ | |
| 631 | + lua_newtable(L); | |
| 632 | + lua_setfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 633 | + /* create register._PRELOAD to allow pre-loaded modules */ | |
| 676 | 634 | lua_newtable(L); |
| 677 | − lua_pushvalue(L, -1); | |
| 678 | − lua_setglobal(L, "_LOADED"); | |
| 679 | − lua_pushcclosure(L, luaB_require, 1); | |
| 680 | − lua_setfield(L, LUA_GLOBALSINDEX, "require"); | |
| 635 | + lua_setfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); | |
| 681 | 636 | /* set global _G */ |
| 682 | 637 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 683 | − lua_setfield(L, LUA_GLOBALSINDEX, "_G"); | |
| 684 | − /* set global _PATH */ | |
| 685 | − path = getenv(LUA_PATH); | |
| 686 | − if (path == NULL) path = LUA_PATH_DEFAULT; | |
| 687 | − lua_pushstring(L, path); | |
| 688 | − lua_setfield(L, LUA_GLOBALSINDEX, "_PATH"); | |
| 638 | + lua_setglobal(L, "_G"); | |
| 689 | 639 | } |
| 690 | 640 | |
| 691 | 641 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldblib.c,v 1.87 2004/08/13 18:02:36 roberto Exp $ | |
| 2 | +** $Id: ldblib.c,v 1.89 2004/11/17 12:02:41 roberto Exp $ | |
| 3 | 3 | ** Interface from Lua to its debug API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -261,7 +261,7 @@ static int debug (lua_State *L) { · 255 unmodified lines | ||
| 261 | 261 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || |
| 262 | 262 | strcmp(buffer, "cont\n") == 0) |
| 263 | 263 | return 0; |
| 264 | − if (luaL_loadbuffer(L, buffer, strlen(buffer), "=debug command") || | |
| 264 | + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || | |
| 265 | 265 | lua_pcall(L, 0, 0, 0)) { |
| 266 | 266 | fputs(lua_tostring(L, -1), stderr); |
| 267 | 267 | fputs("\n", stderr); |
| @@ -275,14 +275,15 @@ static int debug (lua_State *L) { · 7 unmodified lines | ||
| 275 | 275 | #define LEVELS2 10 /* size of the second part of the stack */ |
| 276 | 276 | |
| 277 | 277 | static int errorfb (lua_State *L) { |
| 278 | − int level = 1; /* skip level 0 (it's this function) */ | |
| 278 | + int level = 0; | |
| 279 | 279 | int firstpart = 1; /* still before eventual `...' */ |
| 280 | 280 | int arg; |
| 281 | 281 | lua_State *L1 = getthread(L, &arg); |
| 282 | 282 | lua_Debug ar; |
| 283 | + if (L == L1) level++; /* skip level 0 (it's this function) */ | |
| 283 | 284 | if (lua_gettop(L) == arg) |
| 284 | 285 | lua_pushliteral(L, ""); |
| 285 | − else if (!lua_isstring(L, arg+1)) return 1; /* no string message */ | |
| 286 | + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ | |
| 286 | 287 | else lua_pushliteral(L, "\n"); |
| 287 | 288 | lua_pushliteral(L, "stack traceback:"); |
| 288 | 289 | while (lua_getstack(L1, level++, &ar)) { |
| @@ -1,31 +1,35 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loadlib.c,v 1.6 2004/04/30 20:13:38 roberto Exp $ | |
| 2 | +** $Id: loadlib.c,v 1.11 2004/11/19 15:52:12 roberto Exp $ | |
| 3 | 3 | ** Dynamic library loader for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | * |
| 6 | −* This Lua library exports a single function, called loadlib, which is | |
| 7 | −* called from Lua as loadlib(lib,init), where lib is the full name of the | |
| 8 | −* library to be loaded (including the complete path) and init is the name | |
| 9 | −* of a function to be called after the library is loaded. Typically, this | |
| 10 | −* function will register other functions, thus making the complete library | |
| 11 | −* available to Lua. The init function is *not* automatically called by | |
| 12 | −* loadlib. Instead, loadlib returns the init function as a Lua function | |
| 13 | −* that the client can call when it thinks is appropriate. In the case of | |
| 14 | −* errors, loadlib returns nil and two strings describing the error. | |
| 15 | −* The first string is supplied by the operating system; it should be | |
| 16 | −* informative and useful for error messages. The second string is "open", | |
| 17 | −* "init", or "absent" to identify the error and is meant to be used for | |
| 18 | −* making decisions without having to look into the first string (whose | |
| 19 | −* format is system-dependent). | |
| 20 | −* | |
| 21 | −* This module contains an implementation of loadlib for Unix systems that | |
| 22 | −* have dlfcn, an implementation for Windows, and a stub for other systems. | |
| 23 | −* See the list at the end of this file for some links to available | |
| 24 | −* implementations of dlfcn and interfaces to other native dynamic loaders | |
| 25 | −* on top of which loadlib could be implemented. | |
| 26 | −* | |
| 6 | +* This Lua library exports a single function, called loadlib, which | |
| 7 | +* is called from Lua as loadlib(lib,init), where lib is the full | |
| 8 | +* name of the library to be loaded (including the complete path) and | |
| 9 | +* init is the name of a function to be called after the library is | |
| 10 | +* loaded. Typically, this function will register other functions, thus | |
| 11 | +* making the complete library available to Lua. The init function is | |
| 12 | +* *not* automatically called by loadlib. Instead, loadlib returns the | |
| 13 | +* init function as a Lua function that the client can call when it | |
| 14 | +* thinks is appropriate. In the case of errors, loadlib returns nil and | |
| 15 | +* two strings describing the error. The first string is supplied by | |
| 16 | +* the operating system; it should be informative and useful for error | |
| 17 | +* messages. The second string is "open", "init", or "absent" to identify | |
| 18 | +* the error and is meant to be used for making decisions without having | |
| 19 | +* to look into the first string (whose format is system-dependent). | |
| 20 | +* This module contains an implementation of loadlib for Unix systems | |
| 21 | +* that have dlfcn, an implementation for Darwin (Mac OS X), an | |
| 22 | +* implementation for Windows, and a stub for other systems. See | |
| 23 | +* the list at the end of this file for some links to available | |
| 24 | +* implementations of dlfcn and interfaces to other native dynamic | |
| 25 | +* loaders on top of which loadlib could be implemented. | |
| 27 | 26 | */ |
| 28 | 27 | |
| 28 | + | |
| 29 | +#include <stdlib.h> | |
| 30 | +#include <string.h> | |
| 31 | + | |
| 32 | + | |
| 29 | 33 | #define loadlib_c |
| 30 | 34 | #define LUA_LIB |
| 31 | 35 | |
| @@ -34,11 +38,14 @@ · 2 unmodified lines | ||
| 34 | 38 | #include "lualib.h" |
| 35 | 39 | |
| 36 | 40 | |
| 37 | −#undef LOADLIB | |
| 41 | +#define ERR_OPEN 1 | |
| 42 | +#define ERR_FUNCTION 2 | |
| 43 | + | |
| 44 | + | |
| 45 | +static void registerlib (lua_State *L, const void *lib); | |
| 38 | 46 | |
| 39 | 47 | |
| 40 | −#ifdef USE_DLOPEN | |
| 41 | −#define LOADLIB | |
| 48 | +#if defined(USE_DLOPEN) | |
| 42 | 49 | /* |
| 43 | 50 | * This is an implementation of loadlib based on the dlfcn interface. |
| 44 | 51 | * The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, |
| @@ -48,53 +55,41 @@ · 3 unmodified lines | ||
| 48 | 55 | |
| 49 | 56 | #include <dlfcn.h> |
| 50 | 57 | |
| 51 | −static int loadlib(lua_State *L) | |
| 58 | +#define freelib dlclose | |
| 59 | + | |
| 60 | +static int loadlib(lua_State *L, const char *path, const char *init) | |
| 52 | 61 | { |
| 53 | − const char *path=luaL_checkstring(L,1); | |
| 54 | − const char *init=luaL_checkstring(L,2); | |
| 55 | 62 | void *lib=dlopen(path,RTLD_NOW); |
| 56 | 63 | if (lib!=NULL) |
| 57 | 64 | { |
| 58 | 65 | lua_CFunction f=(lua_CFunction) dlsym(lib,init); |
| 59 | 66 | if (f!=NULL) |
| 60 | 67 | { |
| 61 | − lua_pushlightuserdata(L,lib); | |
| 62 | − lua_pushcclosure(L,f,1); | |
| 63 | − return 1; | |
| 68 | + registerlib(L, lib); | |
| 69 | + lua_pushcfunction(L,f); | |
| 70 | + return 0; | |
| 64 | 71 | } |
| 65 | 72 | } |
| 66 | − /* else return appropriate error messages */ | |
| 67 | − lua_pushnil(L); | |
| 73 | + /* else return appropriate error message */ | |
| 68 | 74 | lua_pushstring(L,dlerror()); |
| 69 | − lua_pushstring(L,(lib!=NULL) ? "init" : "open"); | |
| 70 | − if (lib!=NULL) dlclose(lib); | |
| 71 | − return 3; | |
| 75 | + if (lib!=NULL) { | |
| 76 | + dlclose(lib); | |
| 77 | + return ERR_FUNCTION; /* error loading function */ | |
| 78 | + } | |
| 79 | + else return ERR_OPEN; /* error loading library */ | |
| 72 | 80 | } |
| 73 | 81 | |
| 74 | −#endif | |
| 75 | − | |
| 76 | − | |
| 77 | − | |
| 78 | −/* | |
| 79 | −** In Windows, default is to use dll; otherwise, default is not to use dll | |
| 80 | −*/ | |
| 81 | −#ifndef USE_DLL | |
| 82 | −#ifdef _WIN32 | |
| 83 | −#define USE_DLL 1 | |
| 84 | −#else | |
| 85 | −#define USE_DLL 0 | |
| 86 | −#endif | |
| 87 | −#endif | |
| 88 | 82 | |
| 89 | 83 | |
| 90 | −#if USE_DLL | |
| 91 | −#define LOADLIB | |
| 84 | +#elif defined(USE_DLL) | |
| 92 | 85 | /* |
| 93 | 86 | * This is an implementation of loadlib for Windows using native functions. |
| 94 | 87 | */ |
| 95 | 88 | |
| 96 | 89 | #include <windows.h> |
| 97 | 90 | |
| 91 | +#define freelib(lib) FreeLibrary((HINSTANCE)lib) | |
| 92 | + | |
| 98 | 93 | static void pusherror(lua_State *L) |
| 99 | 94 | { |
| 100 | 95 | int error=GetLastError(); |
| @@ -106,61 +101,310 @@ static void pusherror(lua_State *L) · 5 unmodified lines | ||
| 106 | 101 | lua_pushfstring(L,"system error %d\n",error); |
| 107 | 102 | } |
| 108 | 103 | |
| 109 | −static int loadlib(lua_State *L) | |
| 104 | +static int loadlib(lua_State *L, const char *path, const char *init) | |
| 110 | 105 | { |
| 111 | − const char *path=luaL_checkstring(L,1); | |
| 112 | − const char *init=luaL_checkstring(L,2); | |
| 113 | 106 | HINSTANCE lib=LoadLibrary(path); |
| 114 | 107 | if (lib!=NULL) |
| 115 | 108 | { |
| 116 | 109 | lua_CFunction f=(lua_CFunction) GetProcAddress(lib,init); |
| 117 | 110 | if (f!=NULL) |
| 118 | 111 | { |
| 119 | − lua_pushlightuserdata(L,lib); | |
| 120 | − lua_pushcclosure(L,f,1); | |
| 112 | + registerlib(L, lib); | |
| 113 | + lua_pushcfunction(L,f); | |
| 121 | 114 | return 1; |
| 122 | 115 | } |
| 123 | 116 | } |
| 124 | − lua_pushnil(L); | |
| 125 | 117 | pusherror(L); |
| 126 | − lua_pushstring(L,(lib!=NULL) ? "init" : "open"); | |
| 127 | − if (lib!=NULL) FreeLibrary(lib); | |
| 128 | − return 3; | |
| 118 | + if (lib!=NULL) { | |
| 119 | + FreeLibrary(lib); | |
| 120 | + return ERR_OPEN; | |
| 121 | + } | |
| 122 | + else return ERR_FUNCTION; | |
| 129 | 123 | } |
| 130 | 124 | |
| 131 | −#endif | |
| 132 | 125 | |
| 133 | 126 | |
| 127 | +/* Native Mac OS X / Darwin Implementation */ | |
| 128 | +#elif defined(USE_DYLD) | |
| 129 | + | |
| 130 | +#include <mach-o/dyld.h> | |
| 131 | + | |
| 132 | + | |
| 133 | +/* Mach cannot unload images (?) */ | |
| 134 | +#define freelib(lib) ((void)lib) | |
| 135 | + | |
| 136 | +static void pusherror (lua_State *L) | |
| 137 | +{ | |
| 138 | + const char *err_str; | |
| 139 | + const char *err_file; | |
| 140 | + NSLinkEditErrors err; | |
| 141 | + int err_num; | |
| 142 | + NSLinkEditError(&err, &err_num, &err_file, &err_str); | |
| 143 | + lua_pushstring(L, err_str); | |
| 144 | +} | |
| 145 | + | |
| 146 | +static int loadlib (lua_State *L, const char *path, const char *init) { | |
| 147 | + const struct mach_header *lib; | |
| 148 | + /* this would be a rare case, but prevents crashing if it happens */ | |
| 149 | + if(!_dyld_present()) { | |
| 150 | + lua_pushstring(L,"dyld not present."); | |
| 151 | + return ERR_OPEN; | |
| 152 | + } | |
| 153 | + lib = NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); | |
| 154 | + if(lib != NULL) { | |
| 155 | + NSSymbol init_sym = NSLookupSymbolInImage(lib, init, | |
| 156 | + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | | |
| 157 | + NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); | |
| 158 | + if(init_sym != NULL) { | |
| 159 | + lua_CFunction f = (lua_CFunction)NSAddressOfSymbol(init_sym); | |
| 160 | + registerlib(L, lib); | |
| 161 | + lua_pushcfunction(L,f); | |
| 162 | + return 0; | |
| 163 | + } | |
| 164 | + } | |
| 165 | + /* else an error ocurred */ | |
| 166 | + pusherror(L); | |
| 167 | + /* Can't unload image */ | |
| 168 | + return (lib != NULL) ? ERR_FUNCTION : ERR_OPEN; | |
| 169 | +} | |
| 170 | + | |
| 134 | 171 | |
| 135 | −#ifndef LOADLIB | |
| 136 | −/* Fallback for other systems */ | |
| 137 | 172 | |
| 138 | −/* | |
| 139 | −** Those systems support dlopen, so they should have defined USE_DLOPEN. | |
| 140 | −** The default (no)implementation gives them a special error message. | |
| 141 | −*/ | |
| 142 | −#if defined(linux) || defined(sun) || defined(sgi) || defined(BSD) || defined(_WIN32) | |
| 143 | −#define LOADLIB "`loadlib' not installed (check your Lua configuration)" | |
| 144 | 173 | #else |
| 145 | −#define LOADLIB "`loadlib' not supported" | |
| 146 | −#endif | |
| 174 | +/* Fallback for other systems */ | |
| 175 | + | |
| 147 | 176 | |
| 177 | +#define freelib(lib) ((void)lib) | |
| 148 | 178 | |
| 149 | 179 | static int loadlib(lua_State *L) |
| 150 | 180 | { |
| 181 | + registerlib(L, NULL); /* to avoid warnings */ | |
| 151 | 182 | lua_pushnil(L); |
| 152 | − lua_pushliteral(L,LOADLIB); | |
| 183 | + lua_pushliteral(L,"`loadlib' not supported"); | |
| 153 | 184 | lua_pushliteral(L,"absent"); |
| 154 | 185 | return 3; |
| 155 | 186 | } |
| 187 | + | |
| 156 | 188 | #endif |
| 157 | 189 | |
| 158 | −LUALIB_API int luaopen_loadlib (lua_State *L) | |
| 190 | + | |
| 191 | +/* | |
| 192 | +** common code for all implementations: put a library into the registry | |
| 193 | +** so that, when Lua closes its state, the library's __gc metamethod | |
| 194 | +** will be called to unload the library. | |
| 195 | +*/ | |
| 196 | +static void registerlib (lua_State *L, const void *lib) | |
| 197 | +{ | |
| 198 | + const void **plib = (const void **)lua_newuserdata(L, sizeof(const void *)); | |
| 199 | + *plib = lib; | |
| 200 | + luaL_getmetatable(L, "_LOADLIB"); | |
| 201 | + lua_setmetatable(L, -2); | |
| 202 | + lua_pushboolean(L, 1); | |
| 203 | + lua_settable(L, LUA_REGISTRYINDEX); /* registry[lib] = true */ | |
| 204 | +} | |
| 205 | + | |
| 206 | +/* | |
| 207 | +** __gc tag method: calls library's `freelib' function with the lib | |
| 208 | +** handle | |
| 209 | +*/ | |
| 210 | +static int gctm (lua_State *L) | |
| 159 | 211 | { |
| 160 | − lua_register(L,"loadlib",loadlib); | |
| 212 | + void *lib = *(void **)luaL_checkudata(L, 1, "_LOADLIB"); | |
| 213 | + freelib(lib); | |
| 161 | 214 | return 0; |
| 162 | 215 | } |
| 163 | 216 | |
| 217 | + | |
| 218 | +static int loadlib1 (lua_State *L) { | |
| 219 | + const char *path=luaL_checkstring(L,1); | |
| 220 | + const char *init=luaL_checkstring(L,2); | |
| 221 | + int res = loadlib(L,path,init); | |
| 222 | + if (res == 0) /* no error? */ | |
| 223 | + return 1; /* function is at stack top */ | |
| 224 | + else { /* error */ | |
| 225 | + lua_pushnil(L); | |
| 226 | + lua_insert(L,-2); /* insert nil before error message */ | |
| 227 | + lua_pushstring(L, (res==ERR_OPEN)?"open":"init"); | |
| 228 | + return 3; | |
| 229 | + } | |
| 230 | +} | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | +/* | |
| 235 | +** {====================================================== | |
| 236 | +** `require' and `module' functions | |
| 237 | +** ======================================================= | |
| 238 | +*/ | |
| 239 | + | |
| 240 | + | |
| 241 | +static const char *loadLua (lua_State *L, const char *fname, const char *name) { | |
| 242 | + const char *path; | |
| 243 | + /* try first `LUA_PATH' for compatibility */ | |
| 244 | + lua_getglobal(L, "LUA_PATH"); | |
| 245 | + path = lua_tostring(L, -1); | |
| 246 | + if (!path) { | |
| 247 | + lua_pop(L, 1); | |
| 248 | + luaL_getfield(L, LUA_GLOBALSINDEX, "package.path"); | |
| 249 | + path = lua_tostring(L, -1); | |
| 250 | + } | |
| 251 | + if (path == NULL) | |
| 252 | + luaL_error(L, "`package.path' must be a string"); | |
| 253 | + fname = luaL_searchpath(L, fname, path); | |
| 254 | + if (fname == NULL) return path; /* library not found in this path */ | |
| 255 | + if (luaL_loadfile(L, fname) != 0) | |
| 256 | + luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); | |
| 257 | + return NULL; /* library loaded successfully */ | |
| 258 | +} | |
| 259 | + | |
| 260 | + | |
| 261 | +static const char *loadC (lua_State *L, const char *fname, const char *name) { | |
| 262 | + const char *path; | |
| 263 | + const char *funcname; | |
| 264 | + luaL_getfield(L, LUA_GLOBALSINDEX, "package.cpath"); | |
| 265 | + path = lua_tostring(L, -1); | |
| 266 | + if (path == NULL) | |
| 267 | + luaL_error(L, "global _CPATH must be a string"); | |
| 268 | + fname = luaL_searchpath(L, fname, path); | |
| 269 | + if (fname == NULL) return path; /* library not found in this path */ | |
| 270 | + funcname = luaL_gsub(L, name, ".", ""); | |
| 271 | + funcname = lua_pushfstring(L, "%s%s", LUA_POF, funcname); | |
| 272 | + if (loadlib(L, fname, funcname) != 0) | |
| 273 | + luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); | |
| 274 | + return NULL; /* library loaded successfully */ | |
| 275 | +} | |
| 276 | + | |
| 277 | + | |
| 278 | +static int ll_require (lua_State *L) { | |
| 279 | + const char *name = luaL_checkstring(L, 1); | |
| 280 | + lua_settop(L, 1); | |
| 281 | + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 282 | + lua_getfield(L, 2, name); | |
| 283 | + if (lua_toboolean(L, -1)) /* is it there? */ | |
| 284 | + return 1; /* package is already loaded; return its result */ | |
| 285 | + /* else must load it; first mark it as loaded */ | |
| 286 | + lua_pushboolean(L, 1); | |
| 287 | + lua_setfield(L, 2, name); /* _LOADED[name] = true */ | |
| 288 | + /* check whether it is preloaded */ | |
| 289 | + lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); | |
| 290 | + lua_getfield(L, -1, name); | |
| 291 | + if (lua_isnil(L, -1)) { /* no preload function for that module? */ | |
| 292 | + const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP); | |
| 293 | + const char *cpath = loadC(L, fname, name); /* try a C module */ | |
| 294 | + if (cpath) { /* not found? */ | |
| 295 | + const char *path = loadLua(L, fname, name); /* try a Lua module */ | |
| 296 | + if (path) { /* yet not found? */ | |
| 297 | + lua_pushnil(L); | |
| 298 | + lua_setfield(L, 2, name); /* unmark _LOADED[name] */ | |
| 299 | + return luaL_error(L, "package `%s' not found\n" | |
| 300 | + " cpath: %s\n path: %s", | |
| 301 | + name, cpath, path); | |
| 302 | + } | |
| 303 | + } | |
| 304 | + } | |
| 305 | + lua_pushvalue(L, 1); /* pass name as argument to module */ | |
| 306 | + lua_call(L, 1, 1); /* run loaded module */ | |
| 307 | + if (!lua_isnil(L, -1)) /* non-nil return? */ | |
| 308 | + lua_setfield(L, 2, name); /* update _LOADED[name] with returned value */ | |
| 309 | + lua_getfield(L, 2, name); /* return _LOADED[name] */ | |
| 310 | + return 1; | |
| 311 | +} | |
| 312 | + | |
| 313 | + | |
| 314 | +static void setfenv (lua_State *L) { | |
| 315 | + lua_Debug ar; | |
| 316 | + lua_getstack(L, 1, &ar); | |
| 317 | + lua_getinfo(L, "f", &ar); | |
| 318 | + lua_pushvalue(L, -2); | |
| 319 | + lua_setfenv(L, -2); | |
| 320 | +} | |
| 321 | + | |
| 322 | + | |
| 323 | +static int ll_module (lua_State *L) { | |
| 324 | + const char *modname = luaL_checkstring(L, 1); | |
| 325 | + const char *dot; | |
| 326 | + lua_settop(L, 1); | |
| 327 | + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 328 | + /* try to find given table */ | |
| 329 | + luaL_getfield(L, LUA_GLOBALSINDEX, modname); | |
| 330 | + if (lua_isnil(L, -1)) { /* not found? */ | |
| 331 | + lua_pop(L, 1); /* remove previous result */ | |
| 332 | + lua_newtable(L); /* create it */ | |
| 333 | + /* register it with given name */ | |
| 334 | + lua_pushvalue(L, -1); | |
| 335 | + luaL_setfield(L, LUA_GLOBALSINDEX, modname); | |
| 336 | + } | |
| 337 | + else if (!lua_istable(L, -1)) | |
| 338 | + return luaL_error(L, "name conflict for module `%s'", modname); | |
| 339 | + /* check whether table already has a _NAME field */ | |
| 340 | + lua_getfield(L, -1, "_NAME"); | |
| 341 | + if (!lua_isnil(L, -1)) /* is table an initialized module? */ | |
| 342 | + lua_pop(L, 1); | |
| 343 | + else { /* no; initialize it */ | |
| 344 | + lua_pop(L, 1); | |
| 345 | + lua_newtable(L); /* create new metatable */ | |
| 346 | + lua_pushvalue(L, LUA_GLOBALSINDEX); | |
| 347 | + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ | |
| 348 | + lua_setmetatable(L, -2); | |
| 349 | + lua_pushstring(L, modname); | |
| 350 | + lua_setfield(L, -2, "_NAME"); | |
| 351 | + dot = strrchr(modname, '.'); /* look for last dot in module name */ | |
| 352 | + if (dot == NULL) dot = modname; | |
| 353 | + else dot++; | |
| 354 | + /* set _PACKAGE as package name (full module name minus last part) */ | |
| 355 | + lua_pushlstring(L, modname, dot - modname); | |
| 356 | + lua_setfield(L, -2, "_PACKAGE"); | |
| 357 | + } | |
| 358 | + lua_pushvalue(L, -1); | |
| 359 | + lua_setfield(L, 2, modname); /* _LOADED[modname] = new table */ | |
| 360 | + setfenv(L); | |
| 361 | + return 0; | |
| 362 | +} | |
| 363 | + | |
| 364 | + | |
| 365 | +/* }====================================================== */ | |
| 366 | + | |
| 367 | + | |
| 368 | +static const luaL_reg ll_funcs[] = { | |
| 369 | + {"loadlib", loadlib1}, | |
| 370 | + {"require", ll_require}, | |
| 371 | + {"module", ll_module}, | |
| 372 | + {NULL, NULL} | |
| 373 | +}; | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | +LUALIB_API int luaopen_loadlib (lua_State *L) { | |
| 378 | + const char *path; | |
| 379 | + /* create new type _LOADLIB */ | |
| 380 | + luaL_newmetatable(L, "_LOADLIB"); | |
| 381 | + lua_pushcfunction(L, gctm); | |
| 382 | + lua_setfield(L, -2, "__gc"); | |
| 383 | + /* create `package' table */ | |
| 384 | + lua_newtable(L); | |
| 385 | + lua_pushvalue(L, -1); | |
| 386 | + lua_setglobal(L, "package"); | |
| 387 | + /* set field `path' */ | |
| 388 | + path = getenv(LUA_PATH); | |
| 389 | + if (path == NULL) path = LUA_PATH_DEFAULT; | |
| 390 | + lua_pushstring(L, path); | |
| 391 | + lua_setfield(L, -2, "path"); | |
| 392 | + /* set field `cpath' */ | |
| 393 | + path = getenv(LUA_CPATH); | |
| 394 | + if (path == NULL) path = LUA_CPATH_DEFAULT; | |
| 395 | + lua_pushstring(L, path); | |
| 396 | + lua_setfield(L, -2, "cpath"); | |
| 397 | + /* set field `loaded' */ | |
| 398 | + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 399 | + lua_setfield(L, -2, "loaded"); | |
| 400 | + /* set field `preload' */ | |
| 401 | + lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); | |
| 402 | + lua_setfield(L, -2, "preload"); | |
| 403 | + lua_pushvalue(L, LUA_GLOBALSINDEX); | |
| 404 | + luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */ | |
| 405 | + return 1; | |
| 406 | +} | |
| 407 | + | |
| 164 | 408 | /* |
| 165 | 409 | * Here are some links to available implementations of dlfcn and |
| 166 | 410 | * interfaces to other native dynamic loaders on top of which loadlib |
| @@ -179,9 +423,6 @@ LUALIB_API int luaopen_loadlib (lua_State *L) · 12 unmodified lines | ||
| 179 | 423 | * Macintosh, Windows |
| 180 | 424 | * http://www.stat.umn.edu/~luke/xls/projects/dlbasics/dlbasics.html |
| 181 | 425 | * |
| 182 | −* Mac OS X/Darwin | |
| 183 | −* http://www.opendarwin.org/projects/dlcompat/ | |
| 184 | −* | |
| 185 | 426 | * GLIB has wrapper code for BeOS, OS2, Unix and Windows |
| 186 | 427 | * http://cvs.gnome.org/lxr/source/glib/gmodule/ |
| 187 | 428 | * |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loslib.c,v 1.2 2004/08/05 19:30:37 roberto Exp $ | |
| 2 | +** $Id: loslib.c,v 1.3 2004/10/08 18:57:16 roberto Exp $ | |
| 3 | 3 | ** Standard Operating System library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -20,7 +20,7 @@ · 14 unmodified lines | ||
| 20 | 20 | #include "lualib.h" |
| 21 | 21 | |
| 22 | 22 | |
| 23 | −static int pushresult (lua_State *L, int i, const char *filename) { | |
| 23 | +static int os_pushresult (lua_State *L, int i, const char *filename) { | |
| 24 | 24 | if (i) { |
| 25 | 25 | lua_pushboolean(L, 1); |
| 26 | 26 | return 1; |
| @@ -45,14 +45,14 @@ static int io_execute (lua_State *L) { · 18 unmodified lines | ||
| 45 | 45 | |
| 46 | 46 | static int io_remove (lua_State *L) { |
| 47 | 47 | const char *filename = luaL_checkstring(L, 1); |
| 48 | − return pushresult(L, remove(filename) == 0, filename); | |
| 48 | + return os_pushresult(L, remove(filename) == 0, filename); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | static int io_rename (lua_State *L) { |
| 53 | 53 | const char *fromname = luaL_checkstring(L, 1); |
| 54 | 54 | const char *toname = luaL_checkstring(L, 2); |
| 55 | − return pushresult(L, rename(fromname, toname) == 0, fromname); | |
| 55 | + return os_pushresult(L, rename(fromname, toname) == 0, fromname); | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstrlib.c,v 1.106 2004/08/09 13:30:33 roberto Exp $ | |
| 2 | +** $Id: lstrlib.c,v 1.109 2004/12/01 15:46:06 roberto Exp $ | |
| 3 | 3 | ** Standard library for string operations and pattern-matching |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -24,8 +24,6 @@ · 18 unmodified lines | ||
| 24 | 24 | #define uchar(c) ((unsigned char)(c)) |
| 25 | 25 | |
| 26 | 26 | |
| 27 | −typedef lua_Integer sint32; /* a signed version for size_t */ | |
| 28 | − | |
| 29 | 27 | |
| 30 | 28 | static int str_len (lua_State *L) { |
| 31 | 29 | size_t l; |
| @@ -35,19 +33,19 @@ static int str_len (lua_State *L) { · 3 unmodified lines | ||
| 35 | 33 | } |
| 36 | 34 | |
| 37 | 35 | |
| 38 | −static sint32 posrelat (sint32 pos, size_t len) { | |
| 36 | +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { | |
| 39 | 37 | /* relative string position: negative means back from end */ |
| 40 | − return (pos>=0) ? pos : (sint32)len+pos+1; | |
| 38 | + return (pos>=0) ? pos : (ptrdiff_t)len+pos+1; | |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | 41 | |
| 44 | 42 | static int str_sub (lua_State *L) { |
| 45 | 43 | size_t l; |
| 46 | 44 | const char *s = luaL_checklstring(L, 1, &l); |
| 47 | − sint32 start = posrelat(luaL_checkinteger(L, 2), l); | |
| 48 | − sint32 end = posrelat(luaL_optinteger(L, 3, -1), l); | |
| 45 | + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); | |
| 46 | + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); | |
| 49 | 47 | if (start < 1) start = 1; |
| 50 | − if (end > (sint32)l) end = (sint32)l; | |
| 48 | + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; | |
| 51 | 49 | if (start <= end) |
| 52 | 50 | lua_pushlstring(L, s+start-1, end-start+1); |
| 53 | 51 | else lua_pushliteral(L, ""); |
| @@ -107,8 +105,8 @@ static int str_rep (lua_State *L) { · 53 unmodified lines | ||
| 107 | 105 | static int str_byte (lua_State *L) { |
| 108 | 106 | size_t l; |
| 109 | 107 | const char *s = luaL_checklstring(L, 1, &l); |
| 110 | − sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l); | |
| 111 | − sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l); | |
| 108 | + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); | |
| 109 | + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); | |
| 112 | 110 | int n, i; |
| 113 | 111 | if (posi <= 0) posi = 1; |
| 114 | 112 | if ((size_t)pose > l) pose = l; |
| @@ -173,7 +171,7 @@ typedef struct MatchState { · 58 unmodified lines | ||
| 173 | 171 | int level; /* total number of captures (finished or unfinished) */ |
| 174 | 172 | struct { |
| 175 | 173 | const char *init; |
| 176 | − sint32 len; | |
| 174 | + ptrdiff_t len; | |
| 177 | 175 | } capture[MAX_CAPTURES]; |
| 178 | 176 | } MatchState; |
| 179 | 177 | |
| @@ -198,7 +196,7 @@ static int capture_to_close (MatchState *ms) { · 18 unmodified lines | ||
| 198 | 196 | } |
| 199 | 197 | |
| 200 | 198 | |
| 201 | −static const char *luaI_classend (MatchState *ms, const char *p) { | |
| 199 | +static const char *classend (MatchState *ms, const char *p) { | |
| 202 | 200 | switch (*p++) { |
| 203 | 201 | case ESC: { |
| 204 | 202 | if (*p == '\0') |
| @@ -250,7 +248,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 45 unmodified lines | ||
| 250 | 248 | while (++p < ec) { |
| 251 | 249 | if (*p == ESC) { |
| 252 | 250 | p++; |
| 253 | − if (match_class(c, *p)) | |
| 251 | + if (match_class(c, uchar(*p))) | |
| 254 | 252 | return sig; |
| 255 | 253 | } |
| 256 | 254 | else if ((*(p+1) == '-') && (p+2 < ec)) { |
| @@ -264,10 +262,10 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 7 unmodified lines | ||
| 264 | 262 | } |
| 265 | 263 | |
| 266 | 264 | |
| 267 | −static int luaI_singlematch (int c, const char *p, const char *ep) { | |
| 265 | +static int singlematch (int c, const char *p, const char *ep) { | |
| 268 | 266 | switch (*p) { |
| 269 | 267 | case '.': return 1; /* matches any char */ |
| 270 | − case ESC: return match_class(c, *(p+1)); | |
| 268 | + case ESC: return match_class(c, uchar(*(p+1))); | |
| 271 | 269 | case '[': return matchbracketclass(c, p, ep-1); |
| 272 | 270 | default: return (uchar(*p) == c); |
| 273 | 271 | } |
| @@ -299,8 +297,8 @@ static const char *matchbalance (MatchState *ms, const char *s, · 25 unmodified lines | ||
| 299 | 297 | |
| 300 | 298 | static const char *max_expand (MatchState *ms, const char *s, |
| 301 | 299 | const char *p, const char *ep) { |
| 302 | − sint32 i = 0; /* counts maximum expand for item */ | |
| 303 | − while ((s+i)<ms->src_end && luaI_singlematch(uchar(*(s+i)), p, ep)) | |
| 300 | + ptrdiff_t i = 0; /* counts maximum expand for item */ | |
| 301 | + while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep)) | |
| 304 | 302 | i++; |
| 305 | 303 | /* keeps trying to match with the maximum repetitions */ |
| 306 | 304 | while (i>=0) { |
| @@ -318,7 +316,7 @@ static const char *min_expand (MatchState *ms, const char *s, · 11 unmodified lines | ||
| 318 | 316 | const char *res = match(ms, s, ep+1); |
| 319 | 317 | if (res != NULL) |
| 320 | 318 | return res; |
| 321 | − else if (s<ms->src_end && luaI_singlematch(uchar(*s), p, ep)) | |
| 319 | + else if (s<ms->src_end && singlematch(uchar(*s), p, ep)) | |
| 322 | 320 | s++; /* try with one more repetition */ |
| 323 | 321 | else return NULL; |
| 324 | 322 | } |
| @@ -385,7 +383,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 60 unmodified lines | ||
| 385 | 383 | p += 2; |
| 386 | 384 | if (*p != '[') |
| 387 | 385 | luaL_error(ms->L, "missing `[' after `%%f' in pattern"); |
| 388 | − ep = luaI_classend(ms, p); /* points to what is next */ | |
| 386 | + ep = classend(ms, p); /* points to what is next */ | |
| 389 | 387 | previous = (s == ms->src_init) ? '\0' : *(s-1); |
| 390 | 388 | if (matchbracketclass(uchar(previous), p, ep-1) || |
| 391 | 389 | !matchbracketclass(uchar(*s), p, ep-1)) return NULL; |
| @@ -393,7 +391,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 1 unmodified line | ||
| 393 | 391 | } |
| 394 | 392 | default: { |
| 395 | 393 | if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ |
| 396 | − s = match_capture(ms, s, *(p+1)); | |
| 394 | + s = match_capture(ms, s, uchar(*(p+1))); | |
| 397 | 395 | if (s == NULL) return NULL; |
| 398 | 396 | p+=2; goto init; /* else return match(ms, s, p+2) */ |
| 399 | 397 | } |
| @@ -410,8 +408,8 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 10 unmodified lines | ||
| 410 | 408 | else goto dflt; |
| 411 | 409 | } |
| 412 | 410 | default: dflt: { /* it is a pattern item */ |
| 413 | − const char *ep = luaI_classend(ms, p); /* points to what is next */ | |
| 414 | − int m = s<ms->src_end && luaI_singlematch(uchar(*s), p, ep); | |
| 411 | + const char *ep = classend(ms, p); /* points to what is next */ | |
| 412 | + int m = s<ms->src_end && singlematch(uchar(*s), p, ep); | |
| 415 | 413 | switch (*ep) { |
| 416 | 414 | case '?': { /* optional */ |
| 417 | 415 | const char *res; |
| @@ -490,9 +488,9 @@ static int str_find (lua_State *L) { · 72 unmodified lines | ||
| 490 | 488 | size_t l1, l2; |
| 491 | 489 | const char *s = luaL_checklstring(L, 1, &l1); |
| 492 | 490 | const char *p = luaL_checklstring(L, 2, &l2); |
| 493 | − sint32 init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; | |
| 491 | + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; | |
| 494 | 492 | if (init < 0) init = 0; |
| 495 | − else if ((size_t)(init) > l1) init = (sint32)l1; | |
| 493 | + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; | |
| 496 | 494 | if (lua_toboolean(L, 4) || /* explicit request? */ |
| 497 | 495 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ |
| 498 | 496 | /* do a plain search */ |
| @@ -642,7 +640,7 @@ static int str_gsub (lua_State *L) { · 143 unmodified lines | ||
| 642 | 640 | #define MAX_FORMAT 20 |
| 643 | 641 | |
| 644 | 642 | |
| 645 | −static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { | |
| 643 | +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { | |
| 646 | 644 | size_t l; |
| 647 | 645 | const char *s = luaL_checklstring(L, arg, &l); |
| 648 | 646 | luaL_putchar(b, '"'); |
| @@ -726,7 +724,7 @@ static int str_format (lua_State *L) { · 77 unmodified lines | ||
| 726 | 724 | break; |
| 727 | 725 | } |
| 728 | 726 | case 'q': { |
| 729 | − luaI_addquoted(L, &b, arg); | |
| 727 | + addquoted(L, &b, arg); | |
| 730 | 728 | continue; /* skip the `addsize' at the end */ |
| 731 | 729 | } |
| 732 | 730 | case 's': { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llex.c,v 2.3 2004/04/30 20:13:38 roberto Exp $ | |
| 2 | +** $Id: llex.c,v 2.9 2004/12/03 20:54:12 roberto Exp $ | |
| 3 | 3 | ** Lexical Analyzer |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -26,34 +26,45 @@ · 20 unmodified lines | ||
| 26 | 26 | #define next(ls) (ls->current = zgetc(ls->z)) |
| 27 | 27 | |
| 28 | 28 | |
| 29 | −#define save(ls,c) { \ | |
| 30 | − Mbuffer *b = ls->buff; \ | |
| 31 | − if (b->n + 1 > b->buffsize) \ | |
| 32 | − luaZ_resizebuffer(ls->L, b, ((b->buffsize*2) + LUA_MINBUFFER)); \ | |
| 33 | − b->buffer[b->n++] = cast(char, c); } | |
| 34 | − | |
| 35 | 29 | |
| 36 | 30 | |
| 37 | 31 | #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') |
| 38 | 32 | |
| 39 | 33 | |
| 40 | 34 | /* ORDER RESERVED */ |
| 41 | −static const char *const token2string [] = { | |
| 35 | +const char *const luaX_tokens [] = { | |
| 42 | 36 | "and", "break", "do", "else", "elseif", |
| 43 | 37 | "end", "false", "for", "function", "if", |
| 44 | 38 | "in", "local", "nil", "not", "or", "repeat", |
| 45 | − "return", "then", "true", "until", "while", "*name", | |
| 39 | + "return", "then", "true", "until", "while", | |
| 46 | 40 | "..", "...", "==", ">=", "<=", "~=", |
| 47 | − "*number", "*string", "<eof>" | |
| 41 | + "<number>", "<name>", "<string>", "<eof>", | |
| 42 | + NULL | |
| 48 | 43 | }; |
| 49 | 44 | |
| 50 | 45 | |
| 46 | +#define save_and_next(ls) (save(ls, ls->current), next(ls)) | |
| 47 | + | |
| 48 | + | |
| 49 | +static void save (LexState *ls, int c) { | |
| 50 | + Mbuffer *b = ls->buff; | |
| 51 | + if (b->n + 1 > b->buffsize) { | |
| 52 | + size_t newsize; | |
| 53 | + if (b->buffsize >= MAX_SIZET/2) | |
| 54 | + luaX_lexerror(ls, "lexical element too long", 0); | |
| 55 | + newsize = b->buffsize * 2; | |
| 56 | + luaZ_resizebuffer(ls->L, b, newsize); | |
| 57 | + } | |
| 58 | + b->buffer[b->n++] = cast(char, c); | |
| 59 | +} | |
| 60 | + | |
| 61 | + | |
| 51 | 62 | void luaX_init (lua_State *L) { |
| 52 | 63 | int i; |
| 53 | 64 | for (i=0; i<NUM_RESERVED; i++) { |
| 54 | − TString *ts = luaS_new(L, token2string[i]); | |
| 65 | + TString *ts = luaS_new(L, luaX_tokens[i]); | |
| 55 | 66 | luaS_fix(ts); /* reserved words are never collected */ |
| 56 | − lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN); | |
| 67 | + lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN); | |
| 57 | 68 | ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */ |
| 58 | 69 | } |
| 59 | 70 | } |
| @@ -64,12 +75,12 @@ void luaX_init (lua_State *L) { · 4 unmodified lines | ||
| 64 | 75 | |
| 65 | 76 | const char *luaX_token2str (LexState *ls, int token) { |
| 66 | 77 | if (token < FIRST_RESERVED) { |
| 67 | − lua_assert(token == (unsigned char)token); | |
| 78 | + lua_assert(token == cast(unsigned char, token)); | |
| 68 | 79 | return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : |
| 69 | 80 | luaO_pushfstring(ls->L, "%c", token); |
| 70 | 81 | } |
| 71 | 82 | else |
| 72 | − return token2string[token-FIRST_RESERVED]; | |
| 83 | + return luaX_tokens[token-FIRST_RESERVED]; | |
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | |
| @@ -130,6 +141,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 54 unmodified lines | ||
| 130 | 141 | ls->linenumber = 1; |
| 131 | 142 | ls->lastline = 1; |
| 132 | 143 | ls->source = source; |
| 144 | + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ | |
| 133 | 145 | next(ls); /* read first char */ |
| 134 | 146 | } |
| 135 | 147 | |
| @@ -143,12 +155,6 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 7 unmodified lines | ||
| 143 | 155 | |
| 144 | 156 | |
| 145 | 157 | |
| 146 | −static void save_and_next (LexState *ls) { | |
| 147 | − save(ls, ls->current); | |
| 148 | − next(ls); | |
| 149 | −} | |
| 150 | − | |
| 151 | − | |
| 152 | 158 | |
| 153 | 159 | /* LUA_NUMBER */ |
| 154 | 160 | static void read_numeral (LexState *ls, SemInfo *seminfo) { |
| @@ -181,12 +187,12 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 26 unmodified lines | ||
| 181 | 187 | } |
| 182 | 188 | |
| 183 | 189 | |
| 184 | −static int skip_ast (LexState *ls) { | |
| 190 | +static int skip_sep (LexState *ls) { | |
| 185 | 191 | int count = 0; |
| 186 | 192 | int s = ls->current; |
| 187 | 193 | lua_assert(s == '[' || s == ']'); |
| 188 | 194 | save_and_next(ls); |
| 189 | − while (ls->current == '*') { | |
| 195 | + while (ls->current == '=') { | |
| 190 | 196 | save_and_next(ls); |
| 191 | 197 | count++; |
| 192 | 198 | } |
| @@ -194,7 +200,7 @@ static int skip_ast (LexState *ls) { · 1 unmodified line | ||
| 194 | 200 | } |
| 195 | 201 | |
| 196 | 202 | |
| 197 | −static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) { | |
| 203 | +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { | |
| 198 | 204 | int cont = 0; |
| 199 | 205 | save_and_next(ls); /* skip 2nd `[' */ |
| 200 | 206 | if (currIsNewline(ls)) /* string starts with a newline? */ |
| @@ -206,13 +212,13 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) { · 5 unmodified lines | ||
| 206 | 212 | "unfinished long comment", TK_EOS); |
| 207 | 213 | break; /* to avoid warnings */ |
| 208 | 214 | case '[': |
| 209 | − if (skip_ast(ls) == ast) { | |
| 215 | + if (skip_sep(ls) == sep) { | |
| 210 | 216 | save_and_next(ls); /* skip 2nd `[' */ |
| 211 | 217 | cont++; |
| 212 | 218 | } |
| 213 | 219 | continue; |
| 214 | 220 | case ']': |
| 215 | − if (skip_ast(ls) == ast) { | |
| 221 | + if (skip_sep(ls) == sep) { | |
| 216 | 222 | save_and_next(ls); /* skip 2nd `]' */ |
| 217 | 223 | if (cont-- == 0) goto endloop; |
| 218 | 224 | } |
| @@ -229,8 +235,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) { · 10 unmodified lines | ||
| 229 | 235 | } |
| 230 | 236 | } endloop: |
| 231 | 237 | if (seminfo) |
| 232 | − seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + ast), | |
| 233 | − luaZ_bufflen(ls->buff) - 2*(2 + ast)); | |
| 238 | + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), | |
| 239 | + luaZ_bufflen(ls->buff) - 2*(2 + sep)); | |
| 234 | 240 | } |
| 235 | 241 | |
| 236 | 242 | |
| @@ -305,10 +311,10 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 68 unmodified lines | ||
| 305 | 311 | /* else is a comment */ |
| 306 | 312 | next(ls); |
| 307 | 313 | if (ls->current == '[') { |
| 308 | − int ast = skip_ast(ls); | |
| 309 | − luaZ_resetbuffer(ls->buff); /* `skip_ast' may dirty the buffer */ | |
| 310 | − if (ast >= 0) { | |
| 311 | − read_long_string(ls, NULL, ast); /* long comment */ | |
| 314 | + int sep = skip_sep(ls); | |
| 315 | + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ | |
| 316 | + if (sep >= 0) { | |
| 317 | + read_long_string(ls, NULL, sep); /* long comment */ | |
| 312 | 318 | luaZ_resetbuffer(ls->buff); |
| 313 | 319 | continue; |
| 314 | 320 | } |
| @@ -319,12 +325,12 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 4 unmodified lines | ||
| 319 | 325 | continue; |
| 320 | 326 | } |
| 321 | 327 | case '[': { |
| 322 | − int ast = skip_ast(ls); | |
| 323 | − if (ast >= 0) { | |
| 324 | − read_long_string(ls, seminfo, ast); | |
| 328 | + int sep = skip_sep(ls); | |
| 329 | + if (sep >= 0) { | |
| 330 | + read_long_string(ls, seminfo, sep); | |
| 325 | 331 | return TK_STRING; |
| 326 | 332 | } |
| 327 | − else if (ast == -1) return '['; | |
| 333 | + else if (sep == -1) return '['; | |
| 328 | 334 | else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); |
| 329 | 335 | } |
| 330 | 336 | case '=': { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llex.h,v 1.50 2004/03/12 19:53:56 roberto Exp $ | |
| 2 | +** $Id: llex.h,v 1.52 2004/12/03 20:54:12 roberto Exp $ | |
| 3 | 3 | ** Lexical Analyzer |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -28,14 +28,18 @@ enum RESERVED { · 22 unmodified lines | ||
| 28 | 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, |
| 29 | 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, |
| 30 | 30 | /* other terminal symbols */ |
| 31 | − TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, | |
| 32 | − TK_STRING, TK_EOS | |
| 31 | + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, | |
| 32 | + TK_NAME, TK_STRING, TK_EOS | |
| 33 | 33 | }; |
| 34 | 34 | |
| 35 | 35 | /* number of reserved words */ |
| 36 | 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) |
| 37 | 37 | |
| 38 | 38 | |
| 39 | +/* array with token `names' */ | |
| 40 | +extern const char *const luaX_tokens []; | |
| 41 | + | |
| 42 | + | |
| 39 | 43 | typedef union { |
| 40 | 44 | lua_Number r; |
| 41 | 45 | TString *ts; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llimits.h,v 1.60 2004/09/10 17:30:46 roberto Exp $ | |
| 2 | +** $Id: llimits.h,v 1.61 2004/11/24 18:55:56 roberto Exp $ | |
| 3 | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -18,22 +18,9 @@ · 12 unmodified lines | ||
| 18 | 18 | |
| 19 | 19 | typedef LUA_UINT32 lu_int32; |
| 20 | 20 | |
| 21 | −typedef LUA_INT32 l_int32; | |
| 21 | +typedef LU_MEM lu_mem; | |
| 22 | 22 | |
| 23 | − | |
| 24 | −/* | |
| 25 | −** an unsigned integer big enough to count the total memory used by Lua; | |
| 26 | −** it should be at least as large as `size_t' | |
| 27 | −*/ | |
| 28 | −typedef lu_int32 lu_mem; | |
| 29 | − | |
| 30 | − | |
| 31 | −/* | |
| 32 | −** a signed integer big enough to count the total memory used by Lua; | |
| 33 | −** it should be at least as large as `size_t' | |
| 34 | −*/ | |
| 35 | −typedef l_int32 l_mem; | |
| 36 | −#define MAXLMEM LUA_MAXINT32 | |
| 23 | +typedef L_MEM l_mem; | |
| 37 | 24 | |
| 38 | 25 | |
| 39 | 26 | |
| @@ -43,6 +30,8 @@ typedef unsigned char lu_byte; · 3 unmodified lines | ||
| 43 | 30 | |
| 44 | 31 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
| 45 | 32 | |
| 33 | +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) | |
| 34 | + | |
| 46 | 35 | |
| 47 | 36 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ |
| 48 | 37 | |
| @@ -51,7 +40,7 @@ typedef unsigned char lu_byte; · 2 unmodified lines | ||
| 51 | 40 | ** this is for hashing only; there is no problem if the integer |
| 52 | 41 | ** cannot hold the whole pointer value |
| 53 | 42 | */ |
| 54 | −#define IntPoint(p) ((unsigned int)(p)) | |
| 43 | +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) | |
| 55 | 44 | |
| 56 | 45 | |
| 57 | 46 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lmem.c,v 1.65 2004/08/30 13:44:44 roberto Exp $ | |
| 2 | +** $Id: lmem.c,v 1.67 2004/12/01 15:46:18 roberto Exp $ | |
| 3 | 3 | ** Interface to Memory Manager |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -43,36 +43,39 @@ · 37 unmodified lines | ||
| 43 | 43 | #define MINSIZEARRAY 4 |
| 44 | 44 | |
| 45 | 45 | |
| 46 | −void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | |
| 47 | − int limit, const char *errormsg) { | |
| 46 | +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, | |
| 47 | + int limit, const char *errormsg) { | |
| 48 | 48 | void *newblock; |
| 49 | 49 | int newsize; |
| 50 | 50 | if (*size >= limit/2) { /* cannot double it? */ |
| 51 | − if (*size >= limit - MINSIZEARRAY) /* try something smaller... */ | |
| 51 | + if (*size >= limit) /* cannot grow even a little? */ | |
| 52 | 52 | luaG_runerror(L, errormsg); |
| 53 | − newsize = limit; /* still have at least MINSIZEARRAY free places */ | |
| 53 | + newsize = limit; /* still have at least one free place */ | |
| 54 | 54 | } |
| 55 | 55 | else { |
| 56 | 56 | newsize = (*size)*2; |
| 57 | 57 | if (newsize < MINSIZEARRAY) |
| 58 | 58 | newsize = MINSIZEARRAY; /* minimum size */ |
| 59 | 59 | } |
| 60 | − newblock = luaM_realloc(L, block, | |
| 61 | − cast(lu_mem, *size)*cast(lu_mem, size_elems), | |
| 62 | − cast(lu_mem, newsize)*cast(lu_mem, size_elems)); | |
| 60 | + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); | |
| 63 | 61 | *size = newsize; /* update only when everything else is OK */ |
| 64 | 62 | return newblock; |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | 65 | |
| 66 | +void *luaM_toobig (lua_State *L) { | |
| 67 | + luaG_runerror(L, "memory allocation error: block too big"); | |
| 68 | + return NULL; /* to avoid warnings */ | |
| 69 | +} | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 68 | 73 | /* |
| 69 | 74 | ** generic allocation routine. |
| 70 | 75 | */ |
| 71 | −void *luaM_realloc (lua_State *L, void *block, lu_mem osize, lu_mem nsize) { | |
| 76 | +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { | |
| 72 | 77 | global_State *g = G(L); |
| 73 | 78 | lua_assert((osize == 0) == (block == NULL)); |
| 74 | − if (nsize >= MAX_SIZET) | |
| 75 | − luaG_runerror(L, "memory allocation error: block too big"); | |
| 76 | 79 | block = (*g->realloc)(g->ud, block, osize, nsize); |
| 77 | 80 | if (block == NULL && nsize > 0) |
| 78 | 81 | luaD_throw(L, LUA_ERRMEM); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lmem.h,v 1.26 2002/05/01 20:40:42 roberto Exp $ | |
| 2 | +** $Id: lmem.h,v 1.29 2004/12/01 15:46:18 roberto Exp $ | |
| 3 | 3 | ** Interface to Memory Manager |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -16,28 +16,34 @@ · 10 unmodified lines | ||
| 16 | 16 | #define MEMERRMSG "not enough memory" |
| 17 | 17 | |
| 18 | 18 | |
| 19 | −void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); | |
| 19 | +void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size); | |
| 20 | 20 | |
| 21 | −void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, | |
| 22 | − int limit, const char *errormsg); | |
| 21 | +void *luaM_toobig (lua_State *L); | |
| 23 | 22 | |
| 24 | −#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) | |
| 25 | −#define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) | |
| 26 | −#define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ | |
| 27 | − cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0) | |
| 23 | +#define luaM_reallocv(L,b,on,n,e) \ | |
| 24 | + ((cast(unsigned int, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ | |
| 25 | + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ | |
| 26 | + luaM_toobig(L)) | |
| 28 | 27 | |
| 29 | −#define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) | |
| 30 | −#define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t))) | |
| 31 | −#define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \ | |
| 32 | − cast(lu_mem, n)*cast(lu_mem, sizeof(t)))) | |
| 28 | + | |
| 29 | +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem, | |
| 30 | + int limit, const char *errormsg); | |
| 31 | + | |
| 32 | +#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) | |
| 34 | +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) | |
| 35 | + | |
| 36 | +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) | |
| 37 | +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) | |
| 38 | +#define luaM_newvector(L,n,t) \ | |
| 39 | + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) | |
| 33 | 40 | |
| 34 | 41 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ |
| 35 | − if (((nelems)+1) > (size)) \ | |
| 36 | − ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) | |
| 42 | + if ((nelems)+1 > (size)) \ | |
| 43 | + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) | |
| 37 | 44 | |
| 38 | 45 | #define luaM_reallocvector(L, v,oldn,n,t) \ |
| 39 | − ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \ | |
| 40 | − cast(lu_mem, n)*cast(lu_mem, sizeof(t))))) | |
| 46 | + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) | |
| 41 | 47 | |
| 42 | 48 | |
| 43 | 49 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lobject.c,v 2.4 2004/07/09 16:01:38 roberto Exp $ | |
| 2 | +** $Id: lobject.c,v 2.7 2004/11/24 19:16:03 roberto Exp $ | |
| 3 | 3 | ** Some generic functions over Lua objects |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -23,7 +23,7 @@ · 17 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | |
| 26 | −const TValue luaO_nilobject = {LUA_TNIL, {NULL}}; | |
| 26 | +const TValue luaO_nilobject = {{NULL}, LUA_TNIL}; | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /* |
| @@ -31,12 +31,21 @@ const TValue luaO_nilobject = {LUA_TNIL, {NULL}}; · 1 unmodified line | ||
| 31 | 31 | ** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm) |
| 32 | 32 | */ |
| 33 | 33 | int luaO_int2fb (unsigned int x) { |
| 34 | − int m = 0; /* mantissa */ | |
| 35 | − while (x >= (1<<3)) { | |
| 34 | + int e = 0; /* expoent */ | |
| 35 | + while (x >= 16) { | |
| 36 | 36 | x = (x+1) >> 1; |
| 37 | − m++; | |
| 37 | + e++; | |
| 38 | 38 | } |
| 39 | − return (m << 3) | cast(int, x); | |
| 39 | + if (x < 8) return x; | |
| 40 | + else return ((e+1) << 3) | (cast(int, x) - 8); | |
| 41 | +} | |
| 42 | + | |
| 43 | + | |
| 44 | +/* converts back */ | |
| 45 | +int luaO_fb2int (int x) { | |
| 46 | + int e = (x >> 3) & 31; | |
| 47 | + if (e == 0) return x; | |
| 48 | + else return ((x & 7)+8) << (e - 1); | |
| 40 | 49 | } |
| 41 | 50 | |
| 42 | 51 | |
| @@ -80,7 +89,7 @@ int luaO_str2d (const char *s, lua_Number *result) { · 37 unmodified lines | ||
| 80 | 89 | char *endptr; |
| 81 | 90 | lua_Number res = lua_str2number(s, &endptr); |
| 82 | 91 | if (endptr == s) return 0; /* no conversion */ |
| 83 | − while (isspace((unsigned char)(*endptr))) endptr++; | |
| 92 | + while (isspace(cast(unsigned char, *endptr))) endptr++; | |
| 84 | 93 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ |
| 85 | 94 | *result = res; |
| 86 | 95 | return 1; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lobject.h,v 2.5 2004/05/31 18:51:50 roberto Exp $ | |
| 2 | +** $Id: lobject.h,v 2.8 2004/12/04 18:10:22 roberto Exp $ | |
| 3 | 3 | ** Type definitions for Lua objects |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -25,6 +25,7 @@ · 19 unmodified lines | ||
| 25 | 25 | */ |
| 26 | 26 | #define LUA_TPROTO (NUM_TAGS+1) |
| 27 | 27 | #define LUA_TUPVAL (NUM_TAGS+2) |
| 28 | +#define LUA_TDEADKEY (NUM_TAGS+3) | |
| 28 | 29 | |
| 29 | 30 | |
| 30 | 31 | /* |
| @@ -64,9 +65,11 @@ typedef union { · 33 unmodified lines | ||
| 64 | 65 | /* |
| 65 | 66 | ** Tagged Values |
| 66 | 67 | */ |
| 68 | + | |
| 69 | +#define TValuefields Value value; int tt | |
| 70 | + | |
| 67 | 71 | typedef struct lua_TValue { |
| 68 | − int tt; | |
| 69 | − Value value; | |
| 72 | + TValuefields; | |
| 70 | 73 | } TValue; |
| 71 | 74 | |
| 72 | 75 | |
| @@ -158,7 +161,7 @@ typedef struct lua_TValue { · 85 unmodified lines | ||
| 158 | 161 | |
| 159 | 162 | #define setobj(L,obj1,obj2) \ |
| 160 | 163 | { const TValue *o2=(obj2); TValue *o1=(obj1); \ |
| 161 | − o1->tt=o2->tt; o1->value = o2->value; \ | |
| 164 | + o1->value = o2->value; o1->tt=o2->tt; \ | |
| 162 | 165 | checkliveness(G(L),o1); } |
| 163 | 166 | |
| 164 | 167 | |
| @@ -308,10 +311,15 @@ typedef union Closure { · 143 unmodified lines | ||
| 308 | 311 | ** Tables |
| 309 | 312 | */ |
| 310 | 313 | |
| 314 | +typedef struct TKey { | |
| 315 | + TValuefields; | |
| 316 | + struct Node *next; /* for chaining */ | |
| 317 | +} TKey; | |
| 318 | + | |
| 319 | + | |
| 311 | 320 | typedef struct Node { |
| 312 | − TValue i_key; | |
| 313 | 321 | TValue i_val; |
| 314 | − struct Node *next; /* for chaining */ | |
| 322 | + TKey i_key; | |
| 315 | 323 | } Node; |
| 316 | 324 | |
| 317 | 325 | |
| @@ -345,7 +353,7 @@ extern const TValue luaO_nilobject; · 27 unmodified lines | ||
| 345 | 353 | |
| 346 | 354 | int luaO_log2 (unsigned int x); |
| 347 | 355 | int luaO_int2fb (unsigned int x); |
| 348 | −#define fb2int(x) (((x) & 7) << ((x) >> 3)) | |
| 356 | +int luaO_fb2int (int x); | |
| 349 | 357 | |
| 350 | 358 | int luaO_rawequalObj (const TValue *t1, const TValue *t2); |
| 351 | 359 | int luaO_str2d (const char *s, lua_Number *result); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lopcodes.c,v 1.28 2004/07/16 13:15:32 roberto Exp $ | |
| 2 | +** $Id: lopcodes.c,v 1.30 2004/12/02 12:59:10 roberto Exp $ | |
| 3 | 3 | ** See Copyright Notice in lua.h |
| 4 | 4 | */ |
| 5 | 5 | |
| @@ -15,7 +15,7 @@ · 9 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | /* ORDER OP */ |
| 17 | 17 | |
| 18 | −const char *const luaP_opnames[NUM_OPCODES] = { | |
| 18 | +const char *const luaP_opnames[NUM_OPCODES+1] = { | |
| 19 | 19 | "MOVE", |
| 20 | 20 | "LOADK", |
| 21 | 21 | "LOADBOOL", |
| @@ -49,10 +49,10 @@ const char *const luaP_opnames[NUM_OPCODES] = { · 27 unmodified lines | ||
| 49 | 49 | "TFORLOOP", |
| 50 | 50 | "TFORPREP", |
| 51 | 51 | "SETLIST", |
| 52 | − "SETLISTO", | |
| 53 | 52 | "CLOSE", |
| 54 | 53 | "CLOSURE", |
| 55 | − "VARARG" | |
| 54 | + "VARARG", | |
| 55 | + NULL | |
| 56 | 56 | }; |
| 57 | 57 | |
| 58 | 58 | |
| @@ -92,8 +92,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 33 unmodified lines | ||
| 92 | 92 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ |
| 93 | 93 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ |
| 94 | 94 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_TFORPREP */ |
| 95 | − ,opmode(0, 0, OpArgU, OpArgN, iABx) /* OP_SETLIST */ | |
| 96 | − ,opmode(0, 0, OpArgU, OpArgN, iABx) /* OP_SETLISTO */ | |
| 95 | + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ | |
| 97 | 96 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ |
| 98 | 97 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ |
| 99 | 98 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lopcodes.h,v 1.111 2004/08/04 20:18:13 roberto Exp $ | |
| 2 | +** $Id: lopcodes.h,v 1.114 2004/12/02 12:59:10 roberto Exp $ | |
| 3 | 3 | ** Opcodes for Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -198,8 +198,7 @@ OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); · 192 unmodified lines | ||
| 198 | 198 | OP_TFORPREP,/* A sBx if type(R(A)) == table then R(A+1):=R(A), R(A):=next; |
| 199 | 199 | pc+=sBx */ |
| 200 | 200 | |
| 201 | −OP_SETLIST,/* A Bx R(A)[Bx-Bx%FPF+i] := R(A+i), 1 <= i <= Bx%FPF+1 */ | |
| 202 | −OP_SETLISTO,/* A Bx */ | |
| 201 | +OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ | |
| 203 | 202 | |
| 204 | 203 | OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ |
| 205 | 204 | OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ |
| @@ -219,11 +218,15 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ · 13 unmodified lines | ||
| 219 | 218 | next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. |
| 220 | 219 | |
| 221 | 220 | (*) In OP_VARARG, if (B == 0) then use actual number of varargs and |
| 222 | − set top (like in OP_CALL). | |
| 221 | + set top (like in OP_CALL with C == 0). | |
| 223 | 222 | |
| 224 | 223 | (*) In OP_RETURN, if (B == 0) then return up to `top' |
| 225 | 224 | |
| 226 | − (*) For comparisons, B specifies what conditions the test should accept. | |
| 225 | + (*) In OP_SETLIST, if (B == 0) then B = `top'; | |
| 226 | + if (C == 0) then next `instruction' is real C | |
| 227 | + | |
| 228 | + (*) For comparisons, A specifies what condition the test should accept | |
| 229 | + (true or false). | |
| 227 | 230 | |
| 228 | 231 | (*) All `skips' (pc++) assume that next instruction is a jump |
| 229 | 232 | ===========================================================================*/ |
| @@ -254,12 +257,11 @@ extern const lu_byte luaP_opmodes[NUM_OPCODES]; · 24 unmodified lines | ||
| 254 | 257 | #define testTMode(m) (luaP_opmodes[m] & (1 << 7)) |
| 255 | 258 | |
| 256 | 259 | |
| 257 | −extern const char *const luaP_opnames[NUM_OPCODES]; /* opcode names */ | |
| 260 | +extern const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ | |
| 258 | 261 | |
| 259 | 262 | |
| 260 | 263 | /* number of list items to accumulate before a SETLIST instruction */ |
| 261 | −/* (must be a power of 2) */ | |
| 262 | −#define LFIELDS_PER_FLUSH 32 | |
| 264 | +#define LFIELDS_PER_FLUSH 50 | |
| 263 | 265 | |
| 264 | 266 | |
| 265 | 267 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lparser.c,v 2.5 2004/05/31 18:51:50 roberto Exp $ | |
| 2 | +** $Id: lparser.c,v 2.10 2004/12/03 20:50:25 roberto Exp $ | |
| 3 | 3 | ** Lua Parser |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -31,7 +31,7 @@ · 25 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | #define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) |
| 33 | 33 | |
| 34 | −#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) luaY_errorlimit(fs,l,m) | |
| 34 | +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) | |
| 35 | 35 | |
| 36 | 36 | #define enterlevel(ls) if (++(ls)->nestlevel > LUA_MAXPARSERLEVEL) \ |
| 37 | 37 | luaX_lexerror(ls, "chunk has too many syntax levels", 0) |
| @@ -90,7 +90,7 @@ static void error_expected (LexState *ls, int token) { · 52 unmodified lines | ||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | −static void luaY_errorlimit (FuncState *fs, int limit, const char *what) { | |
| 93 | +static void errorlimit (FuncState *fs, int limit, const char *what) { | |
| 94 | 94 | const char *msg = (fs->f->lineDefined == 0) ? |
| 95 | 95 | luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : |
| 96 | 96 | luaO_pushfstring(fs->L, "function at line %d has more than %d %s", |
| @@ -133,7 +133,7 @@ static void check_match (LexState *ls, int what, int who, int where) { · 36 unmodified lines | ||
| 133 | 133 | |
| 134 | 134 | static TString *str_checkname (LexState *ls) { |
| 135 | 135 | TString *ts; |
| 136 | − check_condition(ls, (ls->t.token == TK_NAME), "<name> expected"); | |
| 136 | + if (ls->t.token != TK_NAME) error_expected(ls, TK_NAME); | |
| 137 | 137 | ts = ls->t.seminfo.ts; |
| 138 | 138 | next(ls); |
| 139 | 139 | return ts; |
| @@ -157,7 +157,7 @@ static void checkname(LexState *ls, expdesc *e) { · 17 unmodified lines | ||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | −static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |
| 160 | +static int registerlocalvar (LexState *ls, TString *varname) { | |
| 161 | 161 | FuncState *fs = ls->fs; |
| 162 | 162 | Proto *f = fs->f; |
| 163 | 163 | int oldsize = f->sizelocvars; |
| @@ -177,8 +177,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { · 13 unmodified lines | ||
| 177 | 177 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 178 | 178 | FuncState *fs = ls->fs; |
| 179 | 179 | luaY_checklimit(fs, fs->nactvar+n+1, MAXVARS, "local variables"); |
| 180 | − fs->actvar[fs->nactvar+n] = cast(unsigned short, | |
| 181 | − luaI_registerlocalvar(ls, name)); | |
| 180 | + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); | |
| 182 | 181 | } |
| 183 | 182 | |
| 184 | 183 | |
| @@ -413,7 +412,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 228 unmodified lines | ||
| 413 | 412 | /*============================================================*/ |
| 414 | 413 | |
| 415 | 414 | |
| 416 | −static void luaY_field (LexState *ls, expdesc *v) { | |
| 415 | +static void field (LexState *ls, expdesc *v) { | |
| 417 | 416 | /* field -> ['.' | ':'] NAME */ |
| 418 | 417 | FuncState *fs = ls->fs; |
| 419 | 418 | expdesc key; |
| @@ -424,7 +423,7 @@ static void luaY_field (LexState *ls, expdesc *v) { · 4 unmodified lines | ||
| 424 | 423 | } |
| 425 | 424 | |
| 426 | 425 | |
| 427 | −static void luaY_index (LexState *ls, expdesc *v) { | |
| 426 | +static void yindex (LexState *ls, expdesc *v) { | |
| 428 | 427 | /* index -> '[' expr ']' */ |
| 429 | 428 | next(ls); /* skip the '[' */ |
| 430 | 429 | expr(ls, v); |
| @@ -460,7 +459,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) { · 29 unmodified lines | ||
| 460 | 459 | checkname(ls, &key); |
| 461 | 460 | } |
| 462 | 461 | else /* ls->t.token == '[' */ |
| 463 | − luaY_index(ls, &key); | |
| 462 | + yindex(ls, &key); | |
| 464 | 463 | check(ls, '='); |
| 465 | 464 | luaK_exp2RK(fs, &key); |
| 466 | 465 | expr(ls, &val); |
| @@ -475,9 +474,8 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) { · 8 unmodified lines | ||
| 475 | 474 | luaK_exp2nextreg(fs, &cc->v); |
| 476 | 475 | cc->v.k = VVOID; |
| 477 | 476 | if (cc->tostore == LFIELDS_PER_FLUSH) { |
| 478 | − luaK_codeABx(fs, OP_SETLIST, cc->t->info, cc->na-1); /* flush */ | |
| 477 | + luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); /* flush */ | |
| 479 | 478 | cc->tostore = 0; /* no more items pending */ |
| 480 | − fs->freereg = cc->t->info + 1; /* free registers */ | |
| 481 | 479 | } |
| 482 | 480 | } |
| 483 | 481 | |
| @@ -486,15 +484,14 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 2 unmodified lines | ||
| 486 | 484 | if (cc->tostore == 0) return; |
| 487 | 485 | if (hasmultret(cc->v.k)) { |
| 488 | 486 | luaK_setmultret(fs, &cc->v); |
| 489 | − luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1); | |
| 487 | + luaK_setlist(fs, cc->t->info, cc->na, LUA_MULTRET); | |
| 490 | 488 | cc->na--; /* do not count last expression (unknown number of elements) */ |
| 491 | 489 | } |
| 492 | 490 | else { |
| 493 | 491 | if (cc->v.k != VVOID) |
| 494 | 492 | luaK_exp2nextreg(fs, &cc->v); |
| 495 | − luaK_codeABx(fs, OP_SETLIST, cc->t->info, cc->na-1); | |
| 493 | + luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); | |
| 496 | 494 | } |
| 497 | − fs->freereg = cc->t->info + 1; /* free registers */ | |
| 498 | 495 | } |
| 499 | 496 | |
| 500 | 497 | |
| @@ -703,13 +700,13 @@ static void primaryexp (LexState *ls, expdesc *v) { · 202 unmodified lines | ||
| 703 | 700 | for (;;) { |
| 704 | 701 | switch (ls->t.token) { |
| 705 | 702 | case '.': { /* field */ |
| 706 | − luaY_field(ls, v); | |
| 703 | + field(ls, v); | |
| 707 | 704 | break; |
| 708 | 705 | } |
| 709 | 706 | case '[': { /* `[' exp1 `]' */ |
| 710 | 707 | expdesc key; |
| 711 | 708 | luaK_exp2anyreg(fs, v); |
| 712 | − luaY_index(ls, &key); | |
| 709 | + yindex(ls, &key); | |
| 713 | 710 | luaK_indexed(fs, v, &key); |
| 714 | 711 | break; |
| 715 | 712 | } |
| @@ -1213,10 +1210,10 @@ static int funcname (LexState *ls, expdesc *v) { · 497 unmodified lines | ||
| 1213 | 1210 | int needself = 0; |
| 1214 | 1211 | singlevar(ls, v, 1); |
| 1215 | 1212 | while (ls->t.token == '.') |
| 1216 | − luaY_field(ls, v); | |
| 1213 | + field(ls, v); | |
| 1217 | 1214 | if (ls->t.token == ':') { |
| 1218 | 1215 | needself = 1; |
| 1219 | − luaY_field(ls, v); | |
| 1216 | + field(ls, v); | |
| 1220 | 1217 | } |
| 1221 | 1218 | return needself; |
| 1222 | 1219 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstate.c,v 2.14 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: lstate.c,v 2.18 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Global State |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -79,7 +79,7 @@ static void f_luaopen (lua_State *L, void *ud) { · 73 unmodified lines | ||
| 79 | 79 | Udata *u; /* head of udata list */ |
| 80 | 80 | global_State *g = G(L); |
| 81 | 81 | UNUSED(ud); |
| 82 | − u = cast(Udata *, luaM_malloc(L, sizeudata(0))); | |
| 82 | + u = luaM_new(L, Udata); | |
| 83 | 83 | u->uv.len = 0; |
| 84 | 84 | u->uv.metatable = NULL; |
| 85 | 85 | g->firstudata = obj2gco(u); |
| @@ -155,7 +155,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) { · 69 unmodified lines | ||
| 155 | 155 | luaF_close(L1, L1->stack); /* close all upvalues for this thread */ |
| 156 | 156 | lua_assert(L1->openupval == NULL); |
| 157 | 157 | freestack(L, L1); |
| 158 | − luaM_free(L, fromstate(L1), state_size(lua_State)); | |
| 158 | + luaM_freemem(L, fromstate(L1), state_size(lua_State)); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
| @@ -191,8 +191,10 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 29 unmodified lines | ||
| 191 | 191 | g->tmudata = NULL; |
| 192 | 192 | setnilvalue(gkey(g->dummynode)); |
| 193 | 193 | setnilvalue(gval(g->dummynode)); |
| 194 | − g->dummynode->next = NULL; | |
| 194 | + gnext(g->dummynode) = NULL; | |
| 195 | 195 | g->totalbytes = sizeof(LG); |
| 196 | + g->stepmul = STEPMUL; | |
| 197 | + g->incgc = 1; | |
| 196 | 198 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { |
| 197 | 199 | /* memory allocation error: free partial state */ |
| 198 | 200 | close_state(L); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstate.h,v 2.8 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: lstate.h,v 2.9 2004/12/06 17:53:42 roberto Exp $ | |
| 3 | 3 | ** Global State |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -85,6 +85,8 @@ typedef struct global_State { · 79 unmodified lines | ||
| 85 | 85 | lu_mem totalbytes; /* number of bytes currently allocated */ |
| 86 | 86 | lu_mem estimate; /* an estimate of number of bytes actually in use */ |
| 87 | 87 | lu_mem prevestimate; /* previous estimate */ |
| 88 | + int stepmul; /* relative `speed' of the GC */ | |
| 89 | + int incgc; /* 0 if GC is done non-incrementally */ | |
| 88 | 90 | lua_CFunction panic; /* to be called in unprotected errors */ |
| 89 | 91 | TValue _registry; |
| 90 | 92 | struct lua_State *mainthread; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstring.c,v 2.3 2004/08/24 20:12:06 roberto Exp $ | |
| 2 | +** $Id: lstring.c,v 2.5 2004/11/24 19:16:03 roberto Exp $ | |
| 3 | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -49,8 +49,11 @@ void luaS_resize (lua_State *L, int newsize) { · 43 unmodified lines | ||
| 49 | 49 | |
| 50 | 50 | static TString *newlstr (lua_State *L, const char *str, size_t l, |
| 51 | 51 | unsigned int h) { |
| 52 | − TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); | |
| 52 | + TString *ts; | |
| 53 | 53 | stringtable *tb; |
| 54 | + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) | |
| 55 | + luaM_toobig(L); | |
| 56 | + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); | |
| 54 | 57 | ts->tsv.len = l; |
| 55 | 58 | ts->tsv.hash = h; |
| 56 | 59 | ts->tsv.marked = luaC_white(G(L)); |
| @@ -75,7 +78,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { · 18 unmodified lines | ||
| 75 | 78 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
| 76 | 79 | size_t l1; |
| 77 | 80 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
| 78 | − h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1])); | |
| 81 | + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); | |
| 79 | 82 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; |
| 80 | 83 | o != NULL; |
| 81 | 84 | o = o->gch.next) { |
| @@ -92,7 +95,9 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { · 10 unmodified lines | ||
| 92 | 95 | |
| 93 | 96 | Udata *luaS_newudata (lua_State *L, size_t s) { |
| 94 | 97 | Udata *u; |
| 95 | − u = cast(Udata *, luaM_malloc(L, sizeudata(s))); | |
| 98 | + if (s > MAX_SIZET - sizeof(Udata)) | |
| 99 | + luaM_toobig(L); | |
| 100 | + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); | |
| 96 | 101 | u->uv.marked = luaC_white(G(L)); /* is not finalized */ |
| 97 | 102 | u->uv.tt = LUA_TUSERDATA; |
| 98 | 103 | u->uv.len = s; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstring.h,v 1.39 2004/08/24 20:12:06 roberto Exp $ | |
| 2 | +** $Id: lstring.h,v 1.40 2004/11/19 15:52:40 roberto Exp $ | |
| 3 | 3 | ** String table (keep all strings handled by Lua) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -13,10 +13,9 @@ · 7 unmodified lines | ||
| 13 | 13 | #include "lstate.h" |
| 14 | 14 | |
| 15 | 15 | |
| 16 | −#define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ | |
| 17 | − (cast(lu_mem, l)+1)*sizeof(char)) | |
| 16 | +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) | |
| 18 | 17 | |
| 19 | −#define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) | |
| 18 | +#define sizeudata(u) (sizeof(union Udata)+(u)->len) | |
| 20 | 19 | |
| 21 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) |
| 22 | 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltable.c,v 2.5 2004/08/31 17:57:33 roberto Exp $ | |
| 2 | +** $Id: ltable.c,v 2.12 2004/12/04 18:10:22 roberto Exp $ | |
| 3 | 3 | ** Lua tables (hash) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -38,7 +38,7 @@ · 32 unmodified lines | ||
| 38 | 38 | ** max size of array part is 2^MAXBITS |
| 39 | 39 | */ |
| 40 | 40 | #if LUA_BITSINT > 26 |
| 41 | −#define MAXBITS 24 | |
| 41 | +#define MAXBITS 26 | |
| 42 | 42 | #else |
| 43 | 43 | #define MAXBITS (LUA_BITSINT-2) |
| 44 | 44 | #endif |
| @@ -107,11 +107,10 @@ Node *luaH_mainposition (const Table *t, const TValue *key) { · 62 unmodified lines | ||
| 107 | 107 | ** returns the index for `key' if `key' is an appropriate key to live in |
| 108 | 108 | ** the array part of the table, -1 otherwise. |
| 109 | 109 | */ |
| 110 | −static int arrayindex (const TValue *key, lua_Number lim) { | |
| 110 | +static int arrayindex (const TValue *key) { | |
| 111 | 111 | if (ttisnumber(key)) { |
| 112 | 112 | lua_Number n = nvalue(key); |
| 113 | 113 | int k; |
| 114 | − if (n <= 0 || n > lim) return -1; /* out of range? */ | |
| 115 | 114 | lua_number2int(k, n); |
| 116 | 115 | if (cast(lua_Number, k) == nvalue(key)) |
| 117 | 116 | return k; |
| @@ -123,28 +122,35 @@ static int arrayindex (const TValue *key, lua_Number lim) { · 5 unmodified lines | ||
| 123 | 122 | /* |
| 124 | 123 | ** returns the index of a `key' for table traversals. First goes all |
| 125 | 124 | ** elements in the array part, then elements in the hash part. The |
| 126 | −** beginning and end of a traversal are signalled by -1. | |
| 125 | +** beginning of a traversal is signalled by -1. | |
| 127 | 126 | */ |
| 128 | −static int luaH_index (lua_State *L, Table *t, StkId key) { | |
| 127 | +static int findindex (lua_State *L, Table *t, StkId key) { | |
| 129 | 128 | int i; |
| 130 | 129 | if (ttisnil(key)) return -1; /* first iteration */ |
| 131 | − i = arrayindex(key, t->sizearray); | |
| 132 | − if (0 <= i) { /* is `key' inside array part? */ | |
| 130 | + i = arrayindex(key); | |
| 131 | + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ | |
| 133 | 132 | return i-1; /* yes; that's the index (corrected to C) */ |
| 134 | − } | |
| 135 | 133 | else { |
| 136 | − const TValue *v = luaH_get(t, key); | |
| 137 | − if (v == &luaO_nilobject) | |
| 138 | − luaG_runerror(L, "invalid key for `next'"); | |
| 139 | − i = cast(int, (cast(const lu_byte *, v) - | |
| 140 | − cast(const lu_byte *, gval(gnode(t, 0)))) / sizeof(Node)); | |
| 141 | − return i + t->sizearray; /* hash elements are numbered after array ones */ | |
| 134 | + Node *n = luaH_mainposition(t, key); | |
| 135 | + do { /* check whether `key' is somewhere in the chain */ | |
| 136 | + /* key may be dead already, but it is ok to use it in `next' */ | |
| 137 | + if (luaO_rawequalObj(key2tval(n), key) || | |
| 138 | + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && | |
| 139 | + gcvalue(gkey(n)) == gcvalue(key))) { | |
| 140 | + i = n - gnode(t, 0); /* key index in hash table */ | |
| 141 | + /* hash elements are numbered after array ones */ | |
| 142 | + return i + t->sizearray; | |
| 143 | + } | |
| 144 | + else n = gnext(n); | |
| 145 | + } while (n); | |
| 146 | + luaG_runerror(L, "invalid key for `next'"); /* key not found */ | |
| 147 | + return 0; /* to avoid warnings */ | |
| 142 | 148 | } |
| 143 | 149 | } |
| 144 | 150 | |
| 145 | 151 | |
| 146 | 152 | int luaH_next (lua_State *L, Table *t, StkId key) { |
| 147 | − int i = luaH_index(L, t, key); /* find original element */ | |
| 153 | + int i = findindex(L, t, key); /* find original element */ | |
| 148 | 154 | for (i++; i < t->sizearray; i++) { /* try first array part */ |
| 149 | 155 | if (!ttisnil(&t->array[i])) { /* a non-nil value? */ |
| 150 | 156 | setnvalue(key, cast(lua_Number, i+1)); |
| @@ -154,7 +160,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { · 3 unmodified lines | ||
| 154 | 160 | } |
| 155 | 161 | for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ |
| 156 | 162 | if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ |
| 157 | − setobj2s(L, key, gkey(gnode(t, i))); | |
| 163 | + setobj2s(L, key, key2tval(gnode(t, i))); | |
| 158 | 164 | setobj2s(L, key+1, gval(gnode(t, i))); |
| 159 | 165 | return 1; |
| 160 | 166 | } |
| @@ -195,7 +201,6 @@ static void numuse (const Table *t, int *narray, int *nhash) { · 34 unmodified lines | ||
| 195 | 201 | int nums[MAXBITS+1]; |
| 196 | 202 | int i, lg; |
| 197 | 203 | int totaluse = 0; |
| 198 | − lua_Number sizelimit; /* an upper bound for the array size */ | |
| 199 | 204 | /* count elements in array part */ |
| 200 | 205 | for (i=0, lg=0; lg<=MAXBITS; lg++) { /* for each slice [2^(lg-1) to 2^lg) */ |
| 201 | 206 | int ttlg = twoto(lg); /* 2^lg */ |
| @@ -215,14 +220,11 @@ static void numuse (const Table *t, int *narray, int *nhash) { · 13 unmodified lines | ||
| 215 | 220 | *narray = totaluse; /* all previous uses were in array part */ |
| 216 | 221 | /* count elements in hash part */ |
| 217 | 222 | i = sizenode(t); |
| 218 | − /* array part cannot be larger than twice the maximum number of elements */ | |
| 219 | − sizelimit = cast(lua_Number, totaluse + i) * 2; | |
| 220 | − if (sizelimit >= MAXASIZE) sizelimit = MAXASIZE; | |
| 221 | 223 | while (i--) { |
| 222 | 224 | Node *n = &t->node[i]; |
| 223 | 225 | if (!ttisnil(gval(n))) { |
| 224 | − int k = arrayindex(gkey(n), sizelimit); | |
| 225 | − if (k >= 0) { /* is `key' an appropriate array index? */ | |
| 226 | + int k = arrayindex(key2tval(n)); | |
| 227 | + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ | |
| 226 | 228 | nums[luaO_log2(k-1)+1]++; /* count as such */ |
| 227 | 229 | (*narray)++; |
| 228 | 230 | } |
| @@ -251,12 +253,12 @@ static void setnodevector (lua_State *L, Table *t, int lsize) { · 22 unmodified lines | ||
| 251 | 253 | t->node = G(L)->dummynode; /* use common `dummynode' */ |
| 252 | 254 | lua_assert(ttisnil(gkey(t->node))); /* assert invariants: */ |
| 253 | 255 | lua_assert(ttisnil(gval(t->node))); |
| 254 | − lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */ | |
| 256 | + lua_assert(gnext(t->node) == NULL); /* (`dummynode' must be empty) */ | |
| 255 | 257 | } |
| 256 | 258 | else { |
| 257 | 259 | t->node = luaM_newvector(L, size, Node); |
| 258 | 260 | for (i=0; i<size; i++) { |
| 259 | − t->node[i].next = NULL; | |
| 261 | + gnext(&t->node[i]) = NULL; | |
| 260 | 262 | setnilvalue(gkey(gnode(t, i))); |
| 261 | 263 | setnilvalue(gval(gnode(t, i))); |
| 262 | 264 | } |
| @@ -280,7 +282,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 17 unmodified lines | ||
| 280 | 282 | nold = temp; |
| 281 | 283 | setnilvalue(gkey(G(L)->dummynode)); /* restate invariant */ |
| 282 | 284 | setnilvalue(gval(G(L)->dummynode)); |
| 283 | − lua_assert(G(L)->dummynode->next == NULL); | |
| 285 | + lua_assert(gnext(G(L)->dummynode) == NULL); | |
| 284 | 286 | } |
| 285 | 287 | if (nasize > oldasize) /* array part must grow? */ |
| 286 | 288 | setarrayvector(L, t, nasize); |
| @@ -301,7 +303,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 14 unmodified lines | ||
| 301 | 303 | for (i = twoto(oldhsize) - 1; i >= 0; i--) { |
| 302 | 304 | Node *old = nold+i; |
| 303 | 305 | if (!ttisnil(gval(old))) |
| 304 | − setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old)); | |
| 306 | + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); | |
| 305 | 307 | } |
| 306 | 308 | if (oldhsize) |
| 307 | 309 | luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ |
| @@ -341,7 +343,7 @@ void luaH_free (lua_State *L, Table *t) { · 33 unmodified lines | ||
| 341 | 343 | if (t->lsizenode) |
| 342 | 344 | luaM_freearray(L, t->node, sizenode(t), Node); |
| 343 | 345 | luaM_freearray(L, t->array, t->sizearray, TValue); |
| 344 | − luaM_freelem(L, t); | |
| 346 | + luaM_free(L, t); | |
| 345 | 347 | } |
| 346 | 348 | |
| 347 | 349 | |
| @@ -357,24 +359,25 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { · 9 unmodified lines | ||
| 357 | 359 | TValue *val; |
| 358 | 360 | Node *mp = luaH_mainposition(t, key); |
| 359 | 361 | if (!ttisnil(gval(mp))) { /* main position is not free? */ |
| 360 | − Node *othern = luaH_mainposition(t, gkey(mp)); /* `mp' of colliding node */ | |
| 362 | + /* `mp' of colliding node */ | |
| 363 | + Node *othern = luaH_mainposition(t, key2tval(mp)); | |
| 361 | 364 | Node *n = t->firstfree; /* get a free place */ |
| 362 | 365 | if (othern != mp) { /* is colliding node out of its main position? */ |
| 363 | 366 | /* yes; move colliding node into free position */ |
| 364 | − while (othern->next != mp) othern = othern->next; /* find previous */ | |
| 365 | − othern->next = n; /* redo the chain with `n' in place of `mp' */ | |
| 367 | + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ | |
| 368 | + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ | |
| 366 | 369 | *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ |
| 367 | − mp->next = NULL; /* now `mp' is free */ | |
| 370 | + gnext(mp) = NULL; /* now `mp' is free */ | |
| 368 | 371 | setnilvalue(gval(mp)); |
| 369 | 372 | } |
| 370 | 373 | else { /* colliding node is in its own main position */ |
| 371 | 374 | /* new node will go into free position */ |
| 372 | − n->next = mp->next; /* chain new position */ | |
| 373 | − mp->next = n; | |
| 375 | + gnext(n) = gnext(mp); /* chain new position */ | |
| 376 | + gnext(mp) = n; | |
| 374 | 377 | mp = n; |
| 375 | 378 | } |
| 376 | 379 | } |
| 377 | − setobj2t(L, gkey(mp), key); | |
| 380 | + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; | |
| 378 | 381 | luaC_barriert(L, t, key); |
| 379 | 382 | lua_assert(ttisnil(gval(mp))); |
| 380 | 383 | for (;;) { /* correct `firstfree' */ |
| @@ -397,7 +400,8 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { · 16 unmodified lines | ||
| 397 | 400 | ** search function for integers |
| 398 | 401 | */ |
| 399 | 402 | const TValue *luaH_getnum (Table *t, int key) { |
| 400 | − if (1 <= key && key <= t->sizearray) | |
| 403 | + /* (1 <= key && key <= t->sizearray) */ | |
| 404 | + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) | |
| 401 | 405 | return &t->array[key-1]; |
| 402 | 406 | else { |
| 403 | 407 | lua_Number nk = cast(lua_Number, key); |
| @@ -405,7 +409,7 @@ const TValue *luaH_getnum (Table *t, int key) { · 1 unmodified line | ||
| 405 | 409 | do { /* check whether `key' is somewhere in the chain */ |
| 406 | 410 | if (ttisnumber(gkey(n)) && nvalue(gkey(n)) == nk) |
| 407 | 411 | return gval(n); /* that's it */ |
| 408 | − else n = n->next; | |
| 412 | + else n = gnext(n); | |
| 409 | 413 | } while (n); |
| 410 | 414 | return &luaO_nilobject; |
| 411 | 415 | } |
| @@ -420,7 +424,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 8 unmodified lines | ||
| 420 | 424 | do { /* check whether `key' is somewhere in the chain */ |
| 421 | 425 | if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) |
| 422 | 426 | return gval(n); /* that's it */ |
| 423 | − else n = n->next; | |
| 427 | + else n = gnext(n); | |
| 424 | 428 | } while (n); |
| 425 | 429 | return &luaO_nilobject; |
| 426 | 430 | } |
| @@ -443,8 +447,9 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 16 unmodified lines | ||
| 443 | 447 | default: { |
| 444 | 448 | Node *n = luaH_mainposition(t, key); |
| 445 | 449 | do { /* check whether `key' is somewhere in the chain */ |
| 446 | − if (luaO_rawequalObj(gkey(n), key)) return gval(n); /* that's it */ | |
| 447 | − else n = n->next; | |
| 450 | + if (luaO_rawequalObj(key2tval(n), key)) | |
| 451 | + return gval(n); /* that's it */ | |
| 452 | + else n = gnext(n); | |
| 448 | 453 | } while (n); |
| 449 | 454 | return &luaO_nilobject; |
| 450 | 455 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltable.h,v 2.2 2004/03/26 14:02:41 roberto Exp $ | |
| 2 | +** $Id: ltable.h,v 2.3 2004/10/06 18:34:16 roberto Exp $ | |
| 3 | 3 | ** Lua tables (hash) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -13,6 +13,9 @@ · 7 unmodified lines | ||
| 13 | 13 | #define gnode(t,i) (&(t)->node[i]) |
| 14 | 14 | #define gkey(n) (&(n)->i_key) |
| 15 | 15 | #define gval(n) (&(n)->i_val) |
| 16 | +#define gnext(n) ((n)->i_key.next) | |
| 17 | + | |
| 18 | +#define key2tval(n) (cast(const TValue *, gkey(n))) | |
| 16 | 19 | |
| 17 | 20 | |
| 18 | 21 | const TValue *luaH_getnum (Table *t, int key); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.c,v 1.132 2004/08/30 18:35:14 roberto Exp $ | |
| 2 | +** $Id: lua.c,v 1.133 2004/11/18 19:53:49 roberto Exp $ | |
| 3 | 3 | ** Lua stand-alone interpreter |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -127,9 +127,9 @@ static int dostring (lua_State *L, const char *s, const char *name) { · 121 unmodified lines | ||
| 127 | 127 | |
| 128 | 128 | |
| 129 | 129 | static int dolibrary (lua_State *L, const char *name) { |
| 130 | − lua_getfield(L, LUA_GLOBALSINDEX, "_PATH"); | |
| 130 | + luaL_getfield(L, LUA_GLOBALSINDEX, "package.path"); | |
| 131 | 131 | if (!lua_isstring(L, -1)) { |
| 132 | − l_message(progname, "global _PATH must be a string"); | |
| 132 | + l_message(progname, "`package.path' must be a string"); | |
| 133 | 133 | return 1; |
| 134 | 134 | } |
| 135 | 135 | name = luaL_searchpath(L, name, lua_tostring(L, -1)); |
| @@ -295,7 +295,7 @@ static int handle_argv (lua_State *L, char *argv[], int *interactive) { · 159 unmodified lines | ||
| 295 | 295 | print_usage(); |
| 296 | 296 | return 1; |
| 297 | 297 | } |
| 298 | − if (dostring(L, chunk, "=<command line>") != 0) | |
| 298 | + if (dostring(L, chunk, "=(command line)") != 0) | |
| 299 | 299 | return 1; |
| 300 | 300 | break; |
| 301 | 301 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: print.c,v 1.48 2004/09/01 21:22:34 lhf Exp $ | |
| 2 | +** $Id: print.c,v 1.49 2004/11/25 09:31:41 lhf Exp $ | |
| 3 | 3 | ** print bytecodes |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -33,7 +33,7 @@ static void PrintString(const Proto* f, int n) · 27 unmodified lines | ||
| 33 | 33 | case '\r': printf("\\r"); break; |
| 34 | 34 | case '\t': printf("\\t"); break; |
| 35 | 35 | case '\v': printf("\\v"); break; |
| 36 | − default: printf(isprint(*s) ? "%c" : "\\%03d",*s); | |
| 36 | + default: printf(isprint((unsigned char)*s) ? "%c" : "\\%03d",*s); | |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | putchar('"'); |
| @@ -44,15 +44,18 @@ static void PrintConstant(const Proto* f, int i) · 4 unmodified lines | ||
| 44 | 44 | const TValue* o=&f->k[i]; |
| 45 | 45 | switch (ttype(o)) |
| 46 | 46 | { |
| 47 | + case LUA_TNIL: | |
| 48 | + printf("nil"); | |
| 49 | + break; | |
| 50 | + case LUA_TBOOLEAN: | |
| 51 | + printf(bvalue(o) ? "true" : "false"); | |
| 52 | + break; | |
| 47 | 53 | case LUA_TNUMBER: |
| 48 | 54 | printf(LUA_NUMBER_FMT,nvalue(o)); |
| 49 | 55 | break; |
| 50 | 56 | case LUA_TSTRING: |
| 51 | 57 | PrintString(f,i); |
| 52 | 58 | break; |
| 53 | − case LUA_TNIL: | |
| 54 | − printf("nil"); | |
| 55 | − break; | |
| 56 | 59 | default: /* cannot happen */ |
| 57 | 60 | printf("? type=%d",ttype(o)); |
| 58 | 61 | break; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lundump.c,v 1.53 2004/09/01 21:22:34 lhf Exp $ | |
| 2 | +** $Id: lundump.c,v 1.54 2004/11/25 09:31:41 lhf Exp $ | |
| 3 | 3 | ** load pre-compiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -177,15 +177,18 @@ static void LoadConstants (LoadState* S, Proto* f) · 171 unmodified lines | ||
| 177 | 177 | int t=LoadByte(S); |
| 178 | 178 | switch (t) |
| 179 | 179 | { |
| 180 | + case LUA_TNIL: | |
| 181 | + setnilvalue(o); | |
| 182 | + break; | |
| 183 | + case LUA_TBOOLEAN: | |
| 184 | + setbvalue(o,LoadByte(S)); | |
| 185 | + break; | |
| 180 | 186 | case LUA_TNUMBER: |
| 181 | 187 | setnvalue(o,LoadNumber(S)); |
| 182 | 188 | break; |
| 183 | 189 | case LUA_TSTRING: |
| 184 | 190 | setsvalue2n(S->L,o,LoadString(S)); |
| 185 | 191 | break; |
| 186 | − case LUA_TNIL: | |
| 187 | − setnilvalue(o); | |
| 188 | − break; | |
| 189 | 192 | default: |
| 190 | 193 | error(S,"bad constant type (%d)",t); |
| 191 | 194 | break; |
| @@ -243,19 +246,15 @@ static void LoadHeader (LoadState* S) · 51 unmodified lines | ||
| 243 | 246 | lua_Number x,tx=TEST_NUMBER; |
| 244 | 247 | LoadSignature(S); |
| 245 | 248 | version=LoadByte(S); |
| 246 | − if (version>VERSION) | |
| 247 | − error(S,"bad version (read %d.%d; expected at %s %d.%d)", | |
| 248 | − V(version),"most",V(VERSION)); | |
| 249 | − if (version<VERSION0) /* check last major change */ | |
| 250 | − error(S,"bad version (read %d.%d; expected at %s %d.%d)", | |
| 251 | − V(version),"least",V(VERSION0)); | |
| 249 | + if (version!=VERSION) | |
| 250 | + error(S,"bad version (read %d.%d; expected %d.%d)",V(version),V(VERSION)); | |
| 252 | 251 | S->swap=(luaU_endianness()!=LoadByte(S)); /* need to swap bytes? */ |
| 253 | 252 | TestSize(S,sizeof(int),"int"); |
| 254 | 253 | TestSize(S,sizeof(size_t),"size_t"); |
| 255 | 254 | TestSize(S,sizeof(Instruction),"instruction"); |
| 256 | 255 | TestSize(S,sizeof(lua_Number),"number"); |
| 257 | 256 | x=LoadNumber(S); |
| 258 | − if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ | |
| 257 | + if (x!=tx) | |
| 259 | 258 | error(S,"unknown number format"); |
| 260 | 259 | } |
| 261 | 260 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lundump.h,v 1.33 2004/06/09 21:03:53 lhf Exp $ | |
| 2 | +** $Id: lundump.h,v 1.34 2004/11/25 09:31:41 lhf Exp $ | |
| 3 | 3 | ** load pre-compiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -22,12 +22,10 @@ int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int · 16 unmodified lines | ||
| 22 | 22 | /* print one chunk; from print.c */ |
| 23 | 23 | void luaU_print (const Proto* f, int full); |
| 24 | 24 | |
| 25 | −/* definitions for headers of binary files */ | |
| 26 | −#define VERSION 0x51 /* last format change was in 5.1 */ | |
| 27 | −#define VERSION0 0x51 /* last major change was in 5.1 */ | |
| 25 | +/* for header of binary files -- this is Lua 5.1 */ | |
| 26 | +#define VERSION 0x51 | |
| 28 | 27 | |
| 29 | −/* a multiple of PI for testing native format */ | |
| 30 | −/* multiplying by 1E7 gives non-trivial integer values */ | |
| 31 | −#define TEST_NUMBER ((lua_Number)3.14159265358979323846E7) | |
| 28 | +/* for testing native format of lua_Numbers */ | |
| 29 | +#define TEST_NUMBER ((lua_Number)31415926.0) | |
| 32 | 30 | |
| 33 | 31 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lvm.c,v 2.14 2004/09/15 20:39:42 roberto Exp $ | |
| 2 | +** $Id: lvm.c,v 2.18 2004/12/03 20:35:33 roberto Exp $ | |
| 3 | 3 | ** Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -214,7 +214,7 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, · 208 unmodified lines | ||
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
| 217 | −static int luaV_strcmp (const TString *ls, const TString *rs) { | |
| 217 | +static int l_strcmp (const TString *ls, const TString *rs) { | |
| 218 | 218 | const char *l = getstr(ls); |
| 219 | 219 | size_t ll = ls->tsv.len; |
| 220 | 220 | const char *r = getstr(rs); |
| @@ -243,21 +243,21 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 22 unmodified lines | ||
| 243 | 243 | else if (ttisnumber(l)) |
| 244 | 244 | return nvalue(l) < nvalue(r); |
| 245 | 245 | else if (ttisstring(l)) |
| 246 | − return luaV_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | |
| 246 | + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | |
| 247 | 247 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) |
| 248 | 248 | return res; |
| 249 | 249 | return luaG_ordererror(L, l, r); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
| 253 | −static int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |
| 253 | +static int lessequal (lua_State *L, const TValue *l, const TValue *r) { | |
| 254 | 254 | int res; |
| 255 | 255 | if (ttype(l) != ttype(r)) |
| 256 | 256 | return luaG_ordererror(L, l, r); |
| 257 | 257 | else if (ttisnumber(l)) |
| 258 | 258 | return nvalue(l) <= nvalue(r); |
| 259 | 259 | else if (ttisstring(l)) |
| 260 | − return luaV_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | |
| 260 | + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | |
| 261 | 261 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ |
| 262 | 262 | return res; |
| 263 | 263 | else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ |
| @@ -303,15 +303,14 @@ void luaV_concat (lua_State *L, int total, int last) { · 39 unmodified lines | ||
| 303 | 303 | luaG_concaterror(L, top-2, top-1); |
| 304 | 304 | } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
| 305 | 305 | /* at least two string values; get as many as possible */ |
| 306 | − lu_mem tl = cast(lu_mem, tsvalue(top-1)->len) + | |
| 307 | − cast(lu_mem, tsvalue(top-2)->len); | |
| 306 | + size_t tl = tsvalue(top-1)->len; | |
| 308 | 307 | char *buffer; |
| 309 | 308 | int i; |
| 310 | − while (n < total && tostring(L, top-n-1)) { /* collect total length */ | |
| 309 | + /* collect total length */ | |
| 310 | + for (n = 1; n < total && tostring(L, top-n-1); n++) { | |
| 311 | 311 | size_t l = tsvalue(top-n-1)->len; |
| 312 | 312 | if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); |
| 313 | 313 | tl += l; |
| 314 | − n++; | |
| 315 | 314 | } |
| 316 | 315 | buffer = luaZ_openspace(L, &G(L)->buff, tl); |
| 317 | 316 | tl = 0; |
| @@ -462,7 +461,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 144 unmodified lines | ||
| 462 | 461 | } |
| 463 | 462 | case OP_NEWTABLE: { |
| 464 | 463 | int b = GETARG_B(i); |
| 465 | − b = fb2int(b); | |
| 464 | + b = luaO_fb2int(b); | |
| 466 | 465 | sethvalue(L, ra, luaH_new(L, b, GETARG_C(i))); |
| 467 | 466 | L->ci->savedpc = pc; |
| 468 | 467 | luaC_checkGC(L); /***/ |
| @@ -569,7 +568,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 100 unmodified lines | ||
| 569 | 568 | } |
| 570 | 569 | case OP_LE: { |
| 571 | 570 | L->ci->savedpc = pc; |
| 572 | − if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | |
| 571 | + if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ | |
| 573 | 572 | else dojump(L, pc, GETARG_sBx(*pc) + 1); |
| 574 | 573 | base = L->base; |
| 575 | 574 | continue; |
| @@ -710,21 +709,19 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 134 unmodified lines | ||
| 710 | 709 | dojump(L, pc, GETARG_sBx(i)); |
| 711 | 710 | continue; |
| 712 | 711 | } |
| 713 | − case OP_SETLIST: | |
| 714 | − case OP_SETLISTO: { | |
| 715 | − int bc = GETARG_Bx(i); | |
| 716 | − int n, last; | |
| 712 | + case OP_SETLIST: { | |
| 713 | + int n = GETARG_B(i); | |
| 714 | + int c = GETARG_C(i); | |
| 715 | + int last; | |
| 717 | 716 | Table *h; |
| 718 | 717 | runtime_check(L, ttistable(ra)); |
| 719 | 718 | h = hvalue(ra); |
| 720 | − if (GET_OPCODE(i) == OP_SETLIST) | |
| 721 | − n = (bc&(LFIELDS_PER_FLUSH-1)) + 1; | |
| 722 | − else { | |
| 719 | + if (n == 0) { | |
| 723 | 720 | n = L->top - ra - 1; |
| 724 | 721 | L->top = L->ci->top; |
| 725 | 722 | } |
| 726 | − bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ | |
| 727 | − last = bc + n + LUA_FIRSTINDEX - 1; | |
| 723 | + if (c == 0) c = cast(int, *pc++); | |
| 724 | + last = ((c-1)*LFIELDS_PER_FLUSH) + n + LUA_FIRSTINDEX - 1; | |
| 728 | 725 | if (last > h->sizearray) /* needs more space? */ |
| 729 | 726 | luaH_resize(L, h, last, h->lsizenode); /* pre-alloc it at once */ |
| 730 | 727 | for (; n > 0; n--) { |