diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-06-21 10:52:27 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-06-21 10:52:27 -0300 |
| commit | 8d3dd04137348b604ec9ebee87df84c8ef5fdced (patch) | |
| tree | 291dcb423b3f288145196334d8121dacfe1fa3fa | |
| parent | 791d8d858502f34204e0460c73e5eb6d340bcd92 (diff) | |
| download | lua-8d3dd04137348b604ec9ebee87df84c8ef5fdced.tar.gz lua-8d3dd04137348b604ec9ebee87df84c8ef5fdced.tar.bz2 lua-8d3dd04137348b604ec9ebee87df84c8ef5fdced.zip | |
clearing some old compatibility code
| -rw-r--r-- | lauxlib.c | 90 | ||||
| -rw-r--r-- | lauxlib.h | 14 | ||||
| -rw-r--r-- | lbaselib.c | 4 | ||||
| -rw-r--r-- | lmathlib.c | 6 | ||||
| -rw-r--r-- | loadlib.c | 6 | ||||
| -rw-r--r-- | ltests.c | 12 | ||||
| -rw-r--r-- | luaconf.h | 30 |
7 files changed, 13 insertions, 149 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.166 2007/04/19 20:21:53 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.167 2007/05/15 18:46:12 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -257,12 +257,6 @@ LUALIB_API const char *luaL_tostring (lua_State *L, int idx) { | |||
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | 259 | ||
| 260 | LUALIB_API void luaL_register (lua_State *L, const char *libname, | ||
| 261 | const luaL_Reg *l) { | ||
| 262 | luaI_openlib(L, libname, l, 0); | ||
| 263 | } | ||
| 264 | |||
| 265 | |||
| 266 | static int libsize (const luaL_Reg *l) { | 260 | static int libsize (const luaL_Reg *l) { |
| 267 | int size = 0; | 261 | int size = 0; |
| 268 | for (; l->name; l++) size++; | 262 | for (; l->name; l++) size++; |
| @@ -270,8 +264,8 @@ static int libsize (const luaL_Reg *l) { | |||
| 270 | } | 264 | } |
| 271 | 265 | ||
| 272 | 266 | ||
| 273 | LUALIB_API void luaI_openlib (lua_State *L, const char *libname, | 267 | LUALIB_API void luaL_register (lua_State *L, const char *libname, |
| 274 | const luaL_Reg *l, int nup) { | 268 | const luaL_Reg *l) { |
| 275 | if (libname) { | 269 | if (libname) { |
| 276 | int size = libsize(l); | 270 | int size = libsize(l); |
| 277 | /* check whether lib already exists */ | 271 | /* check whether lib already exists */ |
| @@ -286,88 +280,14 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, | |||
| 286 | lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ | 280 | lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ |
| 287 | } | 281 | } |
| 288 | lua_remove(L, -2); /* remove _LOADED table */ | 282 | lua_remove(L, -2); /* remove _LOADED table */ |
| 289 | lua_insert(L, -(nup+1)); /* move library table to below upvalues */ | ||
| 290 | } | 283 | } |
| 291 | for (; l->name; l++) { | 284 | for (; l->name; l++) { |
| 292 | int i; | 285 | lua_pushcfunction(L, l->func); |
| 293 | for (i=0; i<nup; i++) /* copy upvalues to the top */ | 286 | lua_setfield(L, -2, l->name); |
| 294 | lua_pushvalue(L, -nup); | ||
| 295 | lua_pushcclosure(L, l->func, nup); | ||
| 296 | lua_setfield(L, -(nup+2), l->name); | ||
| 297 | } | ||
| 298 | lua_pop(L, nup); /* remove upvalues */ | ||
| 299 | } | ||
| 300 | |||
| 301 | |||
| 302 | |||
| 303 | /* | ||
| 304 | ** {====================================================== | ||
| 305 | ** getn-setn: size for arrays | ||
| 306 | ** ======================================================= | ||
| 307 | */ | ||
| 308 | |||
| 309 | #if defined(LUA_COMPAT_GETN) | ||
| 310 | |||
| 311 | static int checkint (lua_State *L, int topop) { | ||
| 312 | int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; | ||
| 313 | lua_pop(L, topop); | ||
| 314 | return n; | ||
| 315 | } | ||
| 316 | |||
| 317 | |||
| 318 | static void getsizes (lua_State *L) { | ||
| 319 | lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); | ||
| 320 | if (lua_isnil(L, -1)) { /* no `size' table? */ | ||
| 321 | lua_pop(L, 1); /* remove nil */ | ||
| 322 | lua_newtable(L); /* create it */ | ||
| 323 | lua_pushvalue(L, -1); /* `size' will be its own metatable */ | ||
| 324 | lua_setmetatable(L, -2); | ||
| 325 | lua_pushliteral(L, "kv"); | ||
| 326 | lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ | ||
| 327 | lua_pushvalue(L, -1); | ||
| 328 | lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ | ||
| 329 | } | ||
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | LUALIB_API void luaL_setn (lua_State *L, int t, int n) { | ||
| 334 | t = abs_index(L, t); | ||
| 335 | lua_pushliteral(L, "n"); | ||
| 336 | lua_rawget(L, t); | ||
| 337 | if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ | ||
| 338 | lua_pushliteral(L, "n"); /* use it */ | ||
| 339 | lua_pushinteger(L, n); | ||
| 340 | lua_rawset(L, t); | ||
| 341 | } | ||
| 342 | else { /* use `sizes' */ | ||
| 343 | getsizes(L); | ||
| 344 | lua_pushvalue(L, t); | ||
| 345 | lua_pushinteger(L, n); | ||
| 346 | lua_rawset(L, -3); /* sizes[t] = n */ | ||
| 347 | lua_pop(L, 1); /* remove `sizes' */ | ||
| 348 | } | 287 | } |
| 349 | } | 288 | } |
| 350 | 289 | ||
| 351 | 290 | ||
| 352 | LUALIB_API int luaL_getn (lua_State *L, int t) { | ||
| 353 | int n; | ||
| 354 | t = abs_index(L, t); | ||
| 355 | lua_pushliteral(L, "n"); /* try t.n */ | ||
| 356 | lua_rawget(L, t); | ||
| 357 | if ((n = checkint(L, 1)) >= 0) return n; | ||
| 358 | getsizes(L); /* else try sizes[t] */ | ||
| 359 | lua_pushvalue(L, t); | ||
| 360 | lua_rawget(L, -2); | ||
| 361 | if ((n = checkint(L, 2)) >= 0) return n; | ||
| 362 | return (int)lua_objlen(L, t); | ||
| 363 | } | ||
| 364 | |||
| 365 | #endif | ||
| 366 | |||
| 367 | /* }====================================================== */ | ||
| 368 | |||
| 369 | |||
| 370 | |||
| 371 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, | 291 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 372 | const char *r) { | 292 | const char *r) { |
| 373 | const char *wild; | 293 | const char *wild; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.89 2007/02/07 17:51:21 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.90 2007/05/15 18:46:12 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -15,18 +15,6 @@ | |||
| 15 | #include "lua.h" | 15 | #include "lua.h" |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | #if defined(LUA_COMPAT_GETN) | ||
| 19 | LUALIB_API int (luaL_getn) (lua_State *L, int t); | ||
| 20 | LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); | ||
| 21 | #else | ||
| 22 | #define luaL_getn(L,i) ((int)lua_objlen(L, i)) | ||
| 23 | #define luaL_setn(L,i,j) ((void)0) /* no op! */ | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if defined(LUA_COMPAT_OPENLIB) | ||
| 27 | #define luaI_openlib luaL_openlib | ||
| 28 | #endif | ||
| 29 | |||
| 30 | 18 | ||
| 31 | /* extra error code for `luaL_load' */ | 19 | /* extra error code for `luaL_load' */ |
| 32 | #define LUA_ERRFILE (LUA_ERRERR+1) | 20 | #define LUA_ERRFILE (LUA_ERRERR+1) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.196 2007/02/07 17:51:21 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.197 2007/02/09 12:40:21 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -343,7 +343,7 @@ static int luaB_unpack (lua_State *L) { | |||
| 343 | int i, e, n; | 343 | int i, e, n; |
| 344 | luaL_checktype(L, 1, LUA_TTABLE); | 344 | luaL_checktype(L, 1, LUA_TTABLE); |
| 345 | i = luaL_optint(L, 2, 1); | 345 | i = luaL_optint(L, 2, 1); |
| 346 | e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); | 346 | e = luaL_opt(L, luaL_checkint, 3, (int)lua_objlen(L, 1)); |
| 347 | n = e - i + 1; /* number of elements */ | 347 | n = e - i + 1; /* number of elements */ |
| 348 | if (n <= 0) return 0; /* empty range */ | 348 | if (n <= 0) return 0; /* empty range */ |
| 349 | luaL_checkstack(L, n, "table too big to unpack"); | 349 | luaL_checkstack(L, n, "table too big to unpack"); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.68 2006/08/07 19:01:56 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.69 2007/03/27 12:37:00 roberto Exp roberto $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -258,10 +258,6 @@ LUALIB_API int luaopen_math (lua_State *L) { | |||
| 258 | lua_setfield(L, -2, "pi"); | 258 | lua_setfield(L, -2, "pi"); |
| 259 | lua_pushnumber(L, HUGE_VAL); | 259 | lua_pushnumber(L, HUGE_VAL); |
| 260 | lua_setfield(L, -2, "huge"); | 260 | lua_setfield(L, -2, "huge"); |
| 261 | #if defined(LUA_COMPAT_MOD) | ||
| 262 | lua_getfield(L, -1, "fmod"); | ||
| 263 | lua_setfield(L, -2, "mod"); | ||
| 264 | #endif | ||
| 265 | return 1; | 261 | return 1; |
| 266 | } | 262 | } |
| 267 | 263 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.56 2006/10/10 17:40:17 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.57 2007/03/26 15:57:35 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -628,10 +628,6 @@ LUALIB_API int luaopen_package (lua_State *L) { | |||
| 628 | lua_setfield(L, -2, "__gc"); | 628 | lua_setfield(L, -2, "__gc"); |
| 629 | /* create `package' table */ | 629 | /* create `package' table */ |
| 630 | luaL_register(L, LUA_LOADLIBNAME, pk_funcs); | 630 | luaL_register(L, LUA_LOADLIBNAME, pk_funcs); |
| 631 | #if defined(LUA_COMPAT_LOADLIB) | ||
| 632 | lua_getfield(L, -1, "loadlib"); | ||
| 633 | lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); | ||
| 634 | #endif | ||
| 635 | lua_pushvalue(L, -1); | 631 | lua_pushvalue(L, -1); |
| 636 | lua_replace(L, LUA_ENVIRONINDEX); | 632 | lua_replace(L, LUA_ENVIRONINDEX); |
| 637 | /* create `loaders' table */ | 633 | /* create `loaders' table */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.41 2007/04/10 12:17:52 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.42 2007/04/17 13:19:53 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -996,16 +996,8 @@ static int testC (lua_State *L) { | |||
| 996 | } | 996 | } |
| 997 | else if EQ("getn") { | 997 | else if EQ("getn") { |
| 998 | int i = getindex; | 998 | int i = getindex; |
| 999 | lua_pushinteger(L1, luaL_getn(L1, i)); | 999 | lua_pushinteger(L1, lua_objlen(L1, i)); |
| 1000 | } | 1000 | } |
| 1001 | #ifndef luaL_setn | ||
| 1002 | else if EQ("setn") { | ||
| 1003 | int i = getindex; | ||
| 1004 | int n = cast_int(lua_tonumber(L1, -1)); | ||
| 1005 | luaL_setn(L1, i, n); | ||
| 1006 | lua_pop(L1, 1); | ||
| 1007 | } | ||
| 1008 | #endif | ||
| 1009 | else if EQ("throw") { | 1001 | else if EQ("throw") { |
| 1010 | #if defined(__cplusplus) | 1002 | #if defined(__cplusplus) |
| 1011 | static struct X { int x; } x; | 1003 | static struct X { int x; } x; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.87 2007/02/07 17:46:20 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.88 2007/05/03 20:49:29 roberto Exp roberto $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -321,20 +321,6 @@ | |||
| 321 | 321 | ||
| 322 | 322 | ||
| 323 | /* | 323 | /* |
| 324 | @@ LUA_COMPAT_GETN controls compatibility with old getn behavior. | ||
| 325 | ** CHANGE it (define it) if you want exact compatibility with the | ||
| 326 | ** behavior of setn/getn in Lua 5.0. | ||
| 327 | */ | ||
| 328 | #undef LUA_COMPAT_GETN | ||
| 329 | |||
| 330 | /* | ||
| 331 | @@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. | ||
| 332 | ** CHANGE it to undefined as soon as you do not need a global 'loadlib' | ||
| 333 | ** function (the function is still available as 'package.loadlib'). | ||
| 334 | */ | ||
| 335 | #undef LUA_COMPAT_LOADLIB | ||
| 336 | |||
| 337 | /* | ||
| 338 | @@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. | 324 | @@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. |
| 339 | ** CHANGE it to undefined as soon as your programs use only '...' to | 325 | ** CHANGE it to undefined as soon as your programs use only '...' to |
| 340 | ** access vararg parameters (instead of the old 'arg' table). | 326 | ** access vararg parameters (instead of the old 'arg' table). |
| @@ -342,26 +328,12 @@ | |||
| 342 | #define LUA_COMPAT_VARARG | 328 | #define LUA_COMPAT_VARARG |
| 343 | 329 | ||
| 344 | /* | 330 | /* |
| 345 | @@ LUA_COMPAT_MOD controls compatibility with old math.mod function. | ||
| 346 | ** CHANGE it to undefined as soon as your programs use 'math.fmod' or | ||
| 347 | ** the new '%' operator instead of 'math.mod'. | ||
| 348 | */ | ||
| 349 | #define LUA_COMPAT_MOD | ||
| 350 | |||
| 351 | /* | ||
| 352 | @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. | 331 | @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. |
| 353 | ** CHANGE it to undefined as soon as you rename 'string.gfind' to | 332 | ** CHANGE it to undefined as soon as you rename 'string.gfind' to |
| 354 | ** 'string.gmatch'. | 333 | ** 'string.gmatch'. |
| 355 | */ | 334 | */ |
| 356 | #define LUA_COMPAT_GFIND | 335 | #define LUA_COMPAT_GFIND |
| 357 | 336 | ||
| 358 | /* | ||
| 359 | @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' | ||
| 360 | @* behavior. | ||
| 361 | ** CHANGE it to undefined as soon as you replace to 'luaL_register' | ||
| 362 | ** your uses of 'luaL_openlib' | ||
| 363 | */ | ||
| 364 | #define LUA_COMPAT_OPENLIB | ||
| 365 | 337 | ||
| 366 | 338 | ||
| 367 | 339 | ||
