Browse Source

'lua_cpcall' is deprecated

Roberto Ierusalimschy 15 years ago
parent
commit
cb3f95d516
3 changed files with 14 additions and 6 deletions
  1. 3 2
      lapi.c
  2. 2 3
      lua.h
  3. 9 1
      luaconf.h

+ 3 - 2
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.105 2009/12/17 16:20:01 roberto Exp roberto $
+** $Id: lapi.c,v 2.106 2009/12/22 15:32:50 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -1148,10 +1148,11 @@ LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
 }
 
 
+#if defined(LUA_COMPAT_CPCALL)
 LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
   lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL);
   lua_pushlightuserdata(L, &func);
   lua_pushlightuserdata(L, ud);
   return lua_pcall(L, 2, 0, 0);
 }
-
+#endif

+ 2 - 3
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.255 2009/12/18 15:32:36 roberto Exp roberto $
+** $Id: lua.h,v 1.256 2009/12/22 15:32:50 roberto Exp roberto $
 ** Lua - A Scripting Language
 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
 ** See Copyright Notice at the end of this file
@@ -239,7 +239,6 @@ LUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
                             int ctx, lua_CFunction k);
 #define lua_pcall(L,n,r,f)	lua_pcallk(L, (n), (r), (f), 0, NULL)
 
-LUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
 LUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,
                                         const char *chunkname);
 
@@ -299,7 +298,7 @@ LUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
 #define lua_newtable(L)		lua_createtable(L, 0, 0)
 
 #define lua_register(L,n,f) \
-	(lua_pushcfunction(L, (f)), lua_setfield(L, LUA_GLOBALSINDEX, (n)))
+	(lua_pushcfunction(L, (f)), lua_setfield(L, LUA_ENVIRONINDEX, (n)))
 
 #define lua_pushcfunction(L,f)	lua_pushcclosure(L, (f), 0)
 

+ 9 - 1
luaconf.h

@@ -1,5 +1,5 @@
 /*
-** $Id: luaconf.h,v 1.123 2009/12/17 12:50:20 roberto Exp roberto $
+** $Id: luaconf.h,v 1.124 2009/12/17 13:08:51 roberto Exp roberto $
 ** Configuration file for Lua
 ** See Copyright Notice in lua.h
 */
@@ -205,6 +205,14 @@
 ** ===================================================================
 */
 
+/*
+@@ LUA_COMPAT_CPCALL controls the presence of function 'lua_cpcall'.
+** CHANGE it (define it) if you need this function.  (You can replace
+** it with the preregistered function cpcall.)
+*/
+/* #define LUA_COMPAT_CPCALL */
+/* LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); */
+
 /*
 @@ LUA_COMPAT_FENV controls the presence of functions 'setfenv/getfenv'.
 ** CHANGE it (define it) if you need these functions.  (You can replace