瀏覽代碼

'loadstring' deprecated; use 'load' instead

Roberto Ierusalimschy 14 年之前
父節點
當前提交
81646af13b
共有 2 個文件被更改,包括 18 次插入13 次删除
  1. 11 12
      lbaselib.c
  2. 7 1
      luaconf.h

+ 11 - 12
lbaselib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lbaselib.c,v 1.252 2010/12/06 16:25:48 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.253 2010/12/07 11:40:42 roberto Exp roberto $
 ** Basic library
 ** Basic library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -114,12 +114,10 @@ static int luaB_setmetatable (lua_State *L) {
 }
 }
 
 
 
 
-static int luaB_getfenv (lua_State *L) {
-  return luaL_error(L, "getfenv/setfenv deprecated");
+static int luaB_deprecated (lua_State *L) {
+  return luaL_error(L, "deprecated function");
 }
 }
 
 
-#define luaB_setfenv	luaB_getfenv
-
 
 
 static int luaB_rawequal (lua_State *L) {
 static int luaB_rawequal (lua_State *L) {
   luaL_checkany(L, 1);
   luaL_checkany(L, 1);
@@ -348,12 +346,13 @@ static int luaB_loadin (lua_State *L) {
 }
 }
 
 
 
 
-static int luaB_loadstring (lua_State *L) {
-  lua_settop(L, 2);
-  lua_pushliteral(L, "tb");
-  return luaB_load(L);  /* loadstring(s, n) == load(s, n, "tb") */
+#if defined(LUA_COMPAT_LOADSTRING)
+#define luaB_loadstring		luaB_load
+#else
+#define luaB_loadstring		luaB_deprecated
+#endif
+
 
 
-}
 /* }====================================================== */
 /* }====================================================== */
 
 
 
 
@@ -473,7 +472,7 @@ static const luaL_Reg base_funcs[] = {
   {"collectgarbage", luaB_collectgarbage},
   {"collectgarbage", luaB_collectgarbage},
   {"dofile", luaB_dofile},
   {"dofile", luaB_dofile},
   {"error", luaB_error},
   {"error", luaB_error},
-  {"getfenv", luaB_getfenv},
+  {"getfenv", luaB_deprecated},
   {"getmetatable", luaB_getmetatable},
   {"getmetatable", luaB_getmetatable},
   {"ipairs", luaB_ipairs},
   {"ipairs", luaB_ipairs},
   {"loadfile", luaB_loadfile},
   {"loadfile", luaB_loadfile},
@@ -488,7 +487,7 @@ static const luaL_Reg base_funcs[] = {
   {"rawget", luaB_rawget},
   {"rawget", luaB_rawget},
   {"rawset", luaB_rawset},
   {"rawset", luaB_rawset},
   {"select", luaB_select},
   {"select", luaB_select},
-  {"setfenv", luaB_setfenv},
+  {"setfenv", luaB_deprecated},
   {"setmetatable", luaB_setmetatable},
   {"setmetatable", luaB_setmetatable},
   {"tonumber", luaB_tonumber},
   {"tonumber", luaB_tonumber},
   {"tostring", luaB_tostring},
   {"tostring", luaB_tostring},

+ 7 - 1
luaconf.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: luaconf.h,v 1.150 2010/11/10 17:38:10 roberto Exp roberto $
+** $Id: luaconf.h,v 1.151 2010/11/12 15:48:30 roberto Exp roberto $
 ** Configuration file for Lua
 ** Configuration file for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -253,6 +253,12 @@
 */
 */
 #define LUA_COMPAT_LOG10
 #define LUA_COMPAT_LOG10
 
 
+/*
+@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
+** library. You can rewrite 'loadstring(s)' as 'load(s)'.
+*/
+#define LUA_COMPAT_LOADSTRING
+
 /*
 /*
 @@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
 @@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
 */
 */