From 0f793d3a457af9afa8bc4eae2dff855cd7e6a192 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sat, 29 Sep 2012 01:37:37 +0200 Subject: [PATCH] lua: propagate incoming message to method callback inside the lua context Signed-off-by: John Crispin --- lua/test.lua | 5 ++++- lua/ubus.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/test.lua b/lua/test.lua index d9ecb45..07e62c6 100755 --- a/lua/test.lua +++ b/lua/test.lua @@ -20,9 +20,12 @@ local my_method = { }, test = { hello = { - function(req) + function(req, msg) conn:reply(req, {message="foo"}); print("Call to function 'hello'") + for k, v in pairs(msg) do + print("key=" .. k .. " value=" .. tostring(v)) + end end, {id = ubus.INT32, msg = ubus.STRING } }, hello1 = { diff --git a/lua/ubus.c b/lua/ubus.c index 899a8bd..081ff45 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -290,7 +290,11 @@ ubus_method_handler(struct ubus_context *ctx, struct ubus_object *obj, if (lua_isfunction(state, -1)) { lua_pushlightuserdata(state, req); - lua_call(state, 1, 0); + if (!msg) + lua_pushnil(state); + else + ubus_lua_parse_blob_array(state, blob_data(msg), blob_len(msg), true); + lua_call(state, 2, 0); } return 0; } -- 2.11.0