From df5caa06eb734b9882ab65380f8c899f073e2fea Mon Sep 17 00:00:00 2001 From: Rob Hoelz Date: Fri, 9 Sep 2016 07:43:56 -0500 Subject: [PATCH] Return success/failure for dbus.connect_signal dbus.connect_signal may only have a single function bound to a given name, but the caller has no way of knowing if their function was bound or not. This change has dbus.connect_signal adopt the standard Lua error convention of returning a truthy value upon success, or nil and an error message upon failure. --- dbus.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dbus.c b/dbus.c index dc5bcaff..547cdef4 100644 --- a/dbus.c +++ b/dbus.c @@ -761,6 +761,8 @@ luaA_dbus_remove_match(lua_State *L) * * @param interface A string with the interface name. * @param func The function to call. + * @return true on success, nil + error if the signal could not be connected + * because another function is already connected. * @function connect_signal */ static int @@ -770,11 +772,16 @@ luaA_dbus_connect_signal(lua_State *L) luaA_checkfunction(L, 2); signal_t *sig = signal_array_getbyid(&dbus_signals, a_strhash((const unsigned char *) name)); - if(sig) + if(sig) { luaA_warn(L, "cannot add signal %s on D-Bus, already existing", name); - else + lua_pushnil(L); + lua_pushfstring(L, "cannot add signal %s on D-Bus, already existing", name); + return 2; + } else { signal_connect(&dbus_signals, name, luaA_object_ref(L, 2)); - return 0; + lua_pushboolean(L, 1); + return 1; + } } /** Remove a signal receiver on the D-Bus.