]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
lua: database: Export description/license/vendor
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 15:46:57 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 15:48:35 +0000 (15:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/lua/database.c
tests/lua/main.lua

index ca46cbb5ec6ed1db67e346f8e600992cba8c5053..ad192407dd26f9e7e976bee11b19ed99b0777318 100644 (file)
@@ -85,6 +85,37 @@ static int Database_gc(lua_State* L) {
        return 0;
 }
 
+// Description
+
+static int Database_get_description(lua_State* L) {
+       Database* self = luaL_checkdatabase(L, 1);
+
+       // Push the description
+       lua_pushstring(L, loc_database_get_description(self->db));
+
+       return 1;
+}
+
+// License
+
+static int Database_get_license(lua_State* L) {
+       Database* self = luaL_checkdatabase(L, 1);
+
+       // Push the license
+       lua_pushstring(L, loc_database_get_license(self->db));
+
+       return 1;
+}
+
+static int Database_get_vendor(lua_State* L) {
+       Database* self = luaL_checkdatabase(L, 1);
+
+       // Push the vendor
+       lua_pushstring(L, loc_database_get_vendor(self->db));
+
+       return 1;
+}
+
 static int Database_get_as(lua_State* L) {
        struct loc_as* as = NULL;
        int r;
@@ -154,7 +185,10 @@ static int Database_lookup(lua_State* L) {
 
 static const struct luaL_Reg database_functions[] = {
        { "get_as", Database_get_as },
+       { "get_description", Database_get_description },
        { "get_country", Database_get_country },
+       { "get_license", Database_get_license },
+       { "get_vendor", Database_get_vendor },
        { "open", Database_open },
        { "lookup", Database_lookup },
        { "__gc", Database_gc },
index 70e918a2e56dba12f3703c267eef2d08c9d45754..073bdc5bb6c02c99f2bd3ae566ffa307909a0194 100755 (executable)
@@ -34,6 +34,17 @@ function test_open_database()
 
        -- Open the database
        db = location.Database.open(ENV_TEST_DATABASE)
+
+       -- Description
+       luaunit.assertIsString(db:get_description())
+
+       -- License
+       luaunit.assertIsString(db:get_license())
+       luaunit.assertEquals(db:get_license(), "CC BY-SA 4.0")
+
+       -- Vendor
+       luaunit.assertIsString(db:get_vendor())
+       luaunit.assertEquals(db:get_vendor(), "IPFire Project")
 end
 
 function test_lookup()