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