Showing the changes to src (34 of 46 files). Show all
Unified · Split
| @@ -4,6 +4,9 @@ · 3 unmodified lines | |||
| 4 | 4 | ||
| 5 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= | 5 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= |
| 6 | 6 | ||
| 7 | # Your platform. See PLATS for possible values. | ||
| 8 | PLAT= none | ||
| 9 | |||
| 7 | CC= gcc | 10 | CC= gcc |
| 8 | CFLAGS= -O2 -Wall $(MYCFLAGS) | 11 | CFLAGS= -O2 -Wall $(MYCFLAGS) |
| 9 | AR= ar rcu | 12 | AR= ar rcu |
| @@ -14,12 +17,11 @@ LIBS= -lm $(MYLIBS) · 4 unmodified lines | |||
| 14 | MYCFLAGS= | 17 | MYCFLAGS= |
| 15 | MYLDFLAGS= | 18 | MYLDFLAGS= |
| 16 | MYLIBS= | 19 | MYLIBS= |
| 17 | # enable dynamic loading and line editing in Linux | ||
| 18 | # MYCFLAGS= -DLUA_USE_DLOPEN -DLUA_USE_READLINE | ||
| 19 | # MYLIBS= -Wl,-E -ldl -lreadline -lhistory -lncurses | ||
| 20 | 20 | ||
| 21 | # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= | 21 | # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= |
| 22 | 22 | ||
| 23 | PLATS= ansi bsd generic linux macosx mingw posix | ||
| 24 | |||
| 23 | LUA_A= liblua.a | 25 | LUA_A= liblua.a |
| 24 | CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ | 26 | CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ |
| 25 | lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ | 27 | lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ |
| @@ -37,6 +39,8 @@ ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) · 11 unmodified lines | |||
| 37 | ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) | 39 | ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) |
| 38 | ALL_A= $(LUA_A) | 40 | ALL_A= $(LUA_A) |
| 39 | 41 | ||
| 42 | default: $(PLAT) | ||
| 43 | |||
| 40 | all: $(ALL_T) | 44 | all: $(ALL_T) |
| 41 | 45 | ||
| 42 | o: $(ALL_O) | 46 | o: $(ALL_O) |
| @@ -60,6 +64,7 @@ depend: · 17 unmodified lines | |||
| 60 | @$(CC) $(CFLAGS) -MM l*.c print.c | 64 | @$(CC) $(CFLAGS) -MM l*.c print.c |
| 61 | 65 | ||
| 62 | echo: | 66 | echo: |
| 67 | @echo "PLAT = $(PLAT)" | ||
| 63 | @echo "CC = $(CC)" | 68 | @echo "CC = $(CC)" |
| 64 | @echo "CFLAGS = $(CFLAGS)" | 69 | @echo "CFLAGS = $(CFLAGS)" |
| 65 | @echo "AR = $(AR)" | 70 | @echo "AR = $(AR)" |
| @@ -69,6 +74,34 @@ echo: · 3 unmodified lines | |||
| 69 | @echo "MYLDFLAGS = $(MYLDFLAGS)" | 74 | @echo "MYLDFLAGS = $(MYLDFLAGS)" |
| 70 | @echo "MYLIBS = $(MYLIBS)" | 75 | @echo "MYLIBS = $(MYLIBS)" |
| 71 | 76 | ||
| 77 | # convenience targets for usual platforms | ||
| 78 | |||
| 79 | none: | ||
| 80 | @echo "Please choose a platform: $(PLATS)" | ||
| 81 | |||
| 82 | ansi: | ||
| 83 | $(MAKE) all MYCFLAGS=-DLUA_ANSI | ||
| 84 | |||
| 85 | bsd: | ||
| 86 | $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E" | ||
| 87 | |||
| 88 | generic: | ||
| 89 | $(MAKE) all MYCFLAGS= | ||
| 90 | |||
| 91 | linux: | ||
| 92 | $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" | ||
| 93 | |||
| 94 | macosx: | ||
| 95 | $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX | ||
| 96 | |||
| 97 | mingw: | ||
| 98 | $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \ | ||
| 99 | "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \ | ||
| 100 | "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe | ||
| 101 | |||
| 102 | posix: | ||
| 103 | $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX | ||
| 104 | |||
| 72 | # DO NOT DELETE | 105 | # DO NOT DELETE |
| 73 | 106 | ||
| 74 | lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \ | 107 | lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \ |
| @@ -86,8 +119,8 @@ ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ · 11 unmodified lines | |||
| 86 | ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ | 119 | ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ |
| 87 | lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \ | 120 | lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \ |
| 88 | lstring.h lundump.h lvm.h | 121 | lstring.h lundump.h lvm.h |
| 89 | ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \ | 122 | ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ |
| 90 | ltm.h lzio.h lmem.h lundump.h | 123 | lzio.h lmem.h lundump.h |
| 91 | lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \ | 124 | lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \ |
| 92 | lstate.h ltm.h lzio.h | 125 | lstate.h ltm.h lzio.h |
| 93 | lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ | 126 | lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ |
| @@ -99,10 +132,11 @@ llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ · 5 unmodified lines | |||
| 99 | lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h | 132 | lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h |
| 100 | lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ | 133 | lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ |
| 101 | ltm.h lzio.h lmem.h ldo.h | 134 | ltm.h lzio.h lmem.h ldo.h |
| 102 | loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h | 135 | loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \ |
| 136 | lualib.h | ||
| 103 | lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ | 137 | lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ |
| 104 | ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h | 138 | ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h |
| 105 | lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h | 139 | lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h |
| 106 | loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h | 140 | loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h |
| 107 | lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ | 141 | lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ |
| 108 | lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ | 142 | lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ |
| @@ -122,8 +156,7 @@ luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \ · 13 unmodified lines | |||
| 122 | lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \ | 156 | lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \ |
| 123 | lundump.h | 157 | lundump.h |
| 124 | lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ | 158 | lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ |
| 125 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \ | 159 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h |
| 126 | lundump.h | ||
| 127 | lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ | 160 | lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ |
| 128 | lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h | 161 | lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h |
| 129 | lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \ | 162 | lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.51 2005/10/20 11:35:50 roberto Exp $ | 2 | ** $Id: lapi.c,v 2.53 2006/01/10 12:50:00 roberto Exp $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -40,7 +40,7 @@ const char lua_ident[] = · 34 unmodified lines | |||
| 40 | 40 | ||
| 41 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) | 41 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) |
| 42 | 42 | ||
| 43 | #define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject) | 43 | #define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) |
| 44 | 44 | ||
| 45 | #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} | 45 | #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} |
| 46 | 46 | ||
| @@ -50,7 +50,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 3 unmodified lines | |||
| 50 | if (idx > 0) { | 50 | if (idx > 0) { |
| 51 | TValue *o = L->base + (idx - 1); | 51 | TValue *o = L->base + (idx - 1); |
| 52 | api_check(L, idx <= L->ci->top - L->base); | 52 | api_check(L, idx <= L->ci->top - L->base); |
| 53 | if (o >= L->top) return cast(TValue *, &luaO_nilobject); | 53 | if (o >= L->top) return cast(TValue *, luaO_nilobject); |
| 54 | else return o; | 54 | else return o; |
| 55 | } | 55 | } |
| 56 | else if (idx > LUA_REGISTRYINDEX) { | 56 | else if (idx > LUA_REGISTRYINDEX) { |
| @@ -70,7 +70,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 13 unmodified lines | |||
| 70 | idx = LUA_GLOBALSINDEX - idx; | 70 | idx = LUA_GLOBALSINDEX - idx; |
| 71 | return (idx <= func->c.nupvalues) | 71 | return (idx <= func->c.nupvalues) |
| 72 | ? &func->c.upvalue[idx-1] | 72 | ? &func->c.upvalue[idx-1] |
| 73 | : cast(TValue *, &luaO_nilobject); | 73 | : cast(TValue *, luaO_nilobject); |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| @@ -153,7 +153,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 76 unmodified lines | |||
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | LUA_API int lua_gettop (lua_State *L) { | 155 | LUA_API int lua_gettop (lua_State *L) { |
| 156 | return cast(int, L->top - L->base); | 156 | return cast_int(L->top - L->base); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | 159 | ||
| @@ -234,7 +234,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 74 unmodified lines | |||
| 234 | 234 | ||
| 235 | LUA_API int lua_type (lua_State *L, int idx) { | 235 | LUA_API int lua_type (lua_State *L, int idx) { |
| 236 | StkId o = index2adr(L, idx); | 236 | StkId o = index2adr(L, idx); |
| 237 | return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o); | 237 | return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | 240 | ||
| @@ -272,7 +272,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { · 31 unmodified lines | |||
| 272 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | 272 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { |
| 273 | StkId o1 = index2adr(L, index1); | 273 | StkId o1 = index2adr(L, index1); |
| 274 | StkId o2 = index2adr(L, index2); | 274 | StkId o2 = index2adr(L, index2); |
| 275 | return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0 | 275 | return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 |
| 276 | : luaO_rawequalObj(o1, o2); | 276 | : luaO_rawequalObj(o1, o2); |
| 277 | } | 277 | } |
| 278 | 278 | ||
| @@ -283,8 +283,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { · 4 unmodified lines | |||
| 283 | lua_lock(L); /* may call tag method */ | 283 | lua_lock(L); /* may call tag method */ |
| 284 | o1 = index2adr(L, index1); | 284 | o1 = index2adr(L, index1); |
| 285 | o2 = index2adr(L, index2); | 285 | o2 = index2adr(L, index2); |
| 286 | i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0 | 286 | i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); |
| 287 | : equalobj(L, o1, o2); | ||
| 288 | lua_unlock(L); | 287 | lua_unlock(L); |
| 289 | return i; | 288 | return i; |
| 290 | } | 289 | } |
| @@ -296,7 +295,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 5 unmodified lines | |||
| 296 | lua_lock(L); /* may call tag method */ | 295 | lua_lock(L); /* may call tag method */ |
| 297 | o1 = index2adr(L, index1); | 296 | o1 = index2adr(L, index1); |
| 298 | o2 = index2adr(L, index2); | 297 | o2 = index2adr(L, index2); |
| 299 | i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0 | 298 | i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 |
| 300 | : luaV_lessthan(L, o1, o2); | 299 | : luaV_lessthan(L, o1, o2); |
| 301 | lua_unlock(L); | 300 | lua_unlock(L); |
| 302 | return i; | 301 | return i; |
| @@ -430,7 +429,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { · 127 unmodified lines | |||
| 430 | 429 | ||
| 431 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | 430 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { |
| 432 | lua_lock(L); | 431 | lua_lock(L); |
| 433 | setnvalue(L->top, cast(lua_Number, n)); | 432 | setnvalue(L->top, cast_num(n)); |
| 434 | api_incr_top(L); | 433 | api_incr_top(L); |
| 435 | lua_unlock(L); | 434 | lua_unlock(L); |
| 436 | } | 435 | } |
| @@ -910,11 +909,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 473 unmodified lines | |||
| 910 | } | 909 | } |
| 911 | case LUA_GCCOUNT: { | 910 | case LUA_GCCOUNT: { |
| 912 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 911 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
| 913 | res = cast(int, g->totalbytes >> 10); | 912 | res = cast_int(g->totalbytes >> 10); |
| 914 | break; | 913 | break; |
| 915 | } | 914 | } |
| 916 | case LUA_GCCOUNTB: { | 915 | case LUA_GCCOUNTB: { |
| 917 | res = cast(int, g->totalbytes & 0x3ff); | 916 | res = cast_int(g->totalbytes & 0x3ff); |
| 918 | break; | 917 | break; |
| 919 | } | 918 | } |
| 920 | case LUA_GCSTEP: { | 919 | case LUA_GCSTEP: { |
| @@ -983,7 +982,7 @@ LUA_API void lua_concat (lua_State *L, int n) { · 62 unmodified lines | |||
| 983 | api_checknelems(L, n); | 982 | api_checknelems(L, n); |
| 984 | if (n >= 2) { | 983 | if (n >= 2) { |
| 985 | luaC_checkGC(L); | 984 | luaC_checkGC(L); |
| 986 | luaV_concat(L, n, cast(int, L->top - L->base) - 1); | 985 | luaV_concat(L, n, cast_int(L->top - L->base) - 1); |
| 987 | L->top -= (n-1); | 986 | L->top -= (n-1); |
| 988 | } | 987 | } |
| 989 | else if (n == 0) { /* push empty string */ | 988 | else if (n == 0) { /* push empty string */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp $ | 2 | ** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -226,16 +226,24 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname, · 220 unmodified lines | |||
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | 228 | ||
| 229 | static int libsize (const luaL_Reg *l) { | ||
| 230 | int size = 0; | ||
| 231 | for (; l->name; l++) size++; | ||
| 232 | return size; | ||
| 233 | } | ||
| 234 | |||
| 235 | |||
| 229 | LUALIB_API void luaI_openlib (lua_State *L, const char *libname, | 236 | LUALIB_API void luaI_openlib (lua_State *L, const char *libname, |
| 230 | const luaL_Reg *l, int nup) { | 237 | const luaL_Reg *l, int nup) { |
| 231 | if (libname) { | 238 | if (libname) { |
| 239 | int size = libsize(l); | ||
| 232 | /* check whether lib already exists */ | 240 | /* check whether lib already exists */ |
| 233 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED"); | 241 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size); |
| 234 | lua_getfield(L, -1, libname); /* get _LOADED[libname] */ | 242 | lua_getfield(L, -1, libname); /* get _LOADED[libname] */ |
| 235 | if (!lua_istable(L, -1)) { /* not found? */ | 243 | if (!lua_istable(L, -1)) { /* not found? */ |
| 236 | lua_pop(L, 1); /* remove previous result */ | 244 | lua_pop(L, 1); /* remove previous result */ |
| 237 | /* try global variable (and create one if it does not exist) */ | 245 | /* try global variable (and create one if it does not exist) */ |
| 238 | if (luaL_findtable(L, LUA_GLOBALSINDEX, libname) != NULL) | 246 | if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) |
| 239 | luaL_error(L, "name conflict for module " LUA_QS, libname); | 247 | luaL_error(L, "name conflict for module " LUA_QS, libname); |
| 240 | lua_pushvalue(L, -1); | 248 | lua_pushvalue(L, -1); |
| 241 | lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ | 249 | lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ |
| @@ -331,7 +339,7 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, · 89 unmodified lines | |||
| 331 | 339 | ||
| 332 | 340 | ||
| 333 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, | 341 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
| 334 | const char *fname) { | 342 | const char *fname, int szhint) { |
| 335 | const char *e; | 343 | const char *e; |
| 336 | lua_pushvalue(L, idx); | 344 | lua_pushvalue(L, idx); |
| 337 | do { | 345 | do { |
| @@ -341,7 +349,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, · 3 unmodified lines | |||
| 341 | lua_rawget(L, -2); | 349 | lua_rawget(L, -2); |
| 342 | if (lua_isnil(L, -1)) { /* no such field? */ | 350 | if (lua_isnil(L, -1)) { /* no such field? */ |
| 343 | lua_pop(L, 1); /* remove this nil */ | 351 | lua_pop(L, 1); /* remove this nil */ |
| 344 | lua_newtable(L); /* create a new table for field */ | 352 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ |
| 345 | lua_pushlstring(L, fname, e - fname); | 353 | lua_pushlstring(L, fname, e - fname); |
| 346 | lua_pushvalue(L, -2); | 354 | lua_pushvalue(L, -2); |
| 347 | lua_settable(L, -4); /* set new table into field */ | 355 | lua_settable(L, -4); /* set new table into field */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.86 2005/10/21 13:47:42 roberto Exp $ | 2 | ** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -86,7 +86,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, · 80 unmodified lines | |||
| 86 | const char *r); | 86 | const char *r); |
| 87 | 87 | ||
| 88 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, | 88 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, |
| 89 | const char *fname); | 89 | const char *fname, int szhint); |
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | 92 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.186 2005/10/21 13:47:42 roberto Exp $ | 2 | ** $Id: lbaselib.c,v 1.188 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -201,7 +201,7 @@ static int luaB_collectgarbage (lua_State *L) { · 195 unmodified lines | |||
| 201 | switch (optsnum[o]) { | 201 | switch (optsnum[o]) { |
| 202 | case LUA_GCCOUNT: { | 202 | case LUA_GCCOUNT: { |
| 203 | int b = lua_gc(L, LUA_GCCOUNTB, 0); | 203 | int b = lua_gc(L, LUA_GCCOUNTB, 0); |
| 204 | lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000); | 204 | lua_pushnumber(L, ((lua_Number)res*1024 + b)/1024); |
| 205 | return 1; | 205 | return 1; |
| 206 | } | 206 | } |
| 207 | case LUA_GCSTEP: { | 207 | case LUA_GCSTEP: { |
| @@ -625,7 +625,7 @@ static void base_open (lua_State *L) { · 417 unmodified lines | |||
| 625 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); | 625 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); |
| 626 | auxopen(L, "pairs", luaB_pairs, luaB_next); | 626 | auxopen(L, "pairs", luaB_pairs, luaB_next); |
| 627 | /* `newproxy' needs a weaktable as upvalue */ | 627 | /* `newproxy' needs a weaktable as upvalue */ |
| 628 | lua_newtable(L); /* new table `w' */ | 628 | lua_createtable(L, 0, 1); /* new table `w' */ |
| 629 | lua_pushvalue(L, -1); /* `w' will be its own metatable */ | 629 | lua_pushvalue(L, -1); /* `w' will be its own metatable */ |
| 630 | lua_setmetatable(L, -2); | 630 | lua_setmetatable(L, -2); |
| 631 | lua_pushliteral(L, "kv"); | 631 | lua_pushliteral(L, "kv"); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.22 2005/11/16 11:55:27 roberto Exp $ | 2 | ** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -196,7 +196,7 @@ void luaK_checkstack (FuncState *fs, int n) { · 190 unmodified lines | |||
| 196 | if (newstack > fs->f->maxstacksize) { | 196 | if (newstack > fs->f->maxstacksize) { |
| 197 | if (newstack >= MAXSTACK) | 197 | if (newstack >= MAXSTACK) |
| 198 | luaX_syntaxerror(fs->ls, "function or expression too complex"); | 198 | luaX_syntaxerror(fs->ls, "function or expression too complex"); |
| 199 | fs->f->maxstacksize = cast(lu_byte, newstack); | 199 | fs->f->maxstacksize = cast_byte(newstack); |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| 202 | 202 | ||
| @@ -227,11 +227,11 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { · 24 unmodified lines | |||
| 227 | Proto *f = fs->f; | 227 | Proto *f = fs->f; |
| 228 | int oldsize = f->sizek; | 228 | int oldsize = f->sizek; |
| 229 | if (ttisnumber(idx)) { | 229 | if (ttisnumber(idx)) { |
| 230 | lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v)); | 230 | lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); |
| 231 | return cast(int, nvalue(idx)); | 231 | return cast_int(nvalue(idx)); |
| 232 | } | 232 | } |
| 233 | else { /* constant not found; create a new entry */ | 233 | else { /* constant not found; create a new entry */ |
| 234 | setnvalue(idx, cast(lua_Number, fs->nk)); | 234 | setnvalue(idx, cast_num(fs->nk)); |
| 235 | luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, | 235 | luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, |
| 236 | MAXARG_Bx, "constant table overflow"); | 236 | MAXARG_Bx, "constant table overflow"); |
| 237 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); | 237 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
| @@ -647,7 +647,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { · 409 unmodified lines | |||
| 647 | case OP_LEN: return 0; /* no constant folding for 'len' */ | 647 | case OP_LEN: return 0; /* no constant folding for 'len' */ |
| 648 | default: lua_assert(0); r = 0; break; | 648 | default: lua_assert(0); r = 0; break; |
| 649 | } | 649 | } |
| 650 | if (r != r) return 0; /* do not attempt to produce NaN */ | 650 | if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ |
| 651 | e1->u.nval = r; | 651 | e1->u.nval = r; |
| 652 | return 1; | 652 | return 1; |
| 653 | } | 653 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.103 2005/11/01 16:08:32 roberto Exp $ | 2 | ** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -116,7 +116,7 @@ static int db_getinfo (lua_State *L) { · 110 unmodified lines | |||
| 116 | return luaL_argerror(L, arg+1, "function or level expected"); | 116 | return luaL_argerror(L, arg+1, "function or level expected"); |
| 117 | if (!lua_getinfo(L1, options, &ar)) | 117 | if (!lua_getinfo(L1, options, &ar)) |
| 118 | return luaL_argerror(L, arg+2, "invalid option"); | 118 | return luaL_argerror(L, arg+2, "invalid option"); |
| 119 | lua_newtable(L); | 119 | lua_createtable(L, 0, 2); |
| 120 | if (strchr(options, 'S')) { | 120 | if (strchr(options, 'S')) { |
| 121 | settabss(L, "source", ar.source); | 121 | settabss(L, "source", ar.source); |
| 122 | settabss(L, "short_src", ar.short_src); | 122 | settabss(L, "short_src", ar.short_src); |
| @@ -246,7 +246,7 @@ static void gethooktable (lua_State *L) { · 123 unmodified lines | |||
| 246 | lua_rawget(L, LUA_REGISTRYINDEX); | 246 | lua_rawget(L, LUA_REGISTRYINDEX); |
| 247 | if (!lua_istable(L, -1)) { | 247 | if (!lua_istable(L, -1)) { |
| 248 | lua_pop(L, 1); | 248 | lua_pop(L, 1); |
| 249 | lua_newtable(L); | 249 | lua_createtable(L, 0, 1); |
| 250 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); | 250 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); |
| 251 | lua_pushvalue(L, -2); | 251 | lua_pushvalue(L, -2); |
| 252 | lua_rawset(L, LUA_REGISTRYINDEX); | 252 | lua_rawset(L, LUA_REGISTRYINDEX); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp $ | 2 | ** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -61,7 +61,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { · 55 unmodified lines | |||
| 61 | L->hook = func; | 61 | L->hook = func; |
| 62 | L->basehookcount = count; | 62 | L->basehookcount = count; |
| 63 | resethookcount(L); | 63 | resethookcount(L); |
| 64 | L->hookmask = cast(lu_byte, mask); | 64 | L->hookmask = cast_byte(mask); |
| 65 | return 1; | 65 | return 1; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| @@ -92,7 +92,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 24 unmodified lines | |||
| 92 | } | 92 | } |
| 93 | if (level == 0 && ci > L->base_ci) { /* level found? */ | 93 | if (level == 0 && ci > L->base_ci) { /* level found? */ |
| 94 | status = 1; | 94 | status = 1; |
| 95 | ar->i_ci = cast(int, ci - L->base_ci); | 95 | ar->i_ci = cast_int(ci - L->base_ci); |
| 96 | } | 96 | } |
| 97 | else if (level < 0) { /* level is of a lost tail call? */ | 97 | else if (level < 0) { /* level is of a lost tail call? */ |
| 98 | status = 1; | 98 | status = 1; |
| @@ -550,7 +550,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 451 unmodified lines | |||
| 550 | const char *name = NULL; | 550 | const char *name = NULL; |
| 551 | const char *t = luaT_typenames[ttype(o)]; | 551 | const char *t = luaT_typenames[ttype(o)]; |
| 552 | const char *kind = (isinstack(L->ci, o)) ? | 552 | const char *kind = (isinstack(L->ci, o)) ? |
| 553 | getobjname(L, L->ci, cast(int, o - L->base), &name) : | 553 | getobjname(L, L->ci, cast_int(o - L->base), &name) : |
| 554 | NULL; | 554 | NULL; |
| 555 | if (kind) | 555 | if (kind) |
| 556 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", | 556 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp $ | 2 | ** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -71,7 +71,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 65 unmodified lines | |||
| 71 | static void restore_stack_limit (lua_State *L) { | 71 | static void restore_stack_limit (lua_State *L) { |
| 72 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); | 72 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); |
| 73 | if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ | 73 | if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ |
| 74 | int inuse = cast(int, L->ci - L->base_ci); | 74 | int inuse = cast_int(L->ci - L->base_ci); |
| 75 | if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ | 75 | if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ |
| 76 | luaD_reallocCI(L, LUAI_MAXCALLS); | 76 | luaD_reallocCI(L, LUAI_MAXCALLS); |
| 77 | } | 77 | } |
| @@ -97,7 +97,7 @@ void luaD_throw (lua_State *L, int errcode) { · 19 unmodified lines | |||
| 97 | LUAI_THROW(L, L->errorJmp); | 97 | LUAI_THROW(L, L->errorJmp); |
| 98 | } | 98 | } |
| 99 | else { | 99 | else { |
| 100 | L->status = cast(lu_byte, errcode); | 100 | L->status = cast_byte(errcode); |
| 101 | if (G(L)->panic) { | 101 | if (G(L)->panic) { |
| 102 | resetstack(L, errcode); | 102 | resetstack(L, errcode); |
| 103 | lua_unlock(L); | 103 | lua_unlock(L); |
| @@ -189,7 +189,7 @@ void luaD_callhook (lua_State *L, int event, int line) { · 85 unmodified lines | |||
| 189 | if (event == LUA_HOOKTAILRET) | 189 | if (event == LUA_HOOKTAILRET) |
| 190 | ar.i_ci = 0; /* tail call; no debug information about it */ | 190 | ar.i_ci = 0; /* tail call; no debug information about it */ |
| 191 | else | 191 | else |
| 192 | ar.i_ci = cast(int, L->ci - L->base_ci); | 192 | ar.i_ci = cast_int(L->ci - L->base_ci); |
| 193 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 193 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
| 194 | L->ci->top = L->top + LUA_MINSTACK; | 194 | L->ci->top = L->top + LUA_MINSTACK; |
| 195 | lua_assert(L->ci->top <= L->stack_last); | 195 | lua_assert(L->ci->top <= L->stack_last); |
| @@ -221,8 +221,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { · 25 unmodified lines | |||
| 221 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ | 221 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
| 222 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); | 222 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); |
| 223 | /* store counter in field `n' */ | 223 | /* store counter in field `n' */ |
| 224 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), | 224 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); |
| 225 | cast(lua_Number, nvar)); | ||
| 226 | } | 225 | } |
| 227 | #endif | 226 | #endif |
| 228 | /* move fixed parameters to final position */ | 227 | /* move fixed parameters to final position */ |
| @@ -282,7 +281,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 53 unmodified lines | |||
| 282 | L->top = base + p->numparams; | 281 | L->top = base + p->numparams; |
| 283 | } | 282 | } |
| 284 | else { /* vararg function */ | 283 | else { /* vararg function */ |
| 285 | int nargs = cast(int, L->top - func) - 1; | 284 | int nargs = cast_int(L->top - func) - 1; |
| 286 | base = adjust_varargs(L, p, nargs); | 285 | base = adjust_varargs(L, p, nargs); |
| 287 | func = restorestack(L, funcr); /* previous call may change the stack */ | 286 | func = restorestack(L, funcr); /* previous call may change the stack */ |
| 288 | } | 287 | } |
| @@ -401,7 +400,7 @@ static void resume (lua_State *L, void *ud) { · 112 unmodified lines | |||
| 401 | L->base = L->ci->base; | 400 | L->base = L->ci->base; |
| 402 | } | 401 | } |
| 403 | L->status = 0; | 402 | L->status = 0; |
| 404 | luaV_execute(L, cast(int, L->ci - L->base_ci)); | 403 | luaV_execute(L, cast_int(L->ci - L->base_ci)); |
| 405 | } | 404 | } |
| 406 | 405 | ||
| 407 | 406 | ||
| @@ -427,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 19 unmodified lines | |||
| 427 | lua_assert(L->errfunc == 0 && L->nCcalls == 0); | 426 | lua_assert(L->errfunc == 0 && L->nCcalls == 0); |
| 428 | status = luaD_rawrunprotected(L, resume, L->top - nargs); | 427 | status = luaD_rawrunprotected(L, resume, L->top - nargs); |
| 429 | if (status != 0) { /* error? */ | 428 | if (status != 0) { /* error? */ |
| 430 | L->status = cast(lu_byte, status); /* mark thread as `dead' */ | 429 | L->status = cast_byte(status); /* mark thread as `dead' */ |
| 431 | luaD_seterrorobj(L, status, L->top); | 430 | luaD_seterrorobj(L, status, L->top); |
| 432 | L->ci->top = L->top; | 431 | L->ci->top = L->top; |
| 433 | } | 432 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp $ | 2 | ** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -25,7 +25,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { · 19 unmodified lines | |||
| 25 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); | 25 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); |
| 26 | c->c.isC = 1; | 26 | c->c.isC = 1; |
| 27 | c->c.env = e; | 27 | c->c.env = e; |
| 28 | c->c.nupvalues = cast(lu_byte, nelems); | 28 | c->c.nupvalues = cast_byte(nelems); |
| 29 | return c; | 29 | return c; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -35,7 +35,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { · 3 unmodified lines | |||
| 35 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); | 35 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); |
| 36 | c->l.isC = 0; | 36 | c->l.isC = 0; |
| 37 | c->l.env = e; | 37 | c->l.env = e; |
| 38 | c->l.nupvalues = cast(lu_byte, nelems); | 38 | c->l.nupvalues = cast_byte(nelems); |
| 39 | while (nelems--) c->l.upvals[nelems] = NULL; | 39 | while (nelems--) c->l.upvals[nelems] = NULL; |
| 40 | return c; | 40 | return c; |
| 41 | } | 41 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.36 2005/08/24 17:06:36 roberto Exp $ | 2 | ** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -29,11 +29,10 @@ · 23 unmodified lines | |||
| 29 | #define GCFINALIZECOST 100 | 29 | #define GCFINALIZECOST 100 |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | #define maskmarks \ | 32 | #define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) |
| 33 | cast(lu_byte, ~(bitmask(BLACKBIT)|WHITEBITS)) | ||
| 34 | 33 | ||
| 35 | #define makewhite(g,x) \ | 34 | #define makewhite(g,x) \ |
| 36 | ((x)->gch.marked = ((x)->gch.marked & maskmarks) | luaC_white(g)) | 35 | ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) |
| 37 | 36 | ||
| 38 | #define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) | 37 | #define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) |
| 39 | #define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) | 38 | #define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) |
| @@ -169,8 +168,8 @@ static int traversetable (global_State *g, Table *h) { · 129 unmodified lines | |||
| 169 | weakvalue = (strchr(svalue(mode), 'v') != NULL); | 168 | weakvalue = (strchr(svalue(mode), 'v') != NULL); |
| 170 | if (weakkey || weakvalue) { /* is really weak? */ | 169 | if (weakkey || weakvalue) { /* is really weak? */ |
| 171 | h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ | 170 | h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ |
| 172 | h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) | | 171 | h->marked |= cast_byte((weakkey << KEYWEAKBIT) | |
| 173 | (weakvalue << VALUEWEAKBIT)); | 172 | (weakvalue << VALUEWEAKBIT)); |
| 174 | h->gclist = g->weak; /* must be cleared after GC, ... */ | 173 | h->gclist = g->weak; /* must be cleared after GC, ... */ |
| 175 | g->weak = obj2gco(h); /* ... so put in the appropriate list */ | 174 | g->weak = obj2gco(h); /* ... so put in the appropriate list */ |
| 176 | } | 175 | } |
| @@ -240,8 +239,8 @@ static void traverseclosure (global_State *g, Closure *cl) { · 63 unmodified lines | |||
| 240 | 239 | ||
| 241 | 240 | ||
| 242 | static void checkstacksizes (lua_State *L, StkId max) { | 241 | static void checkstacksizes (lua_State *L, StkId max) { |
| 243 | int ci_used = cast(int, L->ci - L->base_ci); /* number of `ci' in use */ | 242 | int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ |
| 244 | int s_used = cast(int, max - L->stack); /* part of stack in use */ | 243 | int s_used = cast_int(max - L->stack); /* part of stack in use */ |
| 245 | if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ | 244 | if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ |
| 246 | return; /* do not touch the stacks */ | 245 | return; /* do not touch the stacks */ |
| 247 | if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) | 246 | if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) |
| @@ -544,7 +543,7 @@ static void atomic (lua_State *L) { · 296 unmodified lines | |||
| 544 | propagateall(g); /* remark, to propagate `preserveness' */ | 543 | propagateall(g); /* remark, to propagate `preserveness' */ |
| 545 | cleartable(g->weak); /* remove collected objects from weak tables */ | 544 | cleartable(g->weak); /* remove collected objects from weak tables */ |
| 546 | /* flip current white */ | 545 | /* flip current white */ |
| 547 | g->currentwhite = cast(lu_byte, otherwhite(g)); | 546 | g->currentwhite = cast_byte(otherwhite(g)); |
| 548 | g->sweepstrgc = 0; | 547 | g->sweepstrgc = 0; |
| 549 | g->sweepgc = &g->rootgc; | 548 | g->sweepgc = &g->rootgc; |
| 550 | g->gcstate = GCSsweepstring; | 549 | g->gcstate = GCSsweepstring; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: linit.c,v 1.13 2005/08/26 17:36:32 roberto Exp $ | 2 | ** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Initialization of libraries for lua.c | 3 | ** Initialization of libraries for lua.c |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -16,13 +16,13 @@ · 10 unmodified lines | |||
| 16 | 16 | ||
| 17 | static const luaL_Reg lualibs[] = { | 17 | static const luaL_Reg lualibs[] = { |
| 18 | {"", luaopen_base}, | 18 | {"", luaopen_base}, |
| 19 | {LUA_LOADLIBNAME, luaopen_package}, | ||
| 19 | {LUA_TABLIBNAME, luaopen_table}, | 20 | {LUA_TABLIBNAME, luaopen_table}, |
| 20 | {LUA_IOLIBNAME, luaopen_io}, | 21 | {LUA_IOLIBNAME, luaopen_io}, |
| 21 | {LUA_OSLIBNAME, luaopen_os}, | 22 | {LUA_OSLIBNAME, luaopen_os}, |
| 22 | {LUA_STRLIBNAME, luaopen_string}, | 23 | {LUA_STRLIBNAME, luaopen_string}, |
| 23 | {LUA_MATHLIBNAME, luaopen_math}, | 24 | {LUA_MATHLIBNAME, luaopen_math}, |
| 24 | {LUA_DBLIBNAME, luaopen_debug}, | 25 | {LUA_DBLIBNAME, luaopen_debug}, |
| 25 | {LUA_LOADLIBNAME, luaopen_package}, | ||
| 26 | {NULL, NULL} | 26 | {NULL, NULL} |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.69 2005/10/19 13:05:11 roberto Exp $ | 2 | ** $Id: liolib.c,v 2.70 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -507,8 +507,8 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { · 501 unmodified lines | |||
| 507 | 507 | ||
| 508 | LUALIB_API int luaopen_io (lua_State *L) { | 508 | LUALIB_API int luaopen_io (lua_State *L) { |
| 509 | createmeta(L); | 509 | createmeta(L); |
| 510 | /* create new (private) environment */ | 510 | /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ |
| 511 | lua_newtable(L); | 511 | lua_createtable(L, 2, 1); |
| 512 | lua_replace(L, LUA_ENVIRONINDEX); | 512 | lua_replace(L, LUA_ENVIRONINDEX); |
| 513 | /* open library */ | 513 | /* open library */ |
| 514 | luaL_register(L, LUA_IOLIBNAME, iolib); | 514 | luaL_register(L, LUA_IOLIBNAME, iolib); |
| @@ -518,7 +518,7 @@ LUALIB_API int luaopen_io (lua_State *L) { · 3 unmodified lines | |||
| 518 | createstdfile(L, stderr, 0, "stderr"); | 518 | createstdfile(L, stderr, 0, "stderr"); |
| 519 | /* create environment for 'popen' */ | 519 | /* create environment for 'popen' */ |
| 520 | lua_getfield(L, -1, "popen"); | 520 | lua_getfield(L, -1, "popen"); |
| 521 | lua_newtable(L); | 521 | lua_createtable(L, 0, 1); |
| 522 | lua_pushcfunction(L, io_pclose); | 522 | lua_pushcfunction(L, io_pclose); |
| 523 | lua_setfield(L, -2, "__close"); | 523 | lua_setfield(L, -2, "__close"); |
| 524 | lua_setfenv(L, -2); | 524 | lua_setfenv(L, -2); |
| @@ -1,11 +1,12 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp $ | 2 | ** $Id: llex.c,v 2.17 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | #include <ctype.h> | 8 | #include <ctype.h> |
| 9 | #include <locale.h> | ||
| 9 | #include <string.h> | 10 | #include <string.h> |
| 10 | 11 | ||
| 11 | #define llex_c | 12 | #define llex_c |
| @@ -65,7 +66,7 @@ void luaX_init (lua_State *L) { · 53 unmodified lines | |||
| 65 | TString *ts = luaS_new(L, luaX_tokens[i]); | 66 | TString *ts = luaS_new(L, luaX_tokens[i]); |
| 66 | luaS_fix(ts); /* reserved words are never collected */ | 67 | luaS_fix(ts); /* reserved words are never collected */ |
| 67 | lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN); | 68 | lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN); |
| 68 | ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */ | 69 | ts->tsv.reserved = cast_byte(i+1); /* reserved word */ |
| 69 | } | 70 | } |
| 70 | } | 71 | } |
| 71 | 72 | ||
| @@ -134,6 +135,7 @@ static void inclinenumber (LexState *ls) { · 62 unmodified lines | |||
| 134 | 135 | ||
| 135 | 136 | ||
| 136 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { | 137 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { |
| 138 | ls->decpoint = '.'; | ||
| 137 | ls->L = L; | 139 | ls->L = L; |
| 138 | ls->lookahead.token = TK_EOS; /* no look-ahead token */ | 140 | ls->lookahead.token = TK_EOS; /* no look-ahead token */ |
| 139 | ls->z = z; | 141 | ls->z = z; |
| @@ -163,6 +165,27 @@ static int check_next (LexState *ls, const char *set) { · 23 unmodified lines | |||
| 163 | } | 165 | } |
| 164 | 166 | ||
| 165 | 167 | ||
| 168 | static void buffreplace (LexState *ls, char from, char to) { | ||
| 169 | int n = luaZ_bufflen(ls->buff); | ||
| 170 | char *p = luaZ_buffer(ls->buff); | ||
| 171 | while (n--) | ||
| 172 | if (p[n] == from) p[n] = to; | ||
| 173 | } | ||
| 174 | |||
| 175 | |||
| 176 | static void trydecpoint (LexState *ls, SemInfo *seminfo) { | ||
| 177 | /* format error: try to update decimal point separator */ | ||
| 178 | struct lconv *cv = localeconv(); | ||
| 179 | char old = ls->decpoint; | ||
| 180 | ls->decpoint = (cv ? cv->decimal_point[0] : '.'); | ||
| 181 | buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ | ||
| 182 | if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { | ||
| 183 | /* format error with correct decimal point: no more options */ | ||
| 184 | buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ | ||
| 185 | luaX_lexerror(ls, "malformed number", TK_NUMBER); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | |||
| 166 | 189 | ||
| 167 | /* LUA_NUMBER */ | 190 | /* LUA_NUMBER */ |
| 168 | static void read_numeral (LexState *ls, SemInfo *seminfo) { | 191 | static void read_numeral (LexState *ls, SemInfo *seminfo) { |
| @@ -177,8 +200,9 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 8 unmodified lines | |||
| 177 | } | 200 | } |
| 178 | } | 201 | } |
| 179 | save(ls, '\0'); | 202 | save(ls, '\0'); |
| 180 | if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) | 203 | buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ |
| 181 | luaX_lexerror(ls, "malformed number", TK_NUMBER); | 204 | if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ |
| 205 | trydecpoint(ls, seminfo); /* try to update decimal point separator */ | ||
| 182 | } | 206 | } |
| 183 | 207 | ||
| 184 | 208 | ||
| @@ -306,7 +330,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 121 unmodified lines | |||
| 306 | } | 330 | } |
| 307 | 331 | ||
| 308 | 332 | ||
| 309 | int luaX_lex (LexState *ls, SemInfo *seminfo) { | 333 | static int llex (LexState *ls, SemInfo *seminfo) { |
| 310 | luaZ_resetbuffer(ls->buff); | 334 | luaZ_resetbuffer(ls->buff); |
| 311 | for (;;) { | 335 | for (;;) { |
| 312 | switch (ls->current) { | 336 | switch (ls->current) { |
| @@ -419,4 +443,20 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 106 unmodified lines | |||
| 419 | } | 443 | } |
| 420 | } | 444 | } |
| 421 | 445 | ||
| 422 | #undef next | 446 | |
| 447 | void luaX_next (LexState *ls) { | ||
| 448 | ls->lastline = ls->linenumber; | ||
| 449 | if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ | ||
| 450 | ls->t = ls->lookahead; /* use this one */ | ||
| 451 | ls->lookahead.token = TK_EOS; /* and discharge it */ | ||
| 452 | } | ||
| 453 | else | ||
| 454 | ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ | ||
| 455 | } | ||
| 456 | |||
| 457 | |||
| 458 | void luaX_lookahead (LexState *ls) { | ||
| 459 | lua_assert(ls->lookahead.token == TK_EOS); | ||
| 460 | ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); | ||
| 461 | } | ||
| 462 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.55 2005/06/06 13:30:25 roberto Exp $ | 2 | ** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -63,6 +63,7 @@ typedef struct LexState { · 57 unmodified lines | |||
| 63 | ZIO *z; /* input stream */ | 63 | ZIO *z; /* input stream */ |
| 64 | Mbuffer *buff; /* buffer for tokens */ | 64 | Mbuffer *buff; /* buffer for tokens */ |
| 65 | TString *source; /* current source name */ | 65 | TString *source; /* current source name */ |
| 66 | char decpoint; /* locale decimal point */ | ||
| 66 | } LexState; | 67 | } LexState; |
| 67 | 68 | ||
| 68 | 69 | ||
| @@ -70,7 +71,8 @@ LUAI_FUNC void luaX_init (lua_State *L); · 1 unmodified line | |||
| 70 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, | 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, |
| 71 | TString *source); | 72 | TString *source); |
| 72 | LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l); | 73 | LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l); |
| 73 | LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo); | 74 | LUAI_FUNC void luaX_next (LexState *ls); |
| 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); | ||
| 74 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); | 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); |
| 75 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); | 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); |
| 76 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); | 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.67 2005/08/24 16:15:49 roberto Exp $ | 2 | ** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $ |
| 3 | ** Limits, basic types, and some other `installation-dependent' definitions | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -15,9 +15,6 @@ · 9 unmodified lines | |||
| 15 | #include "lua.h" | 15 | #include "lua.h" |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | #define api_check luai_apicheck | ||
| 19 | |||
| 20 | |||
| 21 | typedef LUAI_UINT32 lu_int32; | 18 | typedef LUAI_UINT32 lu_int32; |
| 22 | 19 | ||
| 23 | typedef LUAI_UMEM lu_mem; | 20 | typedef LUAI_UMEM lu_mem; |
| @@ -54,7 +51,19 @@ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; · 30 unmodified lines | |||
| 54 | typedef LUAI_UACNUMBER l_uacNumber; | 51 | typedef LUAI_UACNUMBER l_uacNumber; |
| 55 | 52 | ||
| 56 | 53 | ||
| 57 | #define check_exp(c,e) (lua_assert(c), (e)) | 54 | /* internal assertions for in-house debugging */ |
| 55 | #ifdef lua_assert | ||
| 56 | |||
| 57 | #define check_exp(c,e) (lua_assert(c), (e)) | ||
| 58 | #define api_check(l,e) lua_assert(e) | ||
| 59 | |||
| 60 | #else | ||
| 61 | |||
| 62 | #define lua_assert(c) ((void)0) | ||
| 63 | #define check_exp(c,e) (e) | ||
| 64 | #define api_check luai_apicheck | ||
| 65 | |||
| 66 | #endif | ||
| 58 | 67 | ||
| 59 | 68 | ||
| 60 | #ifndef UNUSED | 69 | #ifndef UNUSED |
| @@ -66,6 +75,10 @@ typedef LUAI_UACNUMBER l_uacNumber; · 5 unmodified lines | |||
| 66 | #define cast(t, exp) ((t)(exp)) | 75 | #define cast(t, exp) ((t)(exp)) |
| 67 | #endif | 76 | #endif |
| 68 | 77 | ||
| 78 | #define cast_byte(i) cast(lu_byte, (i)) | ||
| 79 | #define cast_num(i) cast(lua_Number, (i)) | ||
| 80 | #define cast_int(i) cast(int, (i)) | ||
| 81 | |||
| 69 | 82 | ||
| 70 | 83 | ||
| 71 | /* | 84 | /* |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.69 2005/02/23 17:30:22 roberto Exp $ | 2 | ** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $ |
| 3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -81,22 +81,6 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 75 unmodified lines | |||
| 81 | luaD_throw(L, LUA_ERRMEM); | 81 | luaD_throw(L, LUA_ERRMEM); |
| 82 | lua_assert((nsize == 0) == (block == NULL)); | 82 | lua_assert((nsize == 0) == (block == NULL)); |
| 83 | g->totalbytes = (g->totalbytes - osize) + nsize; | 83 | g->totalbytes = (g->totalbytes - osize) + nsize; |
| 84 | #if 0 | ||
| 85 | { /* auxiliar patch to monitor garbage collection */ | ||
| 86 | static unsigned long total = 0; /* our "time" */ | ||
| 87 | static lu_mem last = 0; /* last totalmem that generated an output */ | ||
| 88 | static FILE *f = NULL; /* output file */ | ||
| 89 | if (nsize <= osize) total += 1; /* "time" always grow */ | ||
| 90 | else total += (nsize - osize); | ||
| 91 | if ((int)g->totalbytes - (int)last > 1000 || | ||
| 92 | (int)g->totalbytes - (int)last < -1000) { | ||
| 93 | last = g->totalbytes; | ||
| 94 | if (f == NULL) f = fopen("trace", "w"); | ||
| 95 | fprintf(f, "%lu %u %u %u %d\n", total, g->totalbytes, g->GCthreshold, | ||
| 96 | g->estimate, g->gcstate); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | #endif | ||
| 100 | return block; | 84 | return block; |
| 101 | } | 85 | } |
| 102 | 86 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.48 2005/10/17 18:01:51 roberto Exp $ | 2 | ** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -16,8 +16,9 @@ · 10 unmodified lines | |||
| 16 | #define loadlib_c | 16 | #define loadlib_c |
| 17 | #define LUA_LIB | 17 | #define LUA_LIB |
| 18 | 18 | ||
| 19 | #include "lua.h" | ||
| 20 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
| 20 | #include "lobject.h" | ||
| 21 | #include "lua.h" | ||
| 21 | #include "lualib.h" | 22 | #include "lualib.h" |
| 22 | 23 | ||
| 23 | 24 | ||
| @@ -236,11 +237,8 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 212 unmodified lines | |||
| 236 | #define LIB_FAIL "absent" | 237 | #define LIB_FAIL "absent" |
| 237 | 238 | ||
| 238 | 239 | ||
| 239 | #if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux) | 240 | #define DLMSG "dynamic libraries not enabled; check your Lua installation" |
| 240 | #define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation" | 241 | |
| 241 | #else | ||
| 242 | #define DLMSG LUA_QL("loadlib") " not supported" | ||
| 243 | #endif | ||
| 244 | 242 | ||
| 245 | static void ll_unloadlib (void *lib) { | 243 | static void ll_unloadlib (void *lib) { |
| 246 | (void)lib; /* to avoid warnings */ | 244 | (void)lib; /* to avoid warnings */ |
| @@ -362,20 +360,23 @@ static const char *findfile (lua_State *L, const char *name, · 115 unmodified lines | |||
| 362 | path = lua_tostring(L, -1); | 360 | path = lua_tostring(L, -1); |
| 363 | if (path == NULL) | 361 | if (path == NULL) |
| 364 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); | 362 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); |
| 363 | lua_pushstring(L, ""); /* error accumulator */ | ||
| 365 | while ((path = pushnexttemplate(L, path)) != NULL) { | 364 | while ((path = pushnexttemplate(L, path)) != NULL) { |
| 366 | const char *filename; | 365 | const char *filename; |
| 367 | filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); | 366 | filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); |
| 368 | if (readable(filename)) /* does file exist and is readable? */ | 367 | if (readable(filename)) /* does file exist and is readable? */ |
| 369 | return filename; /* return that file name */ | 368 | return filename; /* return that file name */ |
| 370 | lua_pop(L, 2); /* remove path template and file name */ | 369 | lua_pop(L, 2); /* remove path template and file name */ |
| 370 | luaO_pushfstring(L, "\n\tno file " LUA_QS, filename); | ||
| 371 | lua_concat(L, 2); | ||
| 371 | } | 372 | } |
| 372 | return NULL; /* not found */ | 373 | return NULL; /* not found */ |
| 373 | } | 374 | } |
| 374 | 375 | ||
| 375 | 376 | ||
| 376 | static void loaderror (lua_State *L) { | 377 | static void loaderror (lua_State *L, const char *filename) { |
| 377 | luaL_error(L, "error loading module " LUA_QS " (%s)", | 378 | luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", |
| 378 | lua_tostring(L, 1), lua_tostring(L, -1)); | 379 | lua_tostring(L, 1), filename, lua_tostring(L, -1)); |
| 379 | } | 380 | } |
| 380 | 381 | ||
| 381 | 382 | ||
| @@ -383,9 +384,9 @@ static int loader_Lua (lua_State *L) { · 1 unmodified line | |||
| 383 | const char *filename; | 384 | const char *filename; |
| 384 | const char *name = luaL_checkstring(L, 1); | 385 | const char *name = luaL_checkstring(L, 1); |
| 385 | filename = findfile(L, name, "path"); | 386 | filename = findfile(L, name, "path"); |
| 386 | if (filename == NULL) return 0; /* library not found in this path */ | 387 | if (filename == NULL) return 1; /* library not found in this path */ |
| 387 | if (luaL_loadfile(L, filename) != 0) | 388 | if (luaL_loadfile(L, filename) != 0) |
| 388 | loaderror(L); | 389 | loaderror(L, filename); |
| 389 | return 1; /* library loaded successfully */ | 390 | return 1; /* library loaded successfully */ |
| 390 | } | 391 | } |
| 391 | 392 | ||
| @@ -405,10 +406,10 @@ static int loader_C (lua_State *L) { · 13 unmodified lines | |||
| 405 | const char *funcname; | 406 | const char *funcname; |
| 406 | const char *name = luaL_checkstring(L, 1); | 407 | const char *name = luaL_checkstring(L, 1); |
| 407 | const char *filename = findfile(L, name, "cpath"); | 408 | const char *filename = findfile(L, name, "cpath"); |
| 408 | if (filename == NULL) return 0; /* library not found in this path */ | 409 | if (filename == NULL) return 1; /* library not found in this path */ |
| 409 | funcname = mkfuncname(L, name); | 410 | funcname = mkfuncname(L, name); |
| 410 | if (ll_loadfunc(L, filename, funcname) != 0) | 411 | if (ll_loadfunc(L, filename, funcname) != 0) |
| 411 | loaderror(L); | 412 | loaderror(L, filename); |
| 412 | return 1; /* library loaded successfully */ | 413 | return 1; /* library loaded successfully */ |
| 413 | } | 414 | } |
| 414 | 415 | ||
| @@ -422,22 +423,26 @@ static int loader_Croot (lua_State *L) { · 7 unmodified lines | |||
| 422 | if (p == NULL) return 0; /* is root */ | 423 | if (p == NULL) return 0; /* is root */ |
| 423 | lua_pushlstring(L, name, p - name); | 424 | lua_pushlstring(L, name, p - name); |
| 424 | filename = findfile(L, lua_tostring(L, -1), "cpath"); | 425 | filename = findfile(L, lua_tostring(L, -1), "cpath"); |
| 425 | if (filename == NULL) return 0; /* root not found */ | 426 | if (filename == NULL) return 1; /* root not found */ |
| 426 | funcname = mkfuncname(L, name); | 427 | funcname = mkfuncname(L, name); |
| 427 | if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { | 428 | if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { |
| 428 | if (stat == ERRFUNC) return 0; /* function not found */ | 429 | if (stat != ERRFUNC) loaderror(L, filename); /* real error */ |
| 429 | else | 430 | luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, |
| 430 | loaderror(L); /* real error */ | 431 | name, filename); |
| 432 | return 1; /* function not found */ | ||
| 431 | } | 433 | } |
| 432 | return 1; | 434 | return 1; |
| 433 | } | 435 | } |
| 434 | 436 | ||
| 435 | 437 | ||
| 436 | static int loader_preload (lua_State *L) { | 438 | static int loader_preload (lua_State *L) { |
| 439 | const char *name = luaL_checkstring(L, 1); | ||
| 437 | lua_getfield(L, LUA_ENVIRONINDEX, "preload"); | 440 | lua_getfield(L, LUA_ENVIRONINDEX, "preload"); |
| 438 | if (!lua_istable(L, -1)) | 441 | if (!lua_istable(L, -1)) |
| 439 | luaL_error(L, LUA_QL("package.preload") " must be a table"); | 442 | luaL_error(L, LUA_QL("package.preload") " must be a table"); |
| 440 | lua_getfield(L, -1, luaL_checkstring(L, 1)); | 443 | lua_getfield(L, -1, name); |
| 444 | if (lua_isnil(L, -1)) /* not found? */ | ||
| 445 | luaO_pushfstring(L, "\n\tno field package.preload['%s']", name); | ||
| 441 | return 1; | 446 | return 1; |
| 442 | } | 447 | } |
| 443 | 448 | ||
| @@ -461,14 +466,20 @@ static int ll_require (lua_State *L) { · 17 unmodified lines | |||
| 461 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); | 466 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); |
| 462 | if (!lua_istable(L, -1)) | 467 | if (!lua_istable(L, -1)) |
| 463 | luaL_error(L, LUA_QL("package.loaders") " must be a table"); | 468 | luaL_error(L, LUA_QL("package.loaders") " must be a table"); |
| 469 | lua_pushstring(L, ""); /* error message accumulator */ | ||
| 464 | for (i=1; ; i++) { | 470 | for (i=1; ; i++) { |
| 465 | lua_rawgeti(L, -1, i); /* get a loader */ | 471 | lua_rawgeti(L, -2, i); /* get a loader */ |
| 466 | if (lua_isnil(L, -1)) | 472 | if (lua_isnil(L, -1)) |
| 467 | luaL_error(L, "module " LUA_QS " not found", name); | 473 | luaL_error(L, "module " LUA_QS " not found:%s", |
| 474 | name, lua_tostring(L, -2)); | ||
| 468 | lua_pushstring(L, name); | 475 | lua_pushstring(L, name); |
| 469 | lua_call(L, 1, 1); /* call it */ | 476 | lua_call(L, 1, 1); /* call it */ |
| 470 | if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */ | 477 | if (lua_isfunction(L, -1)) /* did it find module? */ |
| 471 | else break; /* module loaded successfully */ | 478 | break; /* module loaded successfully */ |
| 479 | else if (lua_isstring(L, -1)) /* loader returned error message? */ | ||
| 480 | lua_concat(L, 2); /* accumulate it */ | ||
| 481 | else | ||
| 482 | lua_pop(L, 1); | ||
| 472 | } | 483 | } |
| 473 | lua_pushlightuserdata(L, sentinel); | 484 | lua_pushlightuserdata(L, sentinel); |
| 474 | lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ | 485 | lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ |
| @@ -539,7 +550,7 @@ static int ll_module (lua_State *L) { · 64 unmodified lines | |||
| 539 | if (!lua_istable(L, -1)) { /* not found? */ | 550 | if (!lua_istable(L, -1)) { /* not found? */ |
| 540 | lua_pop(L, 1); /* remove previous result */ | 551 | lua_pop(L, 1); /* remove previous result */ |
| 541 | /* try global variable (and create one if it does not exist) */ | 552 | /* try global variable (and create one if it does not exist) */ |
| 542 | if (luaL_findtable(L, LUA_GLOBALSINDEX, modname) != NULL) | 553 | if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) |
| 543 | return luaL_error(L, "name conflict for module " LUA_QS, modname); | 554 | return luaL_error(L, "name conflict for module " LUA_QS, modname); |
| 544 | lua_pushvalue(L, -1); | 555 | lua_pushvalue(L, -1); |
| 545 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ | 556 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ |
| @@ -562,7 +573,7 @@ static int ll_module (lua_State *L) { · 16 unmodified lines | |||
| 562 | static int ll_seeall (lua_State *L) { | 573 | static int ll_seeall (lua_State *L) { |
| 563 | luaL_checktype(L, 1, LUA_TTABLE); | 574 | luaL_checktype(L, 1, LUA_TTABLE); |
| 564 | if (!lua_getmetatable(L, 1)) { | 575 | if (!lua_getmetatable(L, 1)) { |
| 565 | lua_newtable(L); /* create new metatable */ | 576 | lua_createtable(L, 0, 1); /* create new metatable */ |
| 566 | lua_pushvalue(L, -1); | 577 | lua_pushvalue(L, -1); |
| 567 | lua_setmetatable(L, 1); | 578 | lua_setmetatable(L, 1); |
| 568 | } | 579 | } |
| @@ -629,7 +640,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 60 unmodified lines | |||
| 629 | lua_pushvalue(L, -1); | 640 | lua_pushvalue(L, -1); |
| 630 | lua_replace(L, LUA_ENVIRONINDEX); | 641 | lua_replace(L, LUA_ENVIRONINDEX); |
| 631 | /* create `loaders' table */ | 642 | /* create `loaders' table */ |
| 632 | lua_newtable(L); | 643 | lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); |
| 633 | /* fill it with pre-defined loaders */ | 644 | /* fill it with pre-defined loaders */ |
| 634 | for (i=0; loaders[i] != NULL; i++) { | 645 | for (i=0; loaders[i] != NULL; i++) { |
| 635 | lua_pushcfunction(L, loaders[i]); | 646 | lua_pushcfunction(L, loaders[i]); |
| @@ -643,7 +654,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 7 unmodified lines | |||
| 643 | LUA_EXECDIR "\n" LUA_IGMARK); | 654 | LUA_EXECDIR "\n" LUA_IGMARK); |
| 644 | lua_setfield(L, -2, "config"); | 655 | lua_setfield(L, -2, "config"); |
| 645 | /* set field `loaded' */ | 656 | /* set field `loaded' */ |
| 646 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED"); | 657 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); |
| 647 | lua_setfield(L, -2, "loaded"); | 658 | lua_setfield(L, -2, "loaded"); |
| 648 | /* set field `preload' */ | 659 | /* set field `preload' */ |
| 649 | lua_newtable(L); | 660 | lua_newtable(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.19 2005/10/24 17:37:52 roberto Exp $ | 2 | ** $Id: lobject.c,v 2.21 2006/01/10 12:50:00 roberto Exp $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -24,7 +24,7 @@ · 18 unmodified lines | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | const TValue luaO_nilobject = {{NULL}, LUA_TNIL}; | 27 | const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | /* | 30 | /* |
| @@ -39,7 +39,7 @@ int luaO_int2fb (unsigned int x) { · 8 unmodified lines | |||
| 39 | e++; | 39 | e++; |
| 40 | } | 40 | } |
| 41 | if (x < 8) return x; | 41 | if (x < 8) return x; |
| 42 | else return ((e+1) << 3) | (cast(int, x) - 8); | 42 | else return ((e+1) << 3) | (cast_int(x) - 8); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | 45 | ||
| @@ -129,12 +129,12 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 83 unmodified lines | |||
| 129 | break; | 129 | break; |
| 130 | } | 130 | } |
| 131 | case 'd': { | 131 | case 'd': { |
| 132 | setnvalue(L->top, cast(lua_Number, va_arg(argp, int))); | 132 | setnvalue(L->top, cast_num(va_arg(argp, int))); |
| 133 | incr_top(L); | 133 | incr_top(L); |
| 134 | break; | 134 | break; |
| 135 | } | 135 | } |
| 136 | case 'f': { | 136 | case 'f': { |
| 137 | setnvalue(L->top, cast(lua_Number, va_arg(argp, l_uacNumber))); | 137 | setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); |
| 138 | incr_top(L); | 138 | incr_top(L); |
| 139 | break; | 139 | break; |
| 140 | } | 140 | } |
| @@ -161,7 +161,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 20 unmodified lines | |||
| 161 | fmt = e+2; | 161 | fmt = e+2; |
| 162 | } | 162 | } |
| 163 | pushstr(L, fmt); | 163 | pushstr(L, fmt); |
| 164 | luaV_concat(L, n+1, cast(int, L->top - L->base) - 1); | 164 | luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); |
| 165 | L->top -= n; | 165 | L->top -= n; |
| 166 | return svalue(L->top - 1); | 166 | return svalue(L->top - 1); |
| 167 | } | 167 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.18 2005/10/24 17:37:33 roberto Exp $ | 2 | ** $Id: lobject.h,v 2.19 2006/01/10 12:51:53 roberto Exp $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -323,9 +323,12 @@ typedef union Closure { · 317 unmodified lines | |||
| 323 | ** Tables | 323 | ** Tables |
| 324 | */ | 324 | */ |
| 325 | 325 | ||
| 326 | typedef struct TKey { | 326 | typedef union TKey { |
| 327 | TValuefields; | 327 | struct { |
| 328 | struct Node *next; /* for chaining */ | 328 | TValuefields; |
| 329 | struct Node *next; /* for chaining */ | ||
| 330 | } nk; | ||
| 331 | TValue tvk; | ||
| 329 | } TKey; | 332 | } TKey; |
| 330 | 333 | ||
| 331 | 334 | ||
| @@ -360,8 +363,9 @@ typedef struct Table { · 28 unmodified lines | |||
| 360 | #define sizenode(t) (twoto((t)->lsizenode)) | 363 | #define sizenode(t) (twoto((t)->lsizenode)) |
| 361 | 364 | ||
| 362 | 365 | ||
| 366 | #define luaO_nilobject (&luaO_nilobject_) | ||
| 363 | 367 | ||
| 364 | LUAI_DATA const TValue luaO_nilobject; | 368 | LUAI_DATA const TValue luaO_nilobject_; |
| 365 | 369 | ||
| 366 | #define ceillog2(x) (luaO_log2((x)-1) + 1) | 370 | #define ceillog2(x) (luaO_log2((x)-1) + 1) |
| 367 | 371 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.123 2005/10/23 17:37:55 roberto Exp $ | 2 | ** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $ |
| 3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -208,7 +208,7 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ · 202 unmodified lines | |||
| 208 | } OpCode; | 208 | } OpCode; |
| 209 | 209 | ||
| 210 | 210 | ||
| 211 | #define NUM_OPCODES (cast(int, OP_VARARG+1)) | 211 | #define NUM_OPCODES (cast(int, OP_VARARG) + 1) |
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | 214 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 roberto Exp $ | 2 | ** $Id: loslib.c,v 1.16 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Standard Operating System library | 3 | ** Standard Operating System library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -37,26 +37,26 @@ static int os_pushresult (lua_State *L, int i, const char *filename) { · 31 unmodified lines | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | static int io_execute (lua_State *L) { | 40 | static int os_execute (lua_State *L) { |
| 41 | lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); | 41 | lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); |
| 42 | return 1; | 42 | return 1; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | static int io_remove (lua_State *L) { | 46 | static int os_remove (lua_State *L) { |
| 47 | const char *filename = luaL_checkstring(L, 1); | 47 | const char *filename = luaL_checkstring(L, 1); |
| 48 | return os_pushresult(L, remove(filename) == 0, filename); | 48 | return os_pushresult(L, remove(filename) == 0, filename); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | static int io_rename (lua_State *L) { | 52 | static int os_rename (lua_State *L) { |
| 53 | const char *fromname = luaL_checkstring(L, 1); | 53 | const char *fromname = luaL_checkstring(L, 1); |
| 54 | const char *toname = luaL_checkstring(L, 2); | 54 | const char *toname = luaL_checkstring(L, 2); |
| 55 | return os_pushresult(L, rename(fromname, toname) == 0, fromname); | 55 | return os_pushresult(L, rename(fromname, toname) == 0, fromname); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | 58 | ||
| 59 | static int io_tmpname (lua_State *L) { | 59 | static int os_tmpname (lua_State *L) { |
| 60 | char buff[LUA_TMPNAMBUFSIZE]; | 60 | char buff[LUA_TMPNAMBUFSIZE]; |
| 61 | int err; | 61 | int err; |
| 62 | lua_tmpnam(buff, err); | 62 | lua_tmpnam(buff, err); |
| @@ -67,13 +67,13 @@ static int io_tmpname (lua_State *L) { · 4 unmodified lines | |||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | static int io_getenv (lua_State *L) { | 70 | static int os_getenv (lua_State *L) { |
| 71 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ | 71 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ |
| 72 | return 1; | 72 | return 1; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | 75 | ||
| 76 | static int io_clock (lua_State *L) { | 76 | static int os_clock (lua_State *L) { |
| 77 | lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); | 77 | lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); |
| 78 | return 1; | 78 | return 1; |
| 79 | } | 79 | } |
| @@ -123,7 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { · 43 unmodified lines | |||
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | static int io_date (lua_State *L) { | 126 | static int os_date (lua_State *L) { |
| 127 | const char *s = luaL_optstring(L, 1, "%c"); | 127 | const char *s = luaL_optstring(L, 1, "%c"); |
| 128 | time_t t = lua_isnoneornil(L, 2) ? time(NULL) : | 128 | time_t t = lua_isnoneornil(L, 2) ? time(NULL) : |
| 129 | (time_t)luaL_checknumber(L, 2); | 129 | (time_t)luaL_checknumber(L, 2); |
| @@ -159,7 +159,7 @@ static int io_date (lua_State *L) { · 29 unmodified lines | |||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | 161 | ||
| 162 | static int io_time (lua_State *L) { | 162 | static int os_time (lua_State *L) { |
| 163 | time_t t; | 163 | time_t t; |
| 164 | if (lua_isnoneornil(L, 1)) /* called without args? */ | 164 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
| 165 | t = time(NULL); /* get current time */ | 165 | t = time(NULL); /* get current time */ |
| @@ -179,12 +179,12 @@ static int io_time (lua_State *L) { · 13 unmodified lines | |||
| 179 | if (t == (time_t)(-1)) | 179 | if (t == (time_t)(-1)) |
| 180 | lua_pushnil(L); | 180 | lua_pushnil(L); |
| 181 | else | 181 | else |
| 182 | lua_pushnumber(L, t); | 182 | lua_pushnumber(L, (lua_Number)t); |
| 183 | return 1; | 183 | return 1; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | 186 | ||
| 187 | static int io_difftime (lua_State *L) { | 187 | static int os_difftime (lua_State *L) { |
| 188 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), | 188 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), |
| 189 | (time_t)(luaL_optnumber(L, 2, 0)))); | 189 | (time_t)(luaL_optnumber(L, 2, 0)))); |
| 190 | return 1; | 190 | return 1; |
| @@ -193,7 +193,7 @@ static int io_difftime (lua_State *L) { · 2 unmodified lines | |||
| 193 | /* }====================================================== */ | 193 | /* }====================================================== */ |
| 194 | 194 | ||
| 195 | 195 | ||
| 196 | static int io_setloc (lua_State *L) { | 196 | static int os_setlocale (lua_State *L) { |
| 197 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, | 197 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, |
| 198 | LC_NUMERIC, LC_TIME}; | 198 | LC_NUMERIC, LC_TIME}; |
| 199 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", | 199 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
| @@ -206,23 +206,23 @@ static int io_setloc (lua_State *L) { · 6 unmodified lines | |||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | 208 | ||
| 209 | static int io_exit (lua_State *L) { | 209 | static int os_exit (lua_State *L) { |
| 210 | exit(luaL_optint(L, 1, EXIT_SUCCESS)); | 210 | exit(luaL_optint(L, 1, EXIT_SUCCESS)); |
| 211 | return 0; /* to avoid warnings */ | 211 | return 0; /* to avoid warnings */ |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | static const luaL_Reg syslib[] = { | 214 | static const luaL_Reg syslib[] = { |
| 215 | {"clock", io_clock}, | 215 | {"clock", os_clock}, |
| 216 | {"date", io_date}, | 216 | {"date", os_date}, |
| 217 | {"difftime", io_difftime}, | 217 | {"difftime", os_difftime}, |
| 218 | {"execute", io_execute}, | 218 | {"execute", os_execute}, |
| 219 | {"exit", io_exit}, | 219 | {"exit", os_exit}, |
| 220 | {"getenv", io_getenv}, | 220 | {"getenv", os_getenv}, |
| 221 | {"remove", io_remove}, | 221 | {"remove", os_remove}, |
| 222 | {"rename", io_rename}, | 222 | {"rename", os_rename}, |
| 223 | {"setlocale", io_setloc}, | 223 | {"setlocale", os_setlocale}, |
| 224 | {"time", io_time}, | 224 | {"time", os_time}, |
| 225 | {"tmpname", io_tmpname}, | 225 | {"tmpname", os_tmpname}, |
| 226 | {NULL, NULL} | 226 | {NULL, NULL} |
| 227 | }; | 227 | }; |
| 228 | 228 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.38 2005/10/24 17:38:47 roberto Exp $ | 2 | ** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -54,24 +54,6 @@ static void chunk (LexState *ls); · 48 unmodified lines | |||
| 54 | static void expr (LexState *ls, expdesc *v); | 54 | static void expr (LexState *ls, expdesc *v); |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | |||
| 58 | static void next (LexState *ls) { | ||
| 59 | ls->lastline = ls->linenumber; | ||
| 60 | if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ | ||
| 61 | ls->t = ls->lookahead; /* use this one */ | ||
| 62 | ls->lookahead.token = TK_EOS; /* and discharge it */ | ||
| 63 | } | ||
| 64 | else | ||
| 65 | ls->t.token = luaX_lex(ls, &ls->t.seminfo); /* read next token */ | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | static void lookahead (LexState *ls) { | ||
| 70 | lua_assert(ls->lookahead.token == TK_EOS); | ||
| 71 | ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo); | ||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | static void anchor_token (LexState *ls) { | 57 | static void anchor_token (LexState *ls) { |
| 76 | if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { | 58 | if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { |
| 77 | TString *ts = ls->t.seminfo.ts; | 59 | TString *ts = ls->t.seminfo.ts; |
| @@ -97,7 +79,7 @@ static void errorlimit (FuncState *fs, int limit, const char *what) { · 19 unmodified lines | |||
| 97 | 79 | ||
| 98 | static int testnext (LexState *ls, int c) { | 80 | static int testnext (LexState *ls, int c) { |
| 99 | if (ls->t.token == c) { | 81 | if (ls->t.token == c) { |
| 100 | next(ls); | 82 | luaX_next(ls); |
| 101 | return 1; | 83 | return 1; |
| 102 | } | 84 | } |
| 103 | else return 0; | 85 | else return 0; |
| @@ -111,7 +93,7 @@ static void check (LexState *ls, int c) { · 7 unmodified lines | |||
| 111 | 93 | ||
| 112 | static void checknext (LexState *ls, int c) { | 94 | static void checknext (LexState *ls, int c) { |
| 113 | check(ls, c); | 95 | check(ls, c); |
| 114 | next(ls); | 96 | luaX_next(ls); |
| 115 | } | 97 | } |
| 116 | 98 | ||
| 117 | 99 | ||
| @@ -136,7 +118,7 @@ static TString *str_checkname (LexState *ls) { · 18 unmodified lines | |||
| 136 | TString *ts; | 118 | TString *ts; |
| 137 | check(ls, TK_NAME); | 119 | check(ls, TK_NAME); |
| 138 | ts = ls->t.seminfo.ts; | 120 | ts = ls->t.seminfo.ts; |
| 139 | next(ls); | 121 | luaX_next(ls); |
| 140 | return ts; | 122 | return ts; |
| 141 | } | 123 | } |
| 142 | 124 | ||
| @@ -184,7 +166,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { · 41 unmodified lines | |||
| 184 | 166 | ||
| 185 | static void adjustlocalvars (LexState *ls, int nvars) { | 167 | static void adjustlocalvars (LexState *ls, int nvars) { |
| 186 | FuncState *fs = ls->fs; | 168 | FuncState *fs = ls->fs; |
| 187 | fs->nactvar = cast(lu_byte, fs->nactvar + nvars); | 169 | fs->nactvar = cast_byte(fs->nactvar + nvars); |
| 188 | for (; nvars; nvars--) { | 170 | for (; nvars; nvars--) { |
| 189 | getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; | 171 | getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; |
| 190 | } | 172 | } |
| @@ -216,8 +198,8 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 25 unmodified lines | |||
| 216 | f->upvalues[f->nups] = name; | 198 | f->upvalues[f->nups] = name; |
| 217 | luaC_objbarrier(fs->L, f, name); | 199 | luaC_objbarrier(fs->L, f, name); |
| 218 | lua_assert(v->k == VLOCAL || v->k == VUPVAL); | 200 | lua_assert(v->k == VLOCAL || v->k == VUPVAL); |
| 219 | fs->upvalues[f->nups].k = cast(lu_byte, v->k); | 201 | fs->upvalues[f->nups].k = cast_byte(v->k); |
| 220 | fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info); | 202 | fs->upvalues[f->nups].info = cast_byte(v->u.s.info); |
| 221 | return f->nups++; | 203 | return f->nups++; |
| 222 | } | 204 | } |
| 223 | 205 | ||
| @@ -404,7 +386,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 180 unmodified lines | |||
| 404 | luaX_setinput(L, &lexstate, z, luaS_new(L, name)); | 386 | luaX_setinput(L, &lexstate, z, luaS_new(L, name)); |
| 405 | open_func(&lexstate, &funcstate); | 387 | open_func(&lexstate, &funcstate); |
| 406 | funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ | 388 | funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ |
| 407 | next(&lexstate); /* read first token */ | 389 | luaX_next(&lexstate); /* read first token */ |
| 408 | chunk(&lexstate); | 390 | chunk(&lexstate); |
| 409 | check(&lexstate, TK_EOS); | 391 | check(&lexstate, TK_EOS); |
| 410 | close_func(&lexstate); | 392 | close_func(&lexstate); |
| @@ -426,7 +408,7 @@ static void field (LexState *ls, expdesc *v) { · 15 unmodified lines | |||
| 426 | FuncState *fs = ls->fs; | 408 | FuncState *fs = ls->fs; |
| 427 | expdesc key; | 409 | expdesc key; |
| 428 | luaK_exp2anyreg(fs, v); | 410 | luaK_exp2anyreg(fs, v); |
| 429 | next(ls); /* skip the dot or colon */ | 411 | luaX_next(ls); /* skip the dot or colon */ |
| 430 | checkname(ls, &key); | 412 | checkname(ls, &key); |
| 431 | luaK_indexed(fs, v, &key); | 413 | luaK_indexed(fs, v, &key); |
| 432 | } | 414 | } |
| @@ -434,7 +416,7 @@ static void field (LexState *ls, expdesc *v) { · 1 unmodified line | |||
| 434 | 416 | ||
| 435 | static void yindex (LexState *ls, expdesc *v) { | 417 | static void yindex (LexState *ls, expdesc *v) { |
| 436 | /* index -> '[' expr ']' */ | 418 | /* index -> '[' expr ']' */ |
| 437 | next(ls); /* skip the '[' */ | 419 | luaX_next(ls); /* skip the '[' */ |
| 438 | expr(ls, v); | 420 | expr(ls, v); |
| 439 | luaK_exp2val(ls->fs, v); | 421 | luaK_exp2val(ls->fs, v); |
| 440 | checknext(ls, ']'); | 422 | checknext(ls, ']'); |
| @@ -530,7 +512,7 @@ static void constructor (LexState *ls, expdesc *t) { · 89 unmodified lines | |||
| 530 | closelistfield(fs, &cc); | 512 | closelistfield(fs, &cc); |
| 531 | switch(ls->t.token) { | 513 | switch(ls->t.token) { |
| 532 | case TK_NAME: { /* may be listfields or recfields */ | 514 | case TK_NAME: { /* may be listfields or recfields */ |
| 533 | lookahead(ls); | 515 | luaX_lookahead(ls); |
| 534 | if (ls->lookahead.token != '=') /* expression? */ | 516 | if (ls->lookahead.token != '=') /* expression? */ |
| 535 | listfield(ls, &cc); | 517 | listfield(ls, &cc); |
| 536 | else | 518 | else |
| @@ -571,7 +553,7 @@ static void parlist (LexState *ls) { · 34 unmodified lines | |||
| 571 | break; | 553 | break; |
| 572 | } | 554 | } |
| 573 | case TK_DOTS: { /* param -> `...' */ | 555 | case TK_DOTS: { /* param -> `...' */ |
| 574 | next(ls); | 556 | luaX_next(ls); |
| 575 | #if defined(LUA_COMPAT_VARARG) | 557 | #if defined(LUA_COMPAT_VARARG) |
| 576 | /* use `arg' as default name */ | 558 | /* use `arg' as default name */ |
| 577 | new_localvarliteral(ls, "arg", nparams++); | 559 | new_localvarliteral(ls, "arg", nparams++); |
| @@ -585,7 +567,7 @@ static void parlist (LexState *ls) { · 7 unmodified lines | |||
| 585 | } while (!f->is_vararg && testnext(ls, ',')); | 567 | } while (!f->is_vararg && testnext(ls, ',')); |
| 586 | } | 568 | } |
| 587 | adjustlocalvars(ls, nparams); | 569 | adjustlocalvars(ls, nparams); |
| 588 | f->numparams = fs->nactvar - (f->is_vararg & VARARG_HASARG); | 570 | f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); |
| 589 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ | 571 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ |
| 590 | } | 572 | } |
| 591 | 573 | ||
| @@ -632,7 +614,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 40 unmodified lines | |||
| 632 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ | 614 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ |
| 633 | if (line != ls->lastline) | 615 | if (line != ls->lastline) |
| 634 | luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); | 616 | luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); |
| 635 | next(ls); | 617 | luaX_next(ls); |
| 636 | if (ls->t.token == ')') /* arg list is empty? */ | 618 | if (ls->t.token == ')') /* arg list is empty? */ |
| 637 | args.k = VVOID; | 619 | args.k = VVOID; |
| 638 | else { | 620 | else { |
| @@ -648,7 +630,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 9 unmodified lines | |||
| 648 | } | 630 | } |
| 649 | case TK_STRING: { /* funcargs -> STRING */ | 631 | case TK_STRING: { /* funcargs -> STRING */ |
| 650 | codestring(ls, &args, ls->t.seminfo.ts); | 632 | codestring(ls, &args, ls->t.seminfo.ts); |
| 651 | next(ls); /* must use `seminfo' before `next' */ | 633 | luaX_next(ls); /* must use `seminfo' before `next' */ |
| 652 | break; | 634 | break; |
| 653 | } | 635 | } |
| 654 | default: { | 636 | default: { |
| @@ -686,7 +668,7 @@ static void prefixexp (LexState *ls, expdesc *v) { · 31 unmodified lines | |||
| 686 | switch (ls->t.token) { | 668 | switch (ls->t.token) { |
| 687 | case '(': { | 669 | case '(': { |
| 688 | int line = ls->linenumber; | 670 | int line = ls->linenumber; |
| 689 | next(ls); | 671 | luaX_next(ls); |
| 690 | expr(ls, v); | 672 | expr(ls, v); |
| 691 | check_match(ls, ')', '(', line); | 673 | check_match(ls, ')', '(', line); |
| 692 | luaK_dischargevars(ls->fs, v); | 674 | luaK_dischargevars(ls->fs, v); |
| @@ -724,7 +706,7 @@ static void primaryexp (LexState *ls, expdesc *v) { · 31 unmodified lines | |||
| 724 | } | 706 | } |
| 725 | case ':': { /* `:' NAME funcargs */ | 707 | case ':': { /* `:' NAME funcargs */ |
| 726 | expdesc key; | 708 | expdesc key; |
| 727 | next(ls); | 709 | luaX_next(ls); |
| 728 | checkname(ls, &key); | 710 | checkname(ls, &key); |
| 729 | luaK_self(fs, v, &key); | 711 | luaK_self(fs, v, &key); |
| 730 | funcargs(ls, v); | 712 | funcargs(ls, v); |
| @@ -779,7 +761,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 48 unmodified lines | |||
| 779 | return; | 761 | return; |
| 780 | } | 762 | } |
| 781 | case TK_FUNCTION: { | 763 | case TK_FUNCTION: { |
| 782 | next(ls); | 764 | luaX_next(ls); |
| 783 | body(ls, v, 0, ls->linenumber); | 765 | body(ls, v, 0, ls->linenumber); |
| 784 | return; | 766 | return; |
| 785 | } | 767 | } |
| @@ -788,7 +770,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 2 unmodified lines | |||
| 788 | return; | 770 | return; |
| 789 | } | 771 | } |
| 790 | } | 772 | } |
| 791 | next(ls); | 773 | luaX_next(ls); |
| 792 | } | 774 | } |
| 793 | 775 | ||
| 794 | 776 | ||
| @@ -848,7 +830,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 53 unmodified lines | |||
| 848 | enterlevel(ls); | 830 | enterlevel(ls); |
| 849 | uop = getunopr(ls->t.token); | 831 | uop = getunopr(ls->t.token); |
| 850 | if (uop != OPR_NOUNOPR) { | 832 | if (uop != OPR_NOUNOPR) { |
| 851 | next(ls); | 833 | luaX_next(ls); |
| 852 | subexpr(ls, v, UNARY_PRIORITY); | 834 | subexpr(ls, v, UNARY_PRIORITY); |
| 853 | luaK_prefix(ls->fs, uop, v); | 835 | luaK_prefix(ls->fs, uop, v); |
| 854 | } | 836 | } |
| @@ -858,7 +840,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 3 unmodified lines | |||
| 858 | while (op != OPR_NOBINOPR && priority[op].left > limit) { | 840 | while (op != OPR_NOBINOPR && priority[op].left > limit) { |
| 859 | expdesc v2; | 841 | expdesc v2; |
| 860 | BinOpr nextop; | 842 | BinOpr nextop; |
| 861 | next(ls); | 843 | luaX_next(ls); |
| 862 | luaK_infix(ls->fs, op, v); | 844 | luaK_infix(ls->fs, op, v); |
| 863 | /* read sub-expression with higher priority */ | 845 | /* read sub-expression with higher priority */ |
| 864 | nextop = subexpr(ls, &v2, priority[op].right); | 846 | nextop = subexpr(ls, &v2, priority[op].right); |
| @@ -1009,7 +991,7 @@ static void whilestat (LexState *ls, int line) { · 144 unmodified lines | |||
| 1009 | int whileinit; | 991 | int whileinit; |
| 1010 | int condexit; | 992 | int condexit; |
| 1011 | BlockCnt bl; | 993 | BlockCnt bl; |
| 1012 | next(ls); /* skip WHILE */ | 994 | luaX_next(ls); /* skip WHILE */ |
| 1013 | whileinit = luaK_getlabel(fs); | 995 | whileinit = luaK_getlabel(fs); |
| 1014 | condexit = cond(ls); | 996 | condexit = cond(ls); |
| 1015 | enterblock(fs, &bl, 1); | 997 | enterblock(fs, &bl, 1); |
| @@ -1030,7 +1012,7 @@ static void repeatstat (LexState *ls, int line) { · 14 unmodified lines | |||
| 1030 | BlockCnt bl1, bl2; | 1012 | BlockCnt bl1, bl2; |
| 1031 | enterblock(fs, &bl1, 1); /* loop block */ | 1013 | enterblock(fs, &bl1, 1); /* loop block */ |
| 1032 | enterblock(fs, &bl2, 0); /* scope block */ | 1014 | enterblock(fs, &bl2, 0); /* scope block */ |
| 1033 | next(ls); /* skip REPEAT */ | 1015 | luaX_next(ls); /* skip REPEAT */ |
| 1034 | chunk(ls); | 1016 | chunk(ls); |
| 1035 | check_match(ls, TK_UNTIL, TK_REPEAT, line); | 1017 | check_match(ls, TK_UNTIL, TK_REPEAT, line); |
| 1036 | condexit = cond(ls); /* read condition (inside scope block) */ | 1018 | condexit = cond(ls); /* read condition (inside scope block) */ |
| @@ -1130,7 +1112,7 @@ static void forstat (LexState *ls, int line) { · 93 unmodified lines | |||
| 1130 | TString *varname; | 1112 | TString *varname; |
| 1131 | BlockCnt bl; | 1113 | BlockCnt bl; |
| 1132 | enterblock(fs, &bl, 1); /* scope for loop and control variables */ | 1114 | enterblock(fs, &bl, 1); /* scope for loop and control variables */ |
| 1133 | next(ls); /* skip `for' */ | 1115 | luaX_next(ls); /* skip `for' */ |
| 1134 | varname = str_checkname(ls); /* first variable name */ | 1116 | varname = str_checkname(ls); /* first variable name */ |
| 1135 | switch (ls->t.token) { | 1117 | switch (ls->t.token) { |
| 1136 | case '=': fornum(ls, varname, line); break; | 1118 | case '=': fornum(ls, varname, line); break; |
| @@ -1145,7 +1127,7 @@ static void forstat (LexState *ls, int line) { · 8 unmodified lines | |||
| 1145 | static int test_then_block (LexState *ls) { | 1127 | static int test_then_block (LexState *ls) { |
| 1146 | /* test_then_block -> [IF | ELSEIF] cond THEN block */ | 1128 | /* test_then_block -> [IF | ELSEIF] cond THEN block */ |
| 1147 | int condexit; | 1129 | int condexit; |
| 1148 | next(ls); /* skip IF or ELSEIF */ | 1130 | luaX_next(ls); /* skip IF or ELSEIF */ |
| 1149 | condexit = cond(ls); | 1131 | condexit = cond(ls); |
| 1150 | checknext(ls, TK_THEN); | 1132 | checknext(ls, TK_THEN); |
| 1151 | block(ls); /* `then' part */ | 1133 | block(ls); /* `then' part */ |
| @@ -1167,7 +1149,7 @@ static void ifstat (LexState *ls, int line) { · 15 unmodified lines | |||
| 1167 | if (ls->t.token == TK_ELSE) { | 1149 | if (ls->t.token == TK_ELSE) { |
| 1168 | luaK_concat(fs, &escapelist, luaK_jump(fs)); | 1150 | luaK_concat(fs, &escapelist, luaK_jump(fs)); |
| 1169 | luaK_patchtohere(fs, flist); | 1151 | luaK_patchtohere(fs, flist); |
| 1170 | next(ls); /* skip ELSE (after patch, for correct line info) */ | 1152 | luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ |
| 1171 | block(ls); /* `else' part */ | 1153 | block(ls); /* `else' part */ |
| 1172 | } | 1154 | } |
| 1173 | else | 1155 | else |
| @@ -1228,7 +1210,7 @@ static void funcstat (LexState *ls, int line) { · 54 unmodified lines | |||
| 1228 | /* funcstat -> FUNCTION funcname body */ | 1210 | /* funcstat -> FUNCTION funcname body */ |
| 1229 | int needself; | 1211 | int needself; |
| 1230 | expdesc v, b; | 1212 | expdesc v, b; |
| 1231 | next(ls); /* skip FUNCTION */ | 1213 | luaX_next(ls); /* skip FUNCTION */ |
| 1232 | needself = funcname(ls, &v); | 1214 | needself = funcname(ls, &v); |
| 1233 | body(ls, &b, needself, line); | 1215 | body(ls, &b, needself, line); |
| 1234 | luaK_storevar(ls->fs, &v, &b); | 1216 | luaK_storevar(ls->fs, &v, &b); |
| @@ -1255,7 +1237,7 @@ static void retstat (LexState *ls) { · 20 unmodified lines | |||
| 1255 | FuncState *fs = ls->fs; | 1237 | FuncState *fs = ls->fs; |
| 1256 | expdesc e; | 1238 | expdesc e; |
| 1257 | int first, nret; /* registers with returned values */ | 1239 | int first, nret; /* registers with returned values */ |
| 1258 | next(ls); /* skip RETURN */ | 1240 | luaX_next(ls); /* skip RETURN */ |
| 1259 | if (block_follow(ls->t.token) || ls->t.token == ';') | 1241 | if (block_follow(ls->t.token) || ls->t.token == ';') |
| 1260 | first = nret = 0; /* return no values */ | 1242 | first = nret = 0; /* return no values */ |
| 1261 | else { | 1243 | else { |
| @@ -1295,7 +1277,7 @@ static int statement (LexState *ls) { · 33 unmodified lines | |||
| 1295 | return 0; | 1277 | return 0; |
| 1296 | } | 1278 | } |
| 1297 | case TK_DO: { /* stat -> DO block END */ | 1279 | case TK_DO: { /* stat -> DO block END */ |
| 1298 | next(ls); /* skip DO */ | 1280 | luaX_next(ls); /* skip DO */ |
| 1299 | block(ls); | 1281 | block(ls); |
| 1300 | check_match(ls, TK_END, TK_DO, line); | 1282 | check_match(ls, TK_END, TK_DO, line); |
| 1301 | return 0; | 1283 | return 0; |
| @@ -1313,7 +1295,7 @@ static int statement (LexState *ls) { · 11 unmodified lines | |||
| 1313 | return 0; | 1295 | return 0; |
| 1314 | } | 1296 | } |
| 1315 | case TK_LOCAL: { /* stat -> localstat */ | 1297 | case TK_LOCAL: { /* stat -> localstat */ |
| 1316 | next(ls); /* skip LOCAL */ | 1298 | luaX_next(ls); /* skip LOCAL */ |
| 1317 | if (testnext(ls, TK_FUNCTION)) /* local function? */ | 1299 | if (testnext(ls, TK_FUNCTION)) /* local function? */ |
| 1318 | localfunc(ls); | 1300 | localfunc(ls); |
| 1319 | else | 1301 | else |
| @@ -1325,7 +1307,7 @@ static int statement (LexState *ls) { · 5 unmodified lines | |||
| 1325 | return 1; /* must be last statement */ | 1307 | return 1; /* must be last statement */ |
| 1326 | } | 1308 | } |
| 1327 | case TK_BREAK: { /* stat -> breakstat */ | 1309 | case TK_BREAK: { /* stat -> breakstat */ |
| 1328 | next(ls); /* skip BREAK */ | 1310 | luaX_next(ls); /* skip BREAK */ |
| 1329 | breakstat(ls); | 1311 | breakstat(ls); |
| 1330 | return 1; /* must be last statement */ | 1312 | return 1; /* must be last statement */ |
| 1331 | } | 1313 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp $ | 2 | ** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) { · 29 unmodified lines | |||
| 35 | GCObject *next = p->gch.next; /* save next */ | 35 | GCObject *next = p->gch.next; /* save next */ |
| 36 | unsigned int h = gco2ts(p)->hash; | 36 | unsigned int h = gco2ts(p)->hash; |
| 37 | int h1 = lmod(h, newsize); /* new position */ | 37 | int h1 = lmod(h, newsize); /* new position */ |
| 38 | lua_assert(cast(int, h%newsize) == lmod(h, newsize)); | 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); |
| 39 | p->gch.next = newhash[h1]; /* chain it */ | 39 | p->gch.next = newhash[h1]; /* chain it */ |
| 40 | newhash[h1] = p; | 40 | newhash[h1] = p; |
| 41 | p = next; | 41 | p = next; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.127 2005/10/26 13:28:19 roberto Exp $ | 2 | ** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 roberto Exp $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -683,8 +683,13 @@ static int str_gsub (lua_State *L) { · 677 unmodified lines | |||
| 683 | 683 | ||
| 684 | /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ | 684 | /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ |
| 685 | #define MAX_ITEM 512 | 685 | #define MAX_ITEM 512 |
| 686 | /* maximum size of each format specification (such as '%-099.99d') */ | 686 | /* valid flags in a format specification */ |
| 687 | #define MAX_FORMAT 20 | 687 | #define FLAGS "-+ #0" |
| 688 | /* | ||
| 689 | ** maximum size of each format specification (such as '%-099.99d') | ||
| 690 | ** (+10 accounts for %99.99x plus margin of error) | ||
| 691 | */ | ||
| 692 | #define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) | ||
| 688 | 693 | ||
| 689 | 694 | ||
| 690 | static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { | 695 | static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { |
| @@ -712,30 +717,37 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 21 unmodified lines | |||
| 712 | luaL_addchar(b, '"'); | 717 | luaL_addchar(b, '"'); |
| 713 | } | 718 | } |
| 714 | 719 | ||
| 715 | 720 | static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { | |
| 716 | static const char *scanformat (lua_State *L, const char *strfrmt, | ||
| 717 | char *form, int *hasprecision) { | ||
| 718 | const char *p = strfrmt; | 721 | const char *p = strfrmt; |
| 719 | while (strchr("-+ #0", *p)) p++; /* skip flags */ | 722 | while (strchr(FLAGS, *p)) p++; /* skip flags */ |
| 723 | if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) | ||
| 724 | luaL_error(L, "invalid format (repeated flags)"); | ||
| 720 | if (isdigit(uchar(*p))) p++; /* skip width */ | 725 | if (isdigit(uchar(*p))) p++; /* skip width */ |
| 721 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ | 726 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 722 | if (*p == '.') { | 727 | if (*p == '.') { |
| 723 | p++; | 728 | p++; |
| 724 | *hasprecision = 1; | ||
| 725 | if (isdigit(uchar(*p))) p++; /* skip precision */ | 729 | if (isdigit(uchar(*p))) p++; /* skip precision */ |
| 726 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ | 730 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 727 | } | 731 | } |
| 728 | if (isdigit(uchar(*p))) | 732 | if (isdigit(uchar(*p))) |
| 729 | luaL_error(L, "invalid format (width or precision too long)"); | 733 | luaL_error(L, "invalid format (width or precision too long)"); |
| 730 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ | 734 | *(form++) = '%'; |
| 731 | luaL_error(L, "invalid format (too long)"); | 735 | strncpy(form, strfrmt, p - strfrmt + 1); |
| 732 | form[0] = L_ESC; | 736 | form += p - strfrmt + 1; |
| 733 | strncpy(form+1, strfrmt, p-strfrmt+1); | 737 | *form = '\0'; |
| 734 | form[p-strfrmt+2] = 0; | ||
| 735 | return p; | 738 | return p; |
| 736 | } | 739 | } |
| 737 | 740 | ||
| 738 | 741 | ||
| 742 | static void addintlen (char *form) { | ||
| 743 | size_t l = strlen(form); | ||
| 744 | char spec = form[l - 1]; | ||
| 745 | strcpy(form + l - 1, LUA_INTFRMLEN); | ||
| 746 | form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; | ||
| 747 | form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; | ||
| 748 | } | ||
| 749 | |||
| 750 | |||
| 739 | static int str_format (lua_State *L) { | 751 | static int str_format (lua_State *L) { |
| 740 | int arg = 1; | 752 | int arg = 1; |
| 741 | size_t sfl; | 753 | size_t sfl; |
| @@ -751,21 +763,26 @@ static int str_format (lua_State *L) { · 9 unmodified lines | |||
| 751 | else { /* format item */ | 763 | else { /* format item */ |
| 752 | char form[MAX_FORMAT]; /* to store the format (`%...') */ | 764 | char form[MAX_FORMAT]; /* to store the format (`%...') */ |
| 753 | char buff[MAX_ITEM]; /* to store the formatted item */ | 765 | char buff[MAX_ITEM]; /* to store the formatted item */ |
| 754 | int hasprecision = 0; | ||
| 755 | arg++; | 766 | arg++; |
| 756 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); | 767 | strfrmt = scanformat(L, strfrmt, form); |
| 757 | switch (*strfrmt++) { | 768 | switch (*strfrmt++) { |
| 758 | case 'c': case 'd': case 'i': { | 769 | case 'c': { |
| 759 | sprintf(buff, form, luaL_checkint(L, arg)); | 770 | sprintf(buff, form, (int)luaL_checknumber(L, arg)); |
| 771 | break; | ||
| 772 | } | ||
| 773 | case 'd': case 'i': { | ||
| 774 | addintlen(form); | ||
| 775 | sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); | ||
| 760 | break; | 776 | break; |
| 761 | } | 777 | } |
| 762 | case 'o': case 'u': case 'x': case 'X': { | 778 | case 'o': case 'u': case 'x': case 'X': { |
| 763 | sprintf(buff, form, (unsigned int)(luaL_checknumber(L, arg))); | 779 | addintlen(form); |
| 780 | sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); | ||
| 764 | break; | 781 | break; |
| 765 | } | 782 | } |
| 766 | case 'e': case 'E': case 'f': | 783 | case 'e': case 'E': case 'f': |
| 767 | case 'g': case 'G': { | 784 | case 'g': case 'G': { |
| 768 | sprintf(buff, form, luaL_checknumber(L, arg)); | 785 | sprintf(buff, form, (double)luaL_checknumber(L, arg)); |
| 769 | break; | 786 | break; |
| 770 | } | 787 | } |
| 771 | case 'q': { | 788 | case 'q': { |
| @@ -775,7 +792,7 @@ static int str_format (lua_State *L) { · 3 unmodified lines | |||
| 775 | case 's': { | 792 | case 's': { |
| 776 | size_t l; | 793 | size_t l; |
| 777 | const char *s = luaL_checklstring(L, arg, &l); | 794 | const char *s = luaL_checklstring(L, arg, &l); |
| 778 | if (!hasprecision && l >= 100) { | 795 | if (!strchr(form, '.') && l >= 100) { |
| 779 | /* no precision and string is too long to be formatted; | 796 | /* no precision and string is too long to be formatted; |
| 780 | keep original string */ | 797 | keep original string */ |
| 781 | lua_pushvalue(L, arg); | 798 | lua_pushvalue(L, arg); |
| @@ -820,7 +837,7 @@ static const luaL_Reg strlib[] = { · 38 unmodified lines | |||
| 820 | 837 | ||
| 821 | 838 | ||
| 822 | static void createmetatable (lua_State *L) { | 839 | static void createmetatable (lua_State *L) { |
| 823 | lua_newtable(L); /* create metatable for strings */ | 840 | lua_createtable(L, 0, 1); /* create metatable for strings */ |
| 824 | lua_pushliteral(L, ""); /* dummy string */ | 841 | lua_pushliteral(L, ""); /* dummy string */ |
| 825 | lua_pushvalue(L, -2); | 842 | lua_pushvalue(L, -2); |
| 826 | lua_setmetatable(L, -2); /* set string metatable */ | 843 | lua_setmetatable(L, -2); /* set string metatable */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.27 2005/10/24 17:37:52 roberto Exp $ | 2 | ** $Id: ltable.c,v 2.31 2006/01/10 13:13:06 roberto Exp $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -66,13 +66,15 @@ · 60 unmodified lines | |||
| 66 | /* | 66 | /* |
| 67 | ** number of ints inside a lua_Number | 67 | ** number of ints inside a lua_Number |
| 68 | */ | 68 | */ |
| 69 | #define numints cast(int, sizeof(lua_Number)/sizeof(int)) | 69 | #define numints cast_int(sizeof(lua_Number)/sizeof(int)) |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | const Node luaH_dummynode = { | 73 | #define dummynode (&dummynode_) |
| 74 | |||
| 75 | static const Node dummynode_ = { | ||
| 74 | {{NULL}, LUA_TNIL}, /* value */ | 76 | {{NULL}, LUA_TNIL}, /* value */ |
| 75 | {{NULL}, LUA_TNIL, NULL} /* key */ | 77 | {{{NULL}, LUA_TNIL, NULL}} /* key */ |
| 76 | }; | 78 | }; |
| 77 | 79 | ||
| 78 | 80 | ||
| @@ -95,7 +97,7 @@ static Node *hashnum (const Table *t, lua_Number n) { · 16 unmodified lines | |||
| 95 | ** returns the `main' position of an element in a table (that is, the index | 97 | ** returns the `main' position of an element in a table (that is, the index |
| 96 | ** of its hash value) | 98 | ** of its hash value) |
| 97 | */ | 99 | */ |
| 98 | Node *luaH_mainposition (const Table *t, const TValue *key) { | 100 | static Node *mainposition (const Table *t, const TValue *key) { |
| 99 | switch (ttype(key)) { | 101 | switch (ttype(key)) { |
| 100 | case LUA_TNUMBER: | 102 | case LUA_TNUMBER: |
| 101 | return hashnum(t, nvalue(key)); | 103 | return hashnum(t, nvalue(key)); |
| @@ -120,7 +122,7 @@ static int arrayindex (const TValue *key) { · 18 unmodified lines | |||
| 120 | lua_Number n = nvalue(key); | 122 | lua_Number n = nvalue(key); |
| 121 | int k; | 123 | int k; |
| 122 | lua_number2int(k, n); | 124 | lua_number2int(k, n); |
| 123 | if (luai_numeq(cast(lua_Number, k), nvalue(key))) | 125 | if (luai_numeq(cast_num(k), nvalue(key))) |
| 124 | return k; | 126 | return k; |
| 125 | } | 127 | } |
| 126 | return -1; /* `key' did not match some condition */ | 128 | return -1; /* `key' did not match some condition */ |
| @@ -139,13 +141,13 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 12 unmodified lines | |||
| 139 | if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ | 141 | if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ |
| 140 | return i-1; /* yes; that's the index (corrected to C) */ | 142 | return i-1; /* yes; that's the index (corrected to C) */ |
| 141 | else { | 143 | else { |
| 142 | Node *n = luaH_mainposition(t, key); | 144 | Node *n = mainposition(t, key); |
| 143 | do { /* check whether `key' is somewhere in the chain */ | 145 | do { /* check whether `key' is somewhere in the chain */ |
| 144 | /* key may be dead already, but it is ok to use it in `next' */ | 146 | /* key may be dead already, but it is ok to use it in `next' */ |
| 145 | if (luaO_rawequalObj(key2tval(n), key) || | 147 | if (luaO_rawequalObj(key2tval(n), key) || |
| 146 | (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && | 148 | (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && |
| 147 | gcvalue(gkey(n)) == gcvalue(key))) { | 149 | gcvalue(gkey(n)) == gcvalue(key))) { |
| 148 | i = cast(int, n - gnode(t, 0)); /* key index in hash table */ | 150 | i = cast_int(n - gnode(t, 0)); /* key index in hash table */ |
| 149 | /* hash elements are numbered after array ones */ | 151 | /* hash elements are numbered after array ones */ |
| 150 | return i + t->sizearray; | 152 | return i + t->sizearray; |
| 151 | } | 153 | } |
| @@ -161,7 +163,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { · 9 unmodified lines | |||
| 161 | int i = findindex(L, t, key); /* find original element */ | 163 | int i = findindex(L, t, key); /* find original element */ |
| 162 | for (i++; i < t->sizearray; i++) { /* try first array part */ | 164 | for (i++; i < t->sizearray; i++) { /* try first array part */ |
| 163 | if (!ttisnil(&t->array[i])) { /* a non-nil value? */ | 165 | if (!ttisnil(&t->array[i])) { /* a non-nil value? */ |
| 164 | setnvalue(key, cast(lua_Number, i+1)); | 166 | setnvalue(key, cast_num(i+1)); |
| 165 | setobj2s(L, key+1, &t->array[i]); | 167 | setobj2s(L, key+1, &t->array[i]); |
| 166 | return 1; | 168 | return 1; |
| 167 | } | 169 | } |
| @@ -270,7 +272,7 @@ static void setarrayvector (lua_State *L, Table *t, int size) { · 102 unmodified lines | |||
| 270 | static void setnodevector (lua_State *L, Table *t, int size) { | 272 | static void setnodevector (lua_State *L, Table *t, int size) { |
| 271 | int lsize; | 273 | int lsize; |
| 272 | if (size == 0) { /* no elements to hash part? */ | 274 | if (size == 0) { /* no elements to hash part? */ |
| 273 | t->node = cast(Node *, &luaH_dummynode); /* use common `dummynode' */ | 275 | t->node = cast(Node *, dummynode); /* use common `dummynode' */ |
| 274 | lsize = 0; | 276 | lsize = 0; |
| 275 | } | 277 | } |
| 276 | else { | 278 | else { |
| @@ -281,12 +283,13 @@ static void setnodevector (lua_State *L, Table *t, int size) { · 4 unmodified lines | |||
| 281 | size = twoto(lsize); | 283 | size = twoto(lsize); |
| 282 | t->node = luaM_newvector(L, size, Node); | 284 | t->node = luaM_newvector(L, size, Node); |
| 283 | for (i=0; i<size; i++) { | 285 | for (i=0; i<size; i++) { |
| 284 | gnext(&t->node[i]) = NULL; | 286 | Node *n = gnode(t, i); |
| 285 | setnilvalue(gkey(gnode(t, i))); | 287 | gnext(n) = NULL; |
| 286 | setnilvalue(gval(gnode(t, i))); | 288 | setnilvalue(gkey(n)); |
| 289 | setnilvalue(gval(n)); | ||
| 287 | } | 290 | } |
| 288 | } | 291 | } |
| 289 | t->lsizenode = cast(lu_byte, lsize); | 292 | t->lsizenode = cast_byte(lsize); |
| 290 | t->lastfree = gnode(t, size); /* all positions are free */ | 293 | t->lastfree = gnode(t, size); /* all positions are free */ |
| 291 | } | 294 | } |
| 292 | 295 | ||
| @@ -316,13 +319,13 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) { · 23 unmodified lines | |||
| 316 | if (!ttisnil(gval(old))) | 319 | if (!ttisnil(gval(old))) |
| 317 | setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); | 320 | setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); |
| 318 | } | 321 | } |
| 319 | if (nold != &luaH_dummynode) | 322 | if (nold != dummynode) |
| 320 | luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ | 323 | luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ |
| 321 | } | 324 | } |
| 322 | 325 | ||
| 323 | 326 | ||
| 324 | void luaH_resizearray (lua_State *L, Table *t, int nasize) { | 327 | void luaH_resizearray (lua_State *L, Table *t, int nasize) { |
| 325 | int nsize = (t->node == &luaH_dummynode) ? 0 : sizenode(t); | 328 | int nsize = (t->node == dummynode) ? 0 : sizenode(t); |
| 326 | resize(L, t, nasize, nsize); | 329 | resize(L, t, nasize, nsize); |
| 327 | } | 330 | } |
| 328 | 331 | ||
| @@ -356,12 +359,12 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 27 unmodified lines | |||
| 356 | Table *t = luaM_new(L, Table); | 359 | Table *t = luaM_new(L, Table); |
| 357 | luaC_link(L, obj2gco(t), LUA_TTABLE); | 360 | luaC_link(L, obj2gco(t), LUA_TTABLE); |
| 358 | t->metatable = NULL; | 361 | t->metatable = NULL; |
| 359 | t->flags = cast(lu_byte, ~0); | 362 | t->flags = cast_byte(~0); |
| 360 | /* temporary values (kept only if some malloc fails) */ | 363 | /* temporary values (kept only if some malloc fails) */ |
| 361 | t->array = NULL; | 364 | t->array = NULL; |
| 362 | t->sizearray = 0; | 365 | t->sizearray = 0; |
| 363 | t->lsizenode = 0; | 366 | t->lsizenode = 0; |
| 364 | t->node = cast(Node *, &luaH_dummynode); | 367 | t->node = cast(Node *, dummynode); |
| 365 | setarrayvector(L, t, narray); | 368 | setarrayvector(L, t, narray); |
| 366 | setnodevector(L, t, nhash); | 369 | setnodevector(L, t, nhash); |
| 367 | return t; | 370 | return t; |
| @@ -369,7 +372,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 1 unmodified line | |||
| 369 | 372 | ||
| 370 | 373 | ||
| 371 | void luaH_free (lua_State *L, Table *t) { | 374 | void luaH_free (lua_State *L, Table *t) { |
| 372 | if (t->node != &luaH_dummynode) | 375 | if (t->node != dummynode) |
| 373 | luaM_freearray(L, t->node, sizenode(t), Node); | 376 | luaM_freearray(L, t->node, sizenode(t), Node); |
| 374 | luaM_freearray(L, t->array, t->sizearray, TValue); | 377 | luaM_freearray(L, t->array, t->sizearray, TValue); |
| 375 | luaM_free(L, t); | 378 | luaM_free(L, t); |
| @@ -394,16 +397,16 @@ static Node *getfreepos (Table *t) { · 18 unmodified lines | |||
| 394 | ** position), new key goes to an empty position. | 397 | ** position), new key goes to an empty position. |
| 395 | */ | 398 | */ |
| 396 | static TValue *newkey (lua_State *L, Table *t, const TValue *key) { | 399 | static TValue *newkey (lua_State *L, Table *t, const TValue *key) { |
| 397 | Node *mp = luaH_mainposition(t, key); | 400 | Node *mp = mainposition(t, key); |
| 398 | if (!ttisnil(gval(mp)) || mp == &luaH_dummynode) { | 401 | if (!ttisnil(gval(mp)) || mp == dummynode) { |
| 399 | Node *othern; | 402 | Node *othern; |
| 400 | Node *n = getfreepos(t); /* get a free place */ | 403 | Node *n = getfreepos(t); /* get a free place */ |
| 401 | if (n == NULL) { /* cannot find a free place? */ | 404 | if (n == NULL) { /* cannot find a free place? */ |
| 402 | rehash(L, t, key); /* grow table */ | 405 | rehash(L, t, key); /* grow table */ |
| 403 | return luaH_set(L, t, key); /* re-insert key into grown table */ | 406 | return luaH_set(L, t, key); /* re-insert key into grown table */ |
| 404 | } | 407 | } |
| 405 | lua_assert(n != &luaH_dummynode); | 408 | lua_assert(n != dummynode); |
| 406 | othern = luaH_mainposition(t, key2tval(mp)); | 409 | othern = mainposition(t, key2tval(mp)); |
| 407 | if (othern != mp) { /* is colliding node out of its main position? */ | 410 | if (othern != mp) { /* is colliding node out of its main position? */ |
| 408 | /* yes; move colliding node into free position */ | 411 | /* yes; move colliding node into free position */ |
| 409 | while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ | 412 | while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ |
| @@ -434,14 +437,14 @@ const TValue *luaH_getnum (Table *t, int key) { · 24 unmodified lines | |||
| 434 | if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) | 437 | if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) |
| 435 | return &t->array[key-1]; | 438 | return &t->array[key-1]; |
| 436 | else { | 439 | else { |
| 437 | lua_Number nk = cast(lua_Number, key); | 440 | lua_Number nk = cast_num(key); |
| 438 | Node *n = hashnum(t, nk); | 441 | Node *n = hashnum(t, nk); |
| 439 | do { /* check whether `key' is somewhere in the chain */ | 442 | do { /* check whether `key' is somewhere in the chain */ |
| 440 | if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) | 443 | if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) |
| 441 | return gval(n); /* that's it */ | 444 | return gval(n); /* that's it */ |
| 442 | else n = gnext(n); | 445 | else n = gnext(n); |
| 443 | } while (n); | 446 | } while (n); |
| 444 | return &luaO_nilobject; | 447 | return luaO_nilobject; |
| 445 | } | 448 | } |
| 446 | } | 449 | } |
| 447 | 450 | ||
| @@ -456,7 +459,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 8 unmodified lines | |||
| 456 | return gval(n); /* that's it */ | 459 | return gval(n); /* that's it */ |
| 457 | else n = gnext(n); | 460 | else n = gnext(n); |
| 458 | } while (n); | 461 | } while (n); |
| 459 | return &luaO_nilobject; | 462 | return luaO_nilobject; |
| 460 | } | 463 | } |
| 461 | 464 | ||
| 462 | 465 | ||
| @@ -465,24 +468,24 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 2 unmodified lines | |||
| 465 | */ | 468 | */ |
| 466 | const TValue *luaH_get (Table *t, const TValue *key) { | 469 | const TValue *luaH_get (Table *t, const TValue *key) { |
| 467 | switch (ttype(key)) { | 470 | switch (ttype(key)) { |
| 468 | case LUA_TNIL: return &luaO_nilobject; | 471 | case LUA_TNIL: return luaO_nilobject; |
| 469 | case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); | 472 | case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); |
| 470 | case LUA_TNUMBER: { | 473 | case LUA_TNUMBER: { |
| 471 | int k; | 474 | int k; |
| 472 | lua_Number n = nvalue(key); | 475 | lua_Number n = nvalue(key); |
| 473 | lua_number2int(k, n); | 476 | lua_number2int(k, n); |
| 474 | if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */ | 477 | if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ |
| 475 | return luaH_getnum(t, k); /* use specialized version */ | 478 | return luaH_getnum(t, k); /* use specialized version */ |
| 476 | /* else go through */ | 479 | /* else go through */ |
| 477 | } | 480 | } |
| 478 | default: { | 481 | default: { |
| 479 | Node *n = luaH_mainposition(t, key); | 482 | Node *n = mainposition(t, key); |
| 480 | do { /* check whether `key' is somewhere in the chain */ | 483 | do { /* check whether `key' is somewhere in the chain */ |
| 481 | if (luaO_rawequalObj(key2tval(n), key)) | 484 | if (luaO_rawequalObj(key2tval(n), key)) |
| 482 | return gval(n); /* that's it */ | 485 | return gval(n); /* that's it */ |
| 483 | else n = gnext(n); | 486 | else n = gnext(n); |
| 484 | } while (n); | 487 | } while (n); |
| 485 | return &luaO_nilobject; | 488 | return luaO_nilobject; |
| 486 | } | 489 | } |
| 487 | } | 490 | } |
| 488 | } | 491 | } |
| @@ -491,11 +494,11 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 2 unmodified lines | |||
| 491 | TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | 494 | TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { |
| 492 | const TValue *p = luaH_get(t, key); | 495 | const TValue *p = luaH_get(t, key); |
| 493 | t->flags = 0; | 496 | t->flags = 0; |
| 494 | if (p != &luaO_nilobject) | 497 | if (p != luaO_nilobject) |
| 495 | return cast(TValue *, p); | 498 | return cast(TValue *, p); |
| 496 | else { | 499 | else { |
| 497 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | 500 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); |
| 498 | else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key))) | 501 | else if (ttisnumber(key) && luai_numisnan(nvalue(key))) |
| 499 | luaG_runerror(L, "table index is NaN"); | 502 | luaG_runerror(L, "table index is NaN"); |
| 500 | return newkey(L, t, key); | 503 | return newkey(L, t, key); |
| 501 | } | 504 | } |
| @@ -504,11 +507,11 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 2 unmodified lines | |||
| 504 | 507 | ||
| 505 | TValue *luaH_setnum (lua_State *L, Table *t, int key) { | 508 | TValue *luaH_setnum (lua_State *L, Table *t, int key) { |
| 506 | const TValue *p = luaH_getnum(t, key); | 509 | const TValue *p = luaH_getnum(t, key); |
| 507 | if (p != &luaO_nilobject) | 510 | if (p != luaO_nilobject) |
| 508 | return cast(TValue *, p); | 511 | return cast(TValue *, p); |
| 509 | else { | 512 | else { |
| 510 | TValue k; | 513 | TValue k; |
| 511 | setnvalue(&k, cast(lua_Number, key)); | 514 | setnvalue(&k, cast_num(key)); |
| 512 | return newkey(L, t, &k); | 515 | return newkey(L, t, &k); |
| 513 | } | 516 | } |
| 514 | } | 517 | } |
| @@ -516,7 +519,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) { · 1 unmodified line | |||
| 516 | 519 | ||
| 517 | TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { | 520 | TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { |
| 518 | const TValue *p = luaH_getstr(t, key); | 521 | const TValue *p = luaH_getstr(t, key); |
| 519 | if (p != &luaO_nilobject) | 522 | if (p != luaO_nilobject) |
| 520 | return cast(TValue *, p); | 523 | return cast(TValue *, p); |
| 521 | else { | 524 | else { |
| 522 | TValue k; | 525 | TValue k; |
| @@ -528,11 +531,11 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { · 5 unmodified lines | |||
| 528 | 531 | ||
| 529 | static int unbound_search (Table *t, unsigned int j) { | 532 | static int unbound_search (Table *t, unsigned int j) { |
| 530 | unsigned int i = j; /* i is zero or a present index */ | 533 | unsigned int i = j; /* i is zero or a present index */ |
| 531 | j = j+1; | 534 | j++; |
| 532 | /* find `i' and `j' such that i is present and j is not */ | 535 | /* find `i' and `j' such that i is present and j is not */ |
| 533 | while (!ttisnil(luaH_getnum(t, j))) { | 536 | while (!ttisnil(luaH_getnum(t, j))) { |
| 534 | i = j; | 537 | i = j; |
| 535 | j = i*2; | 538 | j *= 2; |
| 536 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ | 539 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ |
| 537 | /* table was built with bad purposes: resort to linear search */ | 540 | /* table was built with bad purposes: resort to linear search */ |
| 538 | i = 1; | 541 | i = 1; |
| @@ -541,7 +544,7 @@ static int unbound_search (Table *t, unsigned int j) { · 2 unmodified lines | |||
| 541 | } | 544 | } |
| 542 | } | 545 | } |
| 543 | /* now do a binary search between them */ | 546 | /* now do a binary search between them */ |
| 544 | while (i < j-1) { | 547 | while (j - i > 1) { |
| 545 | unsigned int m = (i+j)/2; | 548 | unsigned int m = (i+j)/2; |
| 546 | if (ttisnil(luaH_getnum(t, m))) j = m; | 549 | if (ttisnil(luaH_getnum(t, m))) j = m; |
| 547 | else i = m; | 550 | else i = m; |
| @@ -567,8 +570,19 @@ int luaH_getn (Table *t) { · 19 unmodified lines | |||
| 567 | return i; | 570 | return i; |
| 568 | } | 571 | } |
| 569 | /* else must find a boundary in hash part */ | 572 | /* else must find a boundary in hash part */ |
| 570 | else if (t->node == &luaH_dummynode) /* hash part is empty? */ | 573 | else if (t->node == dummynode) /* hash part is empty? */ |
| 571 | return j; /* that is easy... */ | 574 | return j; /* that is easy... */ |
| 572 | else return unbound_search(t, j); | 575 | else return unbound_search(t, j); |
| 573 | } | 576 | } |
| 574 | 577 | ||
| 578 | |||
| 579 | |||
| 580 | #if defined(LUA_DEBUG) | ||
| 581 | |||
| 582 | Node *luaH_mainposition (const Table *t, const TValue *key) { | ||
| 583 | return mainposition(t, key); | ||
| 584 | } | ||
| 585 | |||
| 586 | int luaH_isdummy (Node *n) { return n == dummynode; } | ||
| 587 | |||
| 588 | #endif | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.h,v 2.8 2005/06/06 13:30:25 roberto Exp $ | 2 | ** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -11,15 +11,13 @@ · 5 unmodified lines | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | #define gnode(t,i) (&(t)->node[i]) | 13 | #define gnode(t,i) (&(t)->node[i]) |
| 14 | #define gkey(n) (&(n)->i_key) | 14 | #define gkey(n) (&(n)->i_key.nk) |
| 15 | #define gval(n) (&(n)->i_val) | 15 | #define gval(n) (&(n)->i_val) |
| 16 | #define gnext(n) ((n)->i_key.next) | 16 | #define gnext(n) ((n)->i_key.nk.next) |
| 17 | 17 | ||
| 18 | #define key2tval(n) (cast(const TValue *, gkey(n))) | 18 | #define key2tval(n) (&(n)->i_key.tvk) |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | LUAI_DATA const Node luaH_dummynode; | ||
| 22 | |||
| 23 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); |
| 24 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); | 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); |
| 25 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); | 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); |
| @@ -32,8 +30,11 @@ LUAI_FUNC void luaH_free (lua_State *L, Table *t); · 6 unmodified lines | |||
| 32 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); | 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); |
| 33 | LUAI_FUNC int luaH_getn (Table *t); | 31 | LUAI_FUNC int luaH_getn (Table *t); |
| 34 | 32 | ||
| 35 | /* exported only for debugging */ | 33 | |
| 34 | #if defined(LUA_DEBUG) | ||
| 36 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); | 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); |
| 36 | LUAI_FUNC int luaH_isdummy (Node *n); | ||
| 37 | #endif | ||
| 37 | 38 | ||
| 38 | 39 | ||
| 39 | #endif | 40 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 2.6 2005/05/20 15:53:42 roberto Exp $ | 2 | ** $Id: ltm.c,v 2.8 2006/01/10 12:50:00 roberto Exp $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -51,7 +51,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { · 45 unmodified lines | |||
| 51 | const TValue *tm = luaH_getstr(events, ename); | 51 | const TValue *tm = luaH_getstr(events, ename); |
| 52 | lua_assert(event <= TM_EQ); | 52 | lua_assert(event <= TM_EQ); |
| 53 | if (ttisnil(tm)) { /* no tag method? */ | 53 | if (ttisnil(tm)) { /* no tag method? */ |
| 54 | events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */ | 54 | events->flags |= cast_byte(1u<<event); /* cache this fact */ |
| 55 | return NULL; | 55 | return NULL; |
| 56 | } | 56 | } |
| 57 | else return tm; | 57 | else return tm; |
| @@ -70,6 +70,6 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { · 12 unmodified lines | |||
| 70 | default: | 70 | default: |
| 71 | mt = G(L)->mt[ttype(o)]; | 71 | mt = G(L)->mt[ttype(o)]; |
| 72 | } | 72 | } |
| 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject); | 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.154 2005/10/24 17:38:47 roberto Exp $ | 2 | ** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -120,7 +120,7 @@ static int getargs (lua_State *L, char **argv, int n) { · 114 unmodified lines | |||
| 120 | luaL_checkstack(L, narg + 3, "too many arguments to script"); | 120 | luaL_checkstack(L, narg + 3, "too many arguments to script"); |
| 121 | for (i=n+1; i < argc; i++) | 121 | for (i=n+1; i < argc; i++) |
| 122 | lua_pushstring(L, argv[i]); | 122 | lua_pushstring(L, argv[i]); |
| 123 | lua_newtable(L); | 123 | lua_createtable(L, narg, n + 1); |
| 124 | for (i=0; i < argc; i++) { | 124 | for (i=0; i < argc; i++) { |
| 125 | lua_pushstring(L, argv[i]); | 125 | lua_pushstring(L, argv[i]); |
| 126 | lua_rawseti(L, -2, i - n); | 126 | lua_rawseti(L, -2, i - n); |
| @@ -215,7 +215,6 @@ static void dotty (lua_State *L) { · 88 unmodified lines | |||
| 215 | int status; | 215 | int status; |
| 216 | const char *oldprogname = progname; | 216 | const char *oldprogname = progname; |
| 217 | progname = NULL; | 217 | progname = NULL; |
| 218 | print_version(); | ||
| 219 | while ((status = loadline(L)) != -1) { | 218 | while ((status = loadline(L)) != -1) { |
| 220 | if (status == 0) status = docall(L, 0, 0); | 219 | if (status == 0) status = docall(L, 0, 0); |
| 221 | report(L, status); | 220 | report(L, status); |
| @@ -261,7 +260,7 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 39 unmodified lines | |||
| 261 | switch (argv[i][1]) { /* option */ | 260 | switch (argv[i][1]) { /* option */ |
| 262 | case '-': return (argv[i+1] != NULL ? i+1 : 0); | 261 | case '-': return (argv[i+1] != NULL ? i+1 : 0); |
| 263 | case '\0': return i; | 262 | case '\0': return i; |
| 264 | case 'i': *pi = 1; break; | 263 | case 'i': *pi = 1; /* go through */ |
| 265 | case 'v': *pv = 1; break; | 264 | case 'v': *pv = 1; break; |
| 266 | case 'e': *pe = 1; /* go through */ | 265 | case 'e': *pe = 1; /* go through */ |
| 267 | case 'l': | 266 | case 'l': |
| @@ -330,7 +329,9 @@ static int pmain (lua_State *L) { · 62 unmodified lines | |||
| 330 | int has_i = 0, has_v = 0, has_e = 0; | 329 | int has_i = 0, has_v = 0, has_e = 0; |
| 331 | globalL = L; | 330 | globalL = L; |
| 332 | if (argv[0] && argv[0][0]) progname = argv[0]; | 331 | if (argv[0] && argv[0][0]) progname = argv[0]; |
| 332 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ | ||
| 333 | luaL_openlibs(L); /* open libraries */ | 333 | luaL_openlibs(L); /* open libraries */ |
| 334 | lua_gc(L, LUA_GCRESTART, 0); | ||
| 334 | s->status = handle_luainit(L); | 335 | s->status = handle_luainit(L); |
| 335 | if (s->status != 0) return 0; | 336 | if (s->status != 0) return 0; |
| 336 | script = collectargs(argv, &has_i, &has_v, &has_e); | 337 | script = collectargs(argv, &has_i, &has_v, &has_e); |
| @@ -348,7 +349,10 @@ static int pmain (lua_State *L) { · 11 unmodified lines | |||
| 348 | if (has_i) | 349 | if (has_i) |
| 349 | dotty(L); | 350 | dotty(L); |
| 350 | else if (script == 0 && !has_e && !has_v) { | 351 | else if (script == 0 && !has_e && !has_v) { |
| 351 | if (lua_stdin_is_tty()) dotty(L); | 352 | if (lua_stdin_is_tty()) { |
| 353 | print_version(); | ||
| 354 | dotty(L); | ||
| 355 | } | ||
| 352 | else dofile(L, NULL); /* executes stdin as a file */ | 356 | else dofile(L, NULL); /* executes stdin as a file */ |
| 353 | } | 357 | } |
| 354 | return 0; | 358 | return 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.214 2005/10/20 11:35:50 roberto Exp $ | 2 | ** $Id: lua.h,v 1.216 2006/01/10 12:50:13 roberto Exp $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
| @@ -16,9 +16,9 @@ · 10 unmodified lines | |||
| 16 | #include "luaconf.h" | 16 | #include "luaconf.h" |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | #define LUA_VERSION "Lua 5.1 (beta)" | 19 | #define LUA_VERSION "Lua 5.1" |
| 20 | #define LUA_VERSION_NUM 501 | 20 | #define LUA_VERSION_NUM 501 |
| 21 | #define LUA_COPYRIGHT "Copyright (C) 1994-2005 Lua.org, PUC-Rio" | 21 | #define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio" |
| 22 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" | 22 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" |
| 23 | 23 | ||
| 24 | 24 | ||
| @@ -358,7 +358,7 @@ struct lua_Debug { · 333 unmodified lines | |||
| 358 | 358 | ||
| 359 | 359 | ||
| 360 | /****************************************************************************** | 360 | /****************************************************************************** |
| 361 | * Copyright (C) 1994-2005 Lua.org, PUC-Rio. All rights reserved. | 361 | * Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved. |
| 362 | * | 362 | * |
| 363 | * Permission is hereby granted, free of charge, to any person obtaining | 363 | * Permission is hereby granted, free of charge, to any person obtaining |
| 364 | * a copy of this software and associated documentation files (the | 364 | * a copy of this software and associated documentation files (the |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.74 2005/11/16 16:24:28 roberto Exp $ | 2 | ** $Id: luaconf.h,v 1.77 2005/12/27 17:12:00 roberto Exp $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -28,6 +28,11 @@ · 22 unmodified lines | |||
| 28 | #define LUA_ANSI | 28 | #define LUA_ANSI |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | |||
| 32 | #if !defined(LUA_ANSI) && defined(_WIN32) | ||
| 33 | #define LUA_WIN | ||
| 34 | #endif | ||
| 35 | |||
| 31 | #if defined(LUA_USE_LINUX) | 36 | #if defined(LUA_USE_LINUX) |
| 32 | #define LUA_USE_POSIX | 37 | #define LUA_USE_POSIX |
| 33 | #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ | 38 | #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ |
| @@ -177,13 +182,6 @@ · 143 unmodified lines | |||
| 177 | 182 | ||
| 178 | 183 | ||
| 179 | 184 | ||
| 180 | /* | ||
| 181 | @@ lua_assert describes the internal assertions in Lua. | ||
| 182 | ** CHANGE that only if you need to debug Lua. | ||
| 183 | */ | ||
| 184 | #define lua_assert(c) ((void)0) | ||
| 185 | |||
| 186 | |||
| 187 | /* | 185 | /* |
| 188 | @@ LUA_QL describes how error messages quote program elements. | 186 | @@ LUA_QL describes how error messages quote program elements. |
| 189 | ** CHANGE it if you want a different appearance. | 187 | ** CHANGE it if you want a different appearance. |
| @@ -217,7 +215,7 @@ · 27 unmodified lines | |||
| 217 | #if defined(LUA_USE_ISATTY) | 215 | #if defined(LUA_USE_ISATTY) |
| 218 | #include <unistd.h> | 216 | #include <unistd.h> |
| 219 | #define lua_stdin_is_tty() isatty(0) | 217 | #define lua_stdin_is_tty() isatty(0) |
| 220 | #elif !defined(LUA_ANSI) && defined(_WIN32) | 218 | #elif defined(LUA_WIN) |
| 221 | #include <io.h> | 219 | #include <io.h> |
| 222 | #include <stdio.h> | 220 | #include <stdio.h> |
| 223 | #define lua_stdin_is_tty() _isatty(_fileno(stdin)) | 221 | #define lua_stdin_is_tty() _isatty(_fileno(stdin)) |
| @@ -368,8 +366,7 @@ · 144 unmodified lines | |||
| 368 | #include <assert.h> | 366 | #include <assert.h> |
| 369 | #define luai_apicheck(L,o) { (void)L; assert(o); } | 367 | #define luai_apicheck(L,o) { (void)L; assert(o); } |
| 370 | #else | 368 | #else |
| 371 | /* (By default lua_assert is empty, so luai_apicheck is also empty.) */ | 369 | #define luai_apicheck(L,o) { (void)L; } |
| 372 | #define luai_apicheck(L,o) { (void)L; lua_assert(o); } | ||
| 373 | #endif | 370 | #endif |
| 374 | 371 | ||
| 375 | 372 | ||
| @@ -529,6 +526,7 @@ · 153 unmodified lines | |||
| 529 | #define luai_numeq(a,b) ((a)==(b)) | 526 | #define luai_numeq(a,b) ((a)==(b)) |
| 530 | #define luai_numlt(a,b) ((a)<(b)) | 527 | #define luai_numlt(a,b) ((a)<(b)) |
| 531 | #define luai_numle(a,b) ((a)<=(b)) | 528 | #define luai_numle(a,b) ((a)<=(b)) |
| 529 | #define luai_numisnan(a) (!luai_numeq((a), (a))) | ||
| 532 | #endif | 530 | #endif |
| 533 | 531 | ||
| 534 | 532 | ||
| @@ -644,7 +642,7 @@ union luai_Cast { double l_d; long l_l; }; · 109 unmodified lines | |||
| 644 | #define lua_popen(L,c,m) ((void)L, popen(c,m)) | 642 | #define lua_popen(L,c,m) ((void)L, popen(c,m)) |
| 645 | #define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) | 643 | #define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) |
| 646 | 644 | ||
| 647 | #elif !defined(LUA_ANSI) && defined(_WIN32) | 645 | #elif defined(LUA_WIN) |
| 648 | 646 | ||
| 649 | #define lua_popen(L,c,m) ((void)L, _popen(c,m)) | 647 | #define lua_popen(L,c,m) ((void)L, _popen(c,m)) |
| 650 | #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) | 648 | #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) |
| @@ -675,7 +673,7 @@ union luai_Cast { double l_d; long l_l; }; · 24 unmodified lines | |||
| 675 | #define LUA_DL_DLOPEN | 673 | #define LUA_DL_DLOPEN |
| 676 | #endif | 674 | #endif |
| 677 | 675 | ||
| 678 | #if !defined(LUA_ANSI) && defined(_WIN32) | 676 | #if defined(LUA_WIN) |
| 679 | #define LUA_DL_DLL | 677 | #define LUA_DL_DLL |
| 680 | #endif | 678 | #endif |
| 681 | 679 | ||
| @@ -702,6 +700,26 @@ union luai_Cast { double l_d; long l_l; }; · 20 unmodified lines | |||
| 702 | #define luai_userstateyield(L,n) ((void)L) | 700 | #define luai_userstateyield(L,n) ((void)L) |
| 703 | 701 | ||
| 704 | 702 | ||
| 703 | /* | ||
| 704 | @@ LUA_INTFRMLEN is the length modifier for integer conversions | ||
| 705 | @* in 'string.fomat'. | ||
| 706 | @@ LUA_INTFRM_T is the integer type correspoding to the previous length | ||
| 707 | @* modifier. | ||
| 708 | ** CHANGE them if your system supports long long or does not support long. | ||
| 709 | */ | ||
| 710 | |||
| 711 | #if defined(LUA_USELONGLONG) | ||
| 712 | |||
| 713 | #define LUA_INTFRMLEN "ll" | ||
| 714 | #define LUA_INTFRM_T long long | ||
| 715 | |||
| 716 | #else | ||
| 717 | |||
| 718 | #define LUA_INTFRMLEN "l" | ||
| 719 | #define LUA_INTFRM_T long | ||
| 720 | |||
| 721 | #endif | ||
| 722 | |||
| 705 | 723 | ||
| 706 | 724 | ||
| 707 | /* =================================================================== */ | 725 | /* =================================================================== */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lualib.h,v 1.35 2005/08/10 18:06:58 roberto Exp $ | 2 | ** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $ |
| 3 | ** Lua standard libraries | 3 | ** Lua standard libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,4 +44,10 @@ LUALIB_API int (luaopen_package) (lua_State *L); · 38 unmodified lines | |||
| 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); | 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | |||
| 48 | #ifndef lua_assert | ||
| 49 | #define lua_assert(x) ((void)0) | ||
| 50 | #endif | ||
| 51 | |||
| 52 | |||
| 47 | #endif | 53 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.59 2005/11/01 16:08:45 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.61 2006/01/10 12:50:00 roberto Exp $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -509,16 +509,16 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 503 unmodified lines | |||
| 509 | const TValue *rb = RB(i); | 509 | const TValue *rb = RB(i); |
| 510 | switch (ttype(rb)) { | 510 | switch (ttype(rb)) { |
| 511 | case LUA_TTABLE: { | 511 | case LUA_TTABLE: { |
| 512 | setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); | 512 | setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); |
| 513 | break; | 513 | break; |
| 514 | } | 514 | } |
| 515 | case LUA_TSTRING: { | 515 | case LUA_TSTRING: { |
| 516 | setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); | 516 | setnvalue(ra, cast_num(tsvalue(rb)->len)); |
| 517 | break; | 517 | break; |
| 518 | } | 518 | } |
| 519 | default: { /* try metamethod */ | 519 | default: { /* try metamethod */ |
| 520 | Protect( | 520 | Protect( |
| 521 | if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN)) | 521 | if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) |
| 522 | luaG_typeerror(L, rb, "get length of"); | 522 | luaG_typeerror(L, rb, "get length of"); |
| 523 | ) | 523 | ) |
| 524 | } | 524 | } |
| @@ -693,10 +693,10 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 168 unmodified lines | |||
| 693 | int last; | 693 | int last; |
| 694 | Table *h; | 694 | Table *h; |
| 695 | if (n == 0) { | 695 | if (n == 0) { |
| 696 | n = cast(int, L->top - ra) - 1; | 696 | n = cast_int(L->top - ra) - 1; |
| 697 | L->top = L->ci->top; | 697 | L->top = L->ci->top; |
| 698 | } | 698 | } |
| 699 | if (c == 0) c = cast(int, *pc++); | 699 | if (c == 0) c = cast_int(*pc++); |
| 700 | runtime_check(L, ttistable(ra)); | 700 | runtime_check(L, ttistable(ra)); |
| 701 | h = hvalue(ra); | 701 | h = hvalue(ra); |
| 702 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; | 702 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; |
| @@ -737,7 +737,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 34 unmodified lines | |||
| 737 | int b = GETARG_B(i) - 1; | 737 | int b = GETARG_B(i) - 1; |
| 738 | int j; | 738 | int j; |
| 739 | CallInfo *ci = L->ci; | 739 | CallInfo *ci = L->ci; |
| 740 | int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1; | 740 | int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; |
| 741 | if (b == LUA_MULTRET) { | 741 | if (b == LUA_MULTRET) { |
| 742 | Protect(luaD_checkstack(L, n)); | 742 | Protect(luaD_checkstack(L, n)); |
| 743 | ra = RA(i); /* previous call may change the stack */ | 743 | ra = RA(i); /* previous call may change the stack */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: print.c,v 1.53 2005/11/11 14:03:13 lhf Exp $ | 2 | ** $Id: print.c,v 1.54 2006/01/11 22:49:27 lhf Exp $ |
| 3 | ** print bytecodes | 3 | ** print bytecodes |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -36,7 +36,10 @@ static void PrintString(const Proto* f, int n) · 30 unmodified lines | |||
| 36 | case '\r': printf("\\r"); break; | 36 | case '\r': printf("\\r"); break; |
| 37 | case '\t': printf("\\t"); break; | 37 | case '\t': printf("\\t"); break; |
| 38 | case '\v': printf("\\v"); break; | 38 | case '\v': printf("\\v"); break; |
| 39 | default: printf(isprint((unsigned char)*s) ? "%c" : "\\%03d",*s); | 39 | default: if (isprint((unsigned char)*s)) |
| 40 | printf("%c",*s); | ||
| 41 | else | ||
| 42 | printf("\\%03u",(unsigned char)*s); | ||
| 40 | } | 43 | } |
| 41 | } | 44 | } |
| 42 | putchar('"'); | 45 | putchar('"'); |