Add librpm level lua extension stub
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 14 Jan 2009 13:09:25 +0000 (15:09 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 14 Jan 2009 13:09:25 +0000 (15:09 +0200)
- inspired by rpm5.org, details differ
- just rpm.vercmp() for now
- push all Lua initialization to rpmLuaInit()

lib/Makefile.am
lib/rpmliblua.c [new file with mode: 0644]
lib/rpmliblua.h [new file with mode: 0644]
lib/rpmrc.c

index 982fa73..0e5ed0c 100644 (file)
@@ -33,7 +33,8 @@ librpm_la_SOURCES = \
        rpmte.c rpmte_internal.h rpmts.c \
        rpmvercmp.c signature.c signature.h transaction.c \
        verify.c rpmlock.c rpmlock.h misc.h \
-       legacy.c merge.c
+       legacy.c merge.c \
+       rpmliblua.c rpmliblua.h
 if SQLITE3
 librpm_la_SOURCES += backend/sqlite.c
 endif
diff --git a/lib/rpmliblua.c b/lib/rpmliblua.c
new file mode 100644 (file)
index 0000000..e67fc2d
--- /dev/null
@@ -0,0 +1,38 @@
+#include "system.h"
+
+#ifdef WITH_LUA
+#include <lua.h>
+#include <lauxlib.h>
+#include <rpm/rpmlib.h>
+
+#define _RPMLUA_INTERNAL
+#include "rpmio/rpmlua.h"
+#include "lib/rpmliblua.h"
+
+static int rpm_vercmp(lua_State *L)
+{
+    const char *v1, *v2;
+    int rc;
+
+    v1 = luaL_checkstring(L, 1);
+    v2 = luaL_checkstring(L, 2);
+
+    rc = rpmvercmp(v1, v2);
+    lua_pushinteger(L, rc);
+    return 1;
+}
+
+static const luaL_reg luarpmlib_f[] = {
+    {"vercmp", rpm_vercmp},
+    {NULL, NULL}
+};
+
+void rpmLuaInit(void)
+{
+    rpmlua lua = rpmluaGetGlobalState();
+    lua_pushvalue(lua->L, LUA_GLOBALSINDEX); 
+    luaL_register(lua->L, "rpm", luarpmlib_f);
+    return;
+}
+
+#endif /* WITH_LUA */
diff --git a/lib/rpmliblua.h b/lib/rpmliblua.h
new file mode 100644 (file)
index 0000000..17578ee
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _RPMLIBLUA_H
+#define _RPMLIBLUA_H
+
+/* Initialize Lua subsystem & register all our extensions */
+void rpmLuaInit(void);
+
+#endif /* _RPMLIBLUA_H */
index c2bf118..0877a87 100644 (file)
@@ -22,6 +22,7 @@
 #include "rpmio/rpmlua.h"
 #include "rpmio/rpmio_internal.h"      /* XXX for rpmioSlurp */
 #include "lib/misc.h"
+#include "lib/rpmliblua.h"
 
 #include "debug.h"
 
@@ -1692,9 +1693,9 @@ int rpmReadConfigFiles(const char * file, const char * target)
        os = _free(os);
     }
 
-    /* Force Lua state initialization */
 #ifdef WITH_LUA
-    (void) rpmluaGetGlobalState();
+    /* Force Lua state initialization */
+    rpmLuaInit();
 #endif
 
     return 0;