Modernize Lua library/module initialization, drop support for Lua < 5.2
Replace long since deprecated luaL_openlib() with modern counterparts luaL_newlib() and luaL_setfuncs() and use luaL_requiref() for loading our modules (these changes needed to go hand in hand, otherwise it blows up every which way). Because these functions are only available in Lua >= 5.2, this means we can drop the other compat checks as well, just update the documenation for the new version requirement. This also means that rpm now works on a modern Lua (tested with 5.3.5) without requiring any compat modules and defines to be present in Lua. Whee! Patch based on work done by @daurnimator in PR #169. Resolves: #166
This commit is contained in:
parent
1c433661ea
commit
6d4c68ba10
2
INSTALL
2
INSTALL
|
@ -81,7 +81,7 @@ Minimal instructions for building BDB are
|
|||
make install
|
||||
|
||||
For embedded Lua scripting support (recommended and enabled by default),
|
||||
you'll need Lua >= 5.1 library + development environment installed.
|
||||
you'll need Lua >= 5.2 library + development environment installed.
|
||||
Note that only the library is needed at runtime, RPM never calls external
|
||||
Lua interpreter for anything. Lua is available from
|
||||
http://www.lua.org
|
||||
|
|
|
@ -890,7 +890,7 @@ static const luaL_Reg R[] =
|
|||
|
||||
LUALIB_API int luaopen_posix (lua_State *L)
|
||||
{
|
||||
luaL_openlib(L, MYNAME, R, 0);
|
||||
luaL_newlib(L, R);
|
||||
lua_pushliteral(L,"version"); /** version */
|
||||
lua_pushliteral(L,MYVERSION);
|
||||
lua_settable(L,-3);
|
||||
|
|
|
@ -327,14 +327,14 @@ LUALIB_API int luaopen_rex(lua_State *L)
|
|||
{
|
||||
#ifdef WITH_POSIX
|
||||
createmeta(L, "regex_t");
|
||||
luaL_openlib(L, NULL, rexmeta, 0);
|
||||
luaL_setfuncs(L, rexmeta, 0);
|
||||
lua_pop(L, 1);
|
||||
#endif
|
||||
#ifdef WITH_PCRE
|
||||
createmeta(L, "pcre");
|
||||
luaL_openlib(L, NULL, pcremeta, 0);
|
||||
luaL_setfuncs(L, pcremeta, 0);
|
||||
lua_pop(L, 1);
|
||||
#endif
|
||||
luaL_openlib(L, "rex", rexlib, 0);
|
||||
luaL_newlib(L, rexlib);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -6,20 +6,11 @@
|
|||
#include <lposix.h>
|
||||
#include <lrexlib.h>
|
||||
|
||||
#if (LUA_VERSION_NUM < 502)
|
||||
#define lua_rawlen(L, i) (lua_objlen(L, i))
|
||||
#endif
|
||||
|
||||
#ifndef LUA_LOADED_TABLE
|
||||
/* feature introduced in Lua 5.3.4 */
|
||||
#define LUA_LOADED_TABLE "_LOADED"
|
||||
#endif
|
||||
|
||||
/* define added in 5.2 */
|
||||
#ifndef lua_pushglobaltable
|
||||
#define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <spawn.h>
|
||||
|
@ -145,16 +136,13 @@ rpmlua rpmluaNew()
|
|||
lua->L = L;
|
||||
|
||||
for (lib = extlibs; lib->name; lib++) {
|
||||
lua_pushcfunction(L, lib->func);
|
||||
lua_pushstring(L, lib->name);
|
||||
lua_call(L, 1, 0);
|
||||
lua_settop(L, 0);
|
||||
luaL_requiref(L, lib->name, lib->func, 1);
|
||||
}
|
||||
lua_pushcfunction(L, rpm_print);
|
||||
lua_setglobal(L, "print");
|
||||
|
||||
lua_pushglobaltable(L);
|
||||
luaL_openlib(L, "os", os_overrides, 0);
|
||||
lua_getglobal(L, "os");
|
||||
luaL_setfuncs(L, os_overrides, 0);
|
||||
|
||||
lua_getglobal(L, "package");
|
||||
lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua");
|
||||
|
@ -185,11 +173,7 @@ void rpmluaRegister(rpmlua lua, const luaL_Reg *funcs, const char *lib)
|
|||
{
|
||||
lua_getfield(lua->L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
|
||||
lua_getfield(lua->L, -1, lib);
|
||||
#if (LUA_VERSION_NUM < 502) || defined(LUA_COMPAT_MODULE)
|
||||
luaL_register(lua->L, 0, funcs);
|
||||
#else
|
||||
luaL_setfuncs(lua->L, funcs, 0);
|
||||
#endif
|
||||
lua_pop(lua->L, 2);
|
||||
}
|
||||
|
||||
|
@ -1005,7 +989,6 @@ static const luaL_Reg rpmlib[] = {
|
|||
|
||||
static int luaopen_rpm(lua_State *L)
|
||||
{
|
||||
lua_pushglobaltable(L);
|
||||
luaL_openlib(L, "rpm", rpmlib, 0);
|
||||
return 0;
|
||||
luaL_newlib(L, rpmlib);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue