--- apt-0.5.15lorg3.95.git522/apt-pkg/luaiface.cc.lua-52 2011-04-07 22:18:59.000000000 +0900 +++ apt-0.5.15lorg3.95.git522/apt-pkg/luaiface.cc 2014-05-19 14:21:01.000000000 +0900 @@ -41,6 +41,18 @@ using namespace std; +#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)); \ @@ -107,14 +119,14 @@ 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); @@ -174,14 +186,14 @@ 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] == '/') { @@ -213,15 +225,13 @@ } 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; @@ -359,7 +369,7 @@ { lua_pushstring(L, Name); lua_pushnil(L); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -368,7 +378,7 @@ if (Value != NULL) { lua_pushstring(L, Name); lua_pushstring(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); } Globals.push_back(Name); } @@ -378,7 +388,7 @@ if (Value != NULL) { lua_pushstring(L, Name); pushudata(pkgCache::Package*, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); } Globals.push_back(Name); } @@ -393,7 +403,7 @@ lua_pushstring(L, Value[i]); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -408,7 +418,7 @@ lua_pushstring(L, Value[i]); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -423,7 +433,7 @@ 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); } @@ -438,7 +448,7 @@ pushudata(pkgCache::Package*, Value[i]); lua_rawseti(L, -2, i+1); } - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -446,7 +456,7 @@ { lua_pushstring(L, Name); lua_pushboolean(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -454,7 +464,7 @@ { lua_pushstring(L, Name); lua_pushnumber(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -463,7 +473,7 @@ if (Value != NULL) { lua_pushstring(L, Name); lua_pushlightuserdata(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); } Globals.push_back(Name); } @@ -472,7 +482,7 @@ { lua_pushstring(L, Name); lua_pushcfunction(L, Value); - lua_rawset(L, LUA_GLOBALSINDEX); + lua_setglobal(L, Name); Globals.push_back(Name); } @@ -483,7 +493,7 @@ 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(); } @@ -492,7 +502,7 @@ 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); @@ -504,7 +514,7 @@ { vector 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); @@ -520,8 +530,9 @@ 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); @@ -532,7 +543,7 @@ 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; @@ -541,7 +552,7 @@ 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); @@ -552,7 +563,7 @@ 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); @@ -563,7 +574,7 @@ { vector 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); @@ -1467,7 +1478,7 @@ 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 @@ -1478,7 +1489,7 @@ return 0; } -static const luaL_reg aptlib[] = { +static const luaL_Reg aptlib[] = { {"confget", AptLua_confget}, {"confgetlist", AptLua_confgetlist}, {"confset", AptLua_confset}, @@ -1552,7 +1563,7 @@ static int luaopen_apt(lua_State *L) { - lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_pushglobaltable(L); luaL_openlib(L, NULL, aptlib, 0); return 0; } --- apt-0.5.15lorg3.95.git522/luaext/lposix.c.lua-52 2011-04-07 22:18:59.000000000 +0900 +++ apt-0.5.15lorg3.95.git522/luaext/lposix.c 2014-05-16 15:53:51.000000000 +0900 @@ -49,6 +49,15 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 const luaL_reg R[] = +static const luaL_Reg R[] = { {"access", Paccess}, {"chdir", Pchdir}, --- apt-0.5.15lorg3.95.git522/luaext/lrexlib.c.lua-52 2011-04-07 22:18:59.000000000 +0900 +++ apt-0.5.15lorg3.95.git522/luaext/lrexlib.c 2014-05-16 15:53:51.000000000 +0900 @@ -161,7 +161,7 @@ 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 @@ 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 @@ /* Open the library */ -static const luaL_reg rexlib[] = { +static const luaL_Reg rexlib[] = { #ifdef WITH_POSIX {"newPOSIX", posix_comp}, #endif