]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/lua/database.c
lua: Fix raising an exception if no network was found
[people/ms/libloc.git] / src / lua / database.c
index 8328196f9727849c230b4fcceeb3e4c9669b62ce..dfdb705213c7484f235734c66d567de1edf7902d 100644 (file)
@@ -189,23 +189,18 @@ static int Database_lookup(lua_State* L) {
 
        // Perform lookup
        r = loc_database_lookup_from_string(self->db, address, &network);
-       if (r) {
-               switch (errno) {
-                       // Return nil if the network was not found
-                       case ENOENT:
-                               lua_pushnil(L);
-                               return 1;
-
-                       default:
-                               return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno));
-               }
+       if (r)
+               return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno));
+
+       // Nothing found
+       if (!network) {
+               lua_pushnil(L);
+               return 1;
        }
 
        // Create a network object
-       if (network) {
-               r = create_network(L, network);
-               loc_network_unref(network);
-       }
+       r = create_network(L, network);
+       loc_network_unref(network);
 
        return r;
 }