X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=lua%2Ftest.lua;h=277956a99259b2e4a154ed2487aa5d270268009d;hp=d9ecb4535affb1a0ce8bf4d62b69899626d1d922;hb=HEAD;hpb=73380e45c9c73a425b304a9081be62d2aeaa5a3f diff --git a/lua/test.lua b/lua/test.lua index d9ecb45..277956a 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 = { @@ -31,9 +34,33 @@ local my_method = { conn:reply(req, {message="foo2"}); print("Call to function 'hello1'") end, {id = ubus.INT32, msg = ubus.STRING } + }, + deferred = { + function(req) + conn:reply(req, {message="wait for it"}) + local def_req = conn:defer_request(req) + uloop.timer(function() + conn:reply(def_req, {message="done"}) + conn:complete_deferred_request(def_req, 0) + print("Deferred request complete") + end, 2000) + print("Call to function 'deferred'") + end, {} } } } conn:add(my_method) + +local my_event = { + test = function(msg) + print("Call to test event") + for k, v in pairs(msg) do + print("key=" .. k .. " value=" .. tostring(v)) + end + end, +} + +conn:listen(my_event) + uloop.run()