]> git.ipfire.org Git - location/libloc.git/commitdiff
lua: country: Export remaining properties
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 15:18:21 +0000 (15:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 15:18:21 +0000 (15:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/lua/country.c
tests/lua/main.lua

index 7012ee69ddfcb115d5c1d73cc20917a01fc61a7f..7d2a78a96382ee9ec6449e3d16bd81d26a815b86 100644 (file)
@@ -94,6 +94,19 @@ static int Country_eq(lua_State* L) {
        return 1;
 }
 
+// Name
+
+static int Country_get_name(lua_State* L) {
+       Country* self = luaL_checkcountry(L, 1);
+
+       // Return the code
+       lua_pushstring(L, loc_country_get_name(self->country));
+
+       return 1;
+}
+
+// Code
+
 static int Country_get_code(lua_State* L) {
        Country* self = luaL_checkcountry(L, 1);
 
@@ -103,11 +116,25 @@ static int Country_get_code(lua_State* L) {
        return 1;
 }
 
+// Continent Code
+
+static int Country_get_continent_code(lua_State* L) {
+       Country* self = luaL_checkcountry(L, 1);
+
+       // Return the code
+       lua_pushstring(L, loc_country_get_continent_code(self->country));
+
+       return 1;
+}
+
 static const struct luaL_Reg Country_functions[] = {
        { "new", Country_new },
        { "get_code", Country_get_code },
+       { "get_continent_code", Country_get_continent_code },
+       { "get_name", Country_get_name },
        { "__eq", Country_eq },
        { "__gc", Country_gc },
+       { "__tostring", Country_get_code },
        { NULL, NULL },
 };
 
index 35c63331c3125bb762db4d6623a509bb671c8678..8fb178f695efe3d32d654b85d6fcd4bd2ddc95c5 100755 (executable)
@@ -70,6 +70,8 @@ function test_country()
 
        c1 = location.Country.new("DE")
        luaunit.assertEquals(c1:get_code(), "DE")
+       luaunit.assertNil(c1:get_name())
+       luaunit.assertNil(c1:get_continent_code())
 
        c2 = location.Country.new("GB")
        luaunit.assertNotEquals(c1, c2)