diff options
author | Anders F Bjorklund <afb@users.sourceforge.net> | 2012-09-12 23:26:38 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-10-09 08:28:52 +0300 |
commit | ac959fed0082cb253d45c7a04866e8654e962442 (patch) | |
tree | 8267396b9e374d6d0a0f178d03f9425c2ba0363e /rpmio | |
parent | 389b1ab706be8eddba9f00c7084759f670ce96ac (diff) | |
download | rpm-ac959fed0082cb253d45c7a04866e8654e962442.tar.gz rpm-ac959fed0082cb253d45c7a04866e8654e962442.tar.bz2 rpm-ac959fed0082cb253d45c7a04866e8654e962442.zip |
Add lua 5.2 support.
Add compatibility support for both lua-5.1 and lua-5.2,
assuming that the LUA_COMPAT might have been disabled.
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/rpmlua.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c index 319c0d020..86d0408ed 100644 --- a/rpmio/rpmlua.c +++ b/rpmio/rpmlua.c @@ -7,6 +7,18 @@ #include <lposix.h> #include <lrexlib.h> +#ifndef lua_open +#define lua_open() luaL_newstate() +#endif + +#ifndef lua_strlen +#define lua_strlen(L,i) lua_rawlen(L, (i)) +#endif + +#ifndef lua_pushglobaltable +#define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) +#endif + #include <unistd.h> #include <assert.h> @@ -53,10 +65,10 @@ rpmlua rpmluaNew() { rpmlua lua = (rpmlua) xcalloc(1, sizeof(*lua)); struct stat st; - const luaL_reg *lib; + const luaL_Reg *lib; char *initlua = rpmGenPath(rpmConfigDir(), "init.lua", NULL); - static const luaL_reg extlibs[] = { + static const luaL_Reg extlibs[] = { {"posix", luaopen_posix}, {"rex", luaopen_rex}, {"rpm", luaopen_rpm}, @@ -74,12 +86,26 @@ rpmlua rpmluaNew() lua_call(L, 1, 0); lua_settop(L, 0); } +#ifndef LUA_GLOBALSINDEX + lua_pushglobaltable(L); +#endif lua_pushliteral(L, "LUA_PATH"); lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua"); +#ifdef LUA_GLOBALSINDEX lua_rawset(L, LUA_GLOBALSINDEX); +#else + lua_settable(L, -3); +#endif lua_pushliteral(L, "print"); lua_pushcfunction(L, rpm_print); +#ifdef LUA_GLOBALSINDEX lua_rawset(L, LUA_GLOBALSINDEX); +#else + lua_settable(L, -3); +#endif +#ifndef LUA_GLOBALSINDEX + lua_pop(L, 1); +#endif rpmluaSetData(lua, "lua", lua); if (stat(initlua, &st) != -1) (void)rpmluaRunScriptFile(lua, initlua); @@ -191,7 +217,7 @@ void rpmluaSetVar(rpmlua _lua, rpmluav var) } if (!var->listmode || lua->pushsize > 0) { if (lua->pushsize == 0) - lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_pushglobaltable(L); if (pushvar(L, var->keyType, &var->key) != -1) { if (pushvar(L, var->valueType, &var->value) != -1) lua_rawset(L, -3); @@ -228,7 +254,7 @@ void rpmluaGetVar(rpmlua _lua, rpmluav var) lua_State *L = lua->L; if (!var->listmode) { if (lua->pushsize == 0) - lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_pushglobaltable(L); if (pushvar(L, var->keyType, &var->key) != -1) { lua_rawget(L, -2); popvar(L, &var->valueType, &var->value); @@ -261,7 +287,7 @@ static int findkey(lua_State *L, int oper, const char *key, va_list va) vsnprintf(buf, blen + 1, key, va); s = e = buf; - lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_pushglobaltable(L); for (;;) { if (*e == '\0' || *e == '.') { if (e != s) { @@ -822,7 +848,7 @@ static int rpm_print (lua_State *L) return 0; } -static const luaL_reg rpmlib[] = { +static const luaL_Reg rpmlib[] = { {"b64encode", rpm_b64encode}, {"b64decode", rpm_b64decode}, {"expand", rpm_expand}, @@ -836,7 +862,7 @@ static const luaL_reg rpmlib[] = { static int luaopen_rpm(lua_State *L) { - lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_pushglobaltable(L); luaL_openlib(L, "rpm", rpmlib, 0); return 0; } |