Selaa lähdekoodia

functions 'getfenv' and 'setfenv' are deprecated

Roberto Ierusalimschy 15 vuotta sitten
vanhempi
commit
c5050b1c41
2 muutettua tiedostoa jossa 23 lisäystä ja 4 poistoa
  1. 14 3
      lbaselib.c
  2. 9 1
      luaconf.h

+ 14 - 3
lbaselib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbaselib.c,v 1.222 2009/11/09 18:55:17 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.223 2009/11/13 17:01:40 roberto Exp roberto $
 ** Basic library
 ** See Copyright Notice in lua.h
 */
@@ -107,6 +107,9 @@ static int luaB_setmetatable (lua_State *L) {
 }
 
 
+
+#if defined(LUA_COMPAT_FENV)
+
 static void getfunc (lua_State *L, int opt) {
   if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
   else {
@@ -121,7 +124,6 @@ static void getfunc (lua_State *L, int opt) {
   }
 }
 
-
 static int luaB_getfenv (lua_State *L) {
   getfunc(L, 1);
   if (lua_iscfunction(L, -1))  /* is a C function? */
@@ -131,7 +133,6 @@ static int luaB_getfenv (lua_State *L) {
   return 1;
 }
 
-
 static int luaB_setfenv (lua_State *L) {
   luaL_checktype(L, 2, LUA_TTABLE);
   getfunc(L, 0);
@@ -142,6 +143,16 @@ static int luaB_setfenv (lua_State *L) {
   return 1;
 }
 
+#else
+
+static int luaB_getfenv (lua_State *L) {
+  return luaL_error(L, "getfenv/setfenv deprecated");
+}
+
+#define luaB_setfenv	luaB_getfenv
+
+#endif
+
 
 static int luaB_rawequal (lua_State *L) {
   luaL_checkany(L, 1);

+ 9 - 1
luaconf.h

@@ -1,5 +1,5 @@
 /*
-** $Id: luaconf.h,v 1.111 2009/10/11 20:02:19 roberto Exp roberto $
+** $Id: luaconf.h,v 1.112 2009/10/23 12:31:12 roberto Exp roberto $
 ** Configuration file for Lua
 ** See Copyright Notice in lua.h
 */
@@ -328,6 +328,14 @@
 ** ===================================================================
 */
 
+/*
+@@ LUA_COMPAT_FENV controls de presence of functions 'setfenv/getfenv'.
+** CHANGE it (undefine it) if as soon as you rewrite your code to
+** avoid using those functions. (You can replace them with lexical
+** environments, 'loadin', or the debug library.)
+*/
+/* #define LUA_COMPAT_FENV */
+
 /*
 @@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
 ** CHANGE it (undefine it) if as soon as you rewrite all calls 'log10(x)'