diff -up apt-0.5.15lorg3.94pt/apt-pkg/luaiface.cc.lua apt-0.5.15lorg3.94pt/apt-pkg/luaiface.cc --- apt-0.5.15lorg3.94pt/apt-pkg/luaiface.cc.lua 2009-02-24 11:46:07.000000000 +0100 +++ apt-0.5.15lorg3.94pt/apt-pkg/luaiface.cc 2014-08-03 00:01:46.408169462 +0200 @@ -39,6 +39,18 @@ extern "C" { #include <sys/types.h> #include <assert.h> +#ifndef lua_pushglobaltable +#define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) +#endif + +#ifndef lua_open +#define lua_open() luaL_newstate() +#endif + +#ifndef lua_strlen +#define lua_strlen(L,i) lua_rawlen(L, (i)) +#endif + #define pushudata(ctype, value) \ do { \ ctype *_tmp = (ctype *) lua_newuserdata(L, sizeof(ctype)); \ @@ -105,14 +117,14 @@ Lua::Lua() lua_settop(L, 0); /* discard any results */ } #else - const luaL_reg lualibs[] = { + const luaL_Reg lualibs[] = { {"posix", luaopen_posix}, {"rex", luaopen_rex}, {"apt", luaopen_apt}, {NULL, NULL} }; luaL_openlibs(L); - const luaL_reg *lib = lualibs; + const luaL_Reg *lib = lualibs; for (; lib->name; lib++) { lua_pushcfunction(L, lib->func); lua_pushstring(L, lib->name); @@ -172,14 +184,14 @@ bool Lua::RunScripts(const char *ConfLis continue; if (Value == "interactive") { lua_pushstring(L, "script_slot"); - lua_pushstring(L, ConfListKey); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, ConfListKey); RunInteractive(ConfListKey); lua_pushstring(L, "script_slot"); lua_pushnil(L); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "script_slot"); + continue; } if (Value[0] == '.' || Value[0] == '/') { @@ -211,15 +223,13 @@ bool Lua::RunScripts(const char *ConfLis } lua_pushstring(L, "script_slot"); - lua_pushstring(L, ConfListKey); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, ConfListKey); InternalRunScript(); lua_pushstring(L, "script_slot"); lua_pushnil(L); - lua_rawset(L, LUA_GLOBALSINDEX); - + lua_setglobal(L, "script_slot"); lua_pop(L, 1); return true; @@ -357,7 +367,7 @@ void Lua::SetGlobal(const char *Name) { lua_pushstring(L, Name); lua_pushnil(L); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -366,7 +376,7 @@ void Lua::SetGlobal(const char *Name, co if (Value != NULL) { lua_pushstring(L, Name); lua_pushstring(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); } Globals.push_back(Name); } @@ -376,7 +386,7 @@ void Lua::SetGlobal(const char *Name, pk if (Value != NULL) { lua_pushstring(L, Name); pushudata(pkgCache::Package*, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); } Globals.push_back(Name); } @@ -391,7 +401,7 @@ void Lua::SetGlobal(const char *Name, co lua_pushstring(L, Value[i]); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -406,7 +416,7 @@ void Lua::SetGlobal(const char *Name, ve lua_pushstring(L, Value[i]); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -421,7 +431,7 @@ void Lua::SetGlobal(const char *Name, ve lua_pushstring(L, Value[i].c_str()); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -436,7 +446,7 @@ void Lua::SetGlobal(const char *Name, ve pushudata(pkgCache::Package*, Value[i]); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -444,7 +454,7 @@ void Lua::SetGlobal(const char *Name, bo { lua_pushstring(L, Name); lua_pushboolean(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -452,7 +462,7 @@ void Lua::SetGlobal(const char *Name, do { lua_pushstring(L, Name); lua_pushnumber(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -461,7 +471,7 @@ void Lua::SetGlobal(const char *Name, vo if (Value != NULL) { lua_pushstring(L, Name); lua_pushlightuserdata(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); } Globals.push_back(Name); } @@ -470,7 +480,7 @@ void Lua::SetGlobal(const char *Name, lu { lua_pushstring(L, Name); lua_pushcfunction(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -481,7 +491,7 @@ void Lua::ResetGlobals() I != Globals.end(); I++) { lua_pushstring(L, I->c_str()); lua_pushnil(L); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, I->c_str()); } Globals.clear(); } @@ -490,7 +500,7 @@ void Lua::ResetGlobals() const char *Lua::GetGlobalStr(const char *Name) { lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); const char *Ret = NULL; if (lua_isstring(L, -1)) Ret = lua_tostring(L, -1); @@ -502,7 +512,7 @@ vector<string> Lua::GetGlobalStrList(con { vector<string> Ret; lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); int t = lua_gettop(L); if (lua_istable(L, t)) { lua_pushnil(L); @@ -518,8 +528,9 @@ vector<string> Lua::GetGlobalStrList(con double Lua::GetGlobalNum(const char *Name) { + lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); double Ret = 0; if (lua_isnumber(L, -1)) Ret = lua_tonumber(L, -1); @@ -530,7 +541,7 @@ double Lua::GetGlobalNum(const char *Nam bool Lua::GetGlobalBool(const char *Name) { lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); bool Ret = lua_toboolean(L, -1); lua_remove(L, -1); return Ret; @@ -539,7 +550,7 @@ bool Lua::GetGlobalBool(const char *Name void *Lua::GetGlobalPtr(const char *Name) { lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); void *Ret = NULL; if (lua_isuserdata(L, -1)) Ret = lua_touserdata(L, -1); @@ -550,7 +561,7 @@ void *Lua::GetGlobalPtr(const char *Name pkgCache::Package *Lua::GetGlobalPkg(const char *Name) { lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); pkgCache::Package *Ret; checkudata(pkgCache::Package*, Ret, -1); lua_remove(L, -1); @@ -561,7 +572,7 @@ vector<pkgCache::Package*> Lua::GetGloba { vector<pkgCache::Package*> Ret; lua_pushstring(L, Name); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, Name); int t = lua_gettop(L); if (lua_istable(L, t)) { lua_pushnil(L); @@ -1465,7 +1476,7 @@ static int AptLua_gettext(lua_State *L) const char *str = luaL_checkstring(L, 1); if (str != NULL) { lua_pushliteral(L, "TEXTDOMAIN"); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, "TEXTDOMAIN"); if (lua_isstring(L, -1)) lua_pushstring(L, dgettext(lua_tostring(L, -1), str)); else @@ -1476,7 +1487,7 @@ static int AptLua_gettext(lua_State *L) return 0; } -static const luaL_reg aptlib[] = { +static const luaL_Reg aptlib[] = { {"confget", AptLua_confget}, {"confgetlist", AptLua_confgetlist}, {"confset", AptLua_confset}, @@ -1550,8 +1561,8 @@ static int AptLua_pkgcomp(lua_State *L) static int luaopen_apt(lua_State *L) { - lua_pushvalue(L, LUA_GLOBALSINDEX); - luaL_openlib(L, NULL, aptlib, 0); + lua_pushglobaltable(L); + luaL_setfuncs(L, aptlib, 0); return 0; } diff -up apt-0.5.15lorg3.94pt/luaext/lposix.c.lua apt-0.5.15lorg3.94pt/luaext/lposix.c --- apt-0.5.15lorg3.94pt/luaext/lposix.c.lua 2009-02-24 11:46:07.000000000 +0100 +++ apt-0.5.15lorg3.94pt/luaext/lposix.c 2014-08-02 23:53:35.217948548 +0200 @@ -49,6 +49,15 @@ static const char *filetype(mode_t m) typedef int (*Selector)(lua_State *L, int i, const void *data); +/* implemented as luaL_typerror until lua 5.1, dropped in 5.2 + * (C) 1994-2012 Lua.org, PUC-Rio. MIT license + */ +static int typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + static int doselection(lua_State *L, int i, const char *const S[], Selector F, const void *data) { if (lua_isnone(L, i)) @@ -135,7 +144,7 @@ static uid_t mygetuid(lua_State *L, int return (p==NULL) ? -1 : p->pw_uid; } else - return luaL_typerror(L, i, "string or number"); + return typerror(L, i, "string or number"); } static gid_t mygetgid(lua_State *L, int i) @@ -150,7 +159,7 @@ static gid_t mygetgid(lua_State *L, int return (g==NULL) ? -1 : g->gr_gid; } else - return luaL_typerror(L, i, "string or number"); + return typerror(L, i, "string or number"); } @@ -554,7 +563,7 @@ static int Pgetpasswd(lua_State *L) /** else if (lua_isstring(L, 1)) p = getpwnam(lua_tostring(L, 1)); else - luaL_typerror(L, 1, "string or number"); + typerror(L, 1, "string or number"); if (p==NULL) lua_pushnil(L); else @@ -571,7 +580,7 @@ static int Pgetgroup(lua_State *L) /** else if (lua_isstring(L, 1)) g = getgrnam(lua_tostring(L, 1)); else - luaL_typerror(L, 1, "string or number"); + typerror(L, 1, "string or number"); if (g==NULL) lua_pushnil(L); else @@ -690,10 +699,10 @@ static int Puname(lua_State *L) /** un luaL_buffinit(L, &b); for (s=luaL_optstring(L, 1, "%s %n %r %v %m"); *s; s++) if (*s!='%') - luaL_putchar(&b, *s); + luaL_addchar(&b, *s); else switch (*++s) { - case '%': luaL_putchar(&b, *s); break; + case '%': luaL_addchar(&b, *s); break; case 'm': luaL_addstring(&b,u.machine); break; case 'n': luaL_addstring(&b,u.nodename); break; case 'r': luaL_addstring(&b,u.release); break; @@ -792,7 +801,7 @@ static int Pmkstemp(lua_State *L) } -static const luaL_reg R[] = +static const luaL_Reg R[] = { {"access", Paccess}, {"chdir", Pchdir}, diff -up apt-0.5.15lorg3.94pt/luaext/lrexlib.c.lua apt-0.5.15lorg3.94pt/luaext/lrexlib.c --- apt-0.5.15lorg3.94pt/luaext/lrexlib.c.lua 2009-02-24 11:46:07.000000000 +0100 +++ apt-0.5.15lorg3.94pt/luaext/lrexlib.c 2014-08-02 23:53:35.222948510 +0200 @@ -161,7 +161,7 @@ static int posix_gc (lua_State *L) { return 0; } -static const luaL_reg posixmeta[] = { +static const luaL_Reg posixmeta[] = { {"match", posix_match}, {"gmatch", posix_gmatch}, {"__gc", posix_gc}, @@ -285,7 +285,7 @@ static int pcre_gc (lua_State *L) return 0; } -static const luaL_reg pcremeta[] = { +static const luaL_Reg pcremeta[] = { {"match", pcre_match}, {"gmatch", pcre_gmatch}, {"__gc", pcre_gc}, @@ -297,7 +297,7 @@ static const luaL_reg pcremeta[] = { /* Open the library */ -static const luaL_reg rexlib[] = { +static const luaL_Reg rexlib[] = { #ifdef WITH_POSIX {"newPOSIX", posix_comp}, #endif