diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-09-13 16:52:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-09-13 16:52:39 -0300 |
commit | 2628a424801de3562777a059e599c5e7255965a1 (patch) | |
tree | 931bc22a976835d41da022367b6295547ffe7dde | |
parent | 0b3b6850c90999ebf7217f51ee74184af732285d (diff) | |
download | lua-github-2628a424801de3562777a059e599c5e7255965a1.tar.gz |
re-implementation of deprecated functions (wiht compiler option)
-rw-r--r-- | lbaselib.c | 51 |
1 files changed, 41 insertions, 10 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.2 2000/09/12 13:49:05 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.3 2000/09/12 18:41:43 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -534,31 +534,62 @@ static int luaB_sort (lua_State *L) { */ +#define num_deprecated 4 + +static const struct luaL_reg deprecated_names [num_deprecated] = { + {"foreachvar", luaB_foreach}, + {"nextvar", luaB_next}, + {"rawgetglobal", luaB_rawget}, + {"rawsetglobal", luaB_rawset} +}; + + +#ifdef LUA_DEPRECATETFUNCS + /* -** gives an explicit error in any attempt to call a deprecated function +** call corresponding function inserting `globals' as first argument */ static int deprecated_func (lua_State *L) { - luaL_verror(L, "function `%.20s' is deprecated", luaL_check_string(L, -1)); - return 0; /* to avoid warnings */ + lua_insert(L, 1); /* upvalue is the function to be called */ + lua_getglobals(L); + lua_insert(L, 2); /* table of globals is 1o argument */ + if (lua_call(L, lua_gettop(L)-1, LUA_MULTRET) != 0) + lua_error(L, NULL); + return lua_gettop(L); /* return all results */ } -#define num_deprecated 4 +static void deprecated_funcs (lua_State *L) { + int i; + for (i=0; i<num_deprecated; i++) { + lua_pushcfunction(L, deprecated_names[i].func); + lua_pushcclosure(L, deprecated_func, 1); + lua_setglobal(L, deprecated_names[i].name); + } +} -static const char *const deprecated_names [num_deprecated] = { - "foreachvar", "nextvar", "rawgetglobal", "rawsetglobal" -}; + +#else + +/* +** gives an explicit error in any attempt to call a deprecated function +*/ +static int deprecated_func (lua_State *L) { + luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1)); + return 0; /* to avoid warnings */ +} static void deprecated_funcs (lua_State *L) { int i; for (i=0; i<num_deprecated; i++) { - lua_pushstring(L, deprecated_names[i]); + lua_pushstring(L, deprecated_names[i].name); lua_pushcclosure(L, deprecated_func, 1); - lua_setglobal(L, deprecated_names[i]); + lua_setglobal(L, deprecated_names[i].name); } } +#endif /* }====================================================== */ |