summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-12-15 10:09:35 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2011-02-05 04:23:33 +0000
commit31fc6de9420f35be8cc070657b449ec7d109e043 (patch)
tree7c66210e0f7549c10288d7ead6c99679346c9298
parente984c2a3a333484872acc52fa0cf15ec9bfbfaa9 (diff)
downloadapk-tools-31fc6de9420f35be8cc070657b449ec7d109e043.tar.bz2
apk-tools-31fc6de9420f35be8cc070657b449ec7d109e043.tar.xz
lua: implement who_owns
-rw-r--r--src/lua-apk.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lua-apk.c b/src/lua-apk.c
index 24962ce..6128718 100644
--- a/src/lua-apk.c
+++ b/src/lua-apk.c
@@ -80,6 +80,14 @@ static const char *get_opt_string_field(lua_State *L, int index,
return value;
}
+static void set_string_field(lua_State *L, int index, const char *key,
+ const char *value)
+{
+ lua_pushstring(L, key);
+ lua_pushstring(L, value);
+ lua_settable(L, index);
+}
+
static int get_opt_int_field(lua_State *L, int index, const char *key, int def)
{
int value;
@@ -89,6 +97,13 @@ static int get_opt_int_field(lua_State *L, int index, const char *key, int def)
return value;
}
+static void set_int_field(lua_State *L, int index, const char *key, int value)
+{
+ lua_pushstring(L, key);
+ lua_pushinteger(L, value);
+ lua_settable(L, index);
+}
+
static int get_boolean_field(lua_State *L, int index, const char *key)
{
int value;
@@ -150,11 +165,36 @@ static int Papk_db_close(lua_State *L)
}
+static int push_package(lua_State *L, struct apk_package *pkg)
+{
+ if (pkg == NULL) {
+ lua_pushnil(L);
+ return 1;
+ }
+ lua_newtable(L);
+ set_string_field(L, -3, "name", pkg->name->name);
+ set_string_field(L, -3, "version", pkg->version);
+ set_string_field(L, -3, "url", pkg->url);
+ set_string_field(L, -3, "license", pkg->license);
+ set_string_field(L, -3, "description", pkg->description);
+ set_string_field(L, -3, "filename", pkg->filename);
+ set_int_field(L, -3, "size", pkg->size);
+ return 1;
+}
+static int Papk_who_owns(lua_State *L)
+{
+ struct apk_database *db = checkdb(L, 1);
+ const char *path = luaL_checkstring(L, 2);
+ struct apk_package *pkg = apk_db_get_file_owner(db, APK_BLOB_STR(path));
+ return push_package(L, pkg);
+}
+
static const luaL_reg reg_apk_methods[] = {
{"version_validate", Pversion_validate},
{"version_compare", Pversion_compare},
{"version_is_less", Pversion_is_less},
{"db_open", Papk_db_open},
+ {"who_owns", Papk_who_owns},
{NULL, NULL}
};