]> git.ipfire.org Git - location/libloc.git/commitdiff
lua: Fix calling methods that belong to an object
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 14:43:20 +0000 (14:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 14:43:20 +0000 (14:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/lua/database.c
src/lua/network.c
tests/lua/main.lua

index f5306f984c6d8d45451a078a92f25de5d1f564c2..2d97dcf854661d12a0661be9943093256cc003a9 100644 (file)
@@ -96,10 +96,10 @@ static int Database_lookup(lua_State* L) {
        struct loc_network* network = NULL;
        int r;
 
-       Database* self = luaL_checkdatabase(L, 0);
+       Database* self = luaL_checkdatabase(L, 1);
 
        // Require a string
-       const char* address = luaL_checkstring(L, 1);
+       const char* address = luaL_checkstring(L, 2);
 
        // Perform lookup
        r = loc_database_lookup_from_string(self->db, address, &network);
index 2a75f75dd922655997e14faba892c4bd2291a03d..8a755595cf6829ef407088f5164ae44ca53ebaa3 100644 (file)
@@ -105,7 +105,7 @@ static int Network_tostring(lua_State* L) {
 // ASN
 
 static int Network_get_asn(lua_State* L) {
-       Network* self = luaL_checknetwork(L, 0);
+       Network* self = luaL_checknetwork(L, 1);
 
        uint32_t asn = loc_network_get_asn(self->network);
 
@@ -121,7 +121,7 @@ static int Network_get_asn(lua_State* L) {
 // Family
 
 static int Network_get_family(lua_State* L) {
-       Network* self = luaL_checknetwork(L, 0);
+       Network* self = luaL_checknetwork(L, 1);
 
        // Push family
        lua_pushnumber(L, loc_network_address_family(self->network));
@@ -132,7 +132,7 @@ static int Network_get_family(lua_State* L) {
 // Country Code
 
 static int Network_get_country_code(lua_State* L) {
-       Network* self = luaL_checknetwork(L, 0);
+       Network* self = luaL_checknetwork(L, 1);
 
        const char* country_code = loc_network_get_country_code(self->network);
 
index fada1680cc77247eedd808b2ae744816bf9c67c3..5be48736cb4939073164ed65a051b9e5d83969b5 100755 (executable)
@@ -52,13 +52,13 @@ function test_network()
        n1 = location.Network.new("10.0.0.0/8")
 
        -- The ASN should be nul
-       luaunit.assertNil(n1.get_asn())
+       luaunit.assertNil(n1:get_asn())
 
        -- The family should be IPv4
-       luaunit.assertEquals(n1.get_family(), 2)
+       luaunit.assertEquals(n1:get_family(), 2)
 
        -- The country code should be empty
-       luaunit.assertNil(n1.get_country_code())
+       luaunit.assertNil(n1:get_country_code())
 end
 
 os.exit(luaunit.LuaUnit.run())