From: Michael Tremer Date: Sun, 31 Mar 2024 16:33:34 +0000 (+0000) Subject: lua: Don't raise an error if a network cannot be found X-Git-Tag: 0.9.18~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88908fd46de5694d66eb1fe0cc3467d4a393ad93;p=location%2Flibloc.git lua: Don't raise an error if a network cannot be found The lookup function now returns nil which is easier to handle than catching a Lua error. Signed-off-by: Michael Tremer --- diff --git a/src/lua/database.c b/src/lua/database.c index 841041d..aada739 100644 --- a/src/lua/database.c +++ b/src/lua/database.c @@ -174,8 +174,17 @@ static int Database_lookup(lua_State* L) { // Perform lookup r = loc_database_lookup_from_string(self->db, address, &network); - if (r) - return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno)); + 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)); + } + } // Create a network object r = create_network(L, network);