lua: propagate incoming message to method callback inside the lua context
authorJohn Crispin <blogic@openwrt.org>
Fri, 28 Sep 2012 23:37:37 +0000 (01:37 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 28 Sep 2012 23:41:09 +0000 (01:41 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
lua/test.lua
lua/ubus.c

index d9ecb4535affb1a0ce8bf4d62b69899626d1d922..07e62c6ac5341d9cc0aecbf110284d57c3d9b2ce 100755 (executable)
@@ -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 = {
index 899a8bd3dcadc9ace66e8e5683cad1833b60855c..081ff45b53f6482657d5922a8bc130f4b294198f 100644 (file)
@@ -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;
 }