From: Michael Tremer Date: Thu, 22 Feb 2024 15:46:57 +0000 (+0000) Subject: lua: database: Export description/license/vendor X-Git-Tag: 0.9.18~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba81f7323f1257348cba45a592b3e48d0f6bf86a;p=location%2Flibloc.git lua: database: Export description/license/vendor Signed-off-by: Michael Tremer --- diff --git a/src/lua/database.c b/src/lua/database.c index ca46cbb..ad19240 100644 --- a/src/lua/database.c +++ b/src/lua/database.c @@ -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 }, diff --git a/tests/lua/main.lua b/tests/lua/main.lua index 70e918a..073bdc5 100755 --- a/tests/lua/main.lua +++ b/tests/lua/main.lua @@ -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()