summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Feytons <dirk.feytons@gmail.com>2018-01-16 18:13:39 +0100
committerJohn Crispin <john@phrozen.org>2018-01-17 09:59:58 +0100
commit5bae22eb5472c9c7cc30caa9a84004bba19940d3 (patch)
tree7ea322c69503050674c5c5e3fe16d79891f5a4a7
parent212ceb1b021bc0db19201894e1e9633fa6a25638 (diff)
downloadubus-5bae22eb5472c9c7cc30caa9a84004bba19940d3.tar.gz
ubus/lua: pass notification name to callback
The callback function registered to be invoked when subscribing to a notification was only passed the notification data (if any) but not the name of the notification. This name is now passed as second argument to remain backwards compatible. The example subscriber.lua has also be updated. Signed-off-by: Dirk Feytons <dirk.feytons@gmail.com>
-rwxr-xr-xlua/subscriber.lua5
-rw-r--r--lua/ubus.c5
2 files changed, 6 insertions, 4 deletions
diff --git a/lua/subscriber.lua b/lua/subscriber.lua
index e1d3a9f..f59448d 100755
--- a/lua/subscriber.lua
+++ b/lua/subscriber.lua
@@ -15,8 +15,9 @@ if not conn then
end
local sub = {
- notify = function( msg )
- print("Count: ", msg["count"])
+ notify = function( msg, name )
+ print("name:", name)
+ print(" count:", msg["count"])
end,
}
diff --git a/lua/ubus.c b/lua/ubus.c
index cfe9c9b..00d9e00 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -787,10 +787,11 @@ ubus_sub_notify_handler(struct ubus_context *ctx, struct ubus_object *obj,
if (lua_isfunction(state, -1)) {
if( msg ){
ubus_lua_parse_blob_array(state, blob_data(msg), blob_len(msg), true);
- lua_call(state, 1, 0);
} else {
- lua_call(state, 0, 0);
+ lua_pushnil(state);
}
+ lua_pushstring(state, method);
+ lua_call(state, 2, 0);
} else {
lua_pop(state, 1);
}