cmake: Fix find_library for ubusd and examples/server
[project/ubus.git] / lua / test.lua
1 #!/usr/bin/env lua
2
3 require "ubus"
4 require "uloop"
5
6 uloop.init()
7
8 local conn = ubus.connect()
9 if not conn then
10 error("Failed to connect to ubus")
11 end
12
13 local my_method = {
14 broken = {
15 hello = 1,
16 hello1 = {
17 function(req)
18 end, {id = "fail" }
19 },
20 },
21 test = {
22 hello = {
23 function(req, msg)
24 conn:reply(req, {message="foo"});
25 print("Call to function 'hello'")
26 for k, v in pairs(msg) do
27 print("key=" .. k .. " value=" .. tostring(v))
28 end
29 end, {id = ubus.INT32, msg = ubus.STRING }
30 },
31 hello1 = {
32 function(req)
33 conn:reply(req, {message="foo1"});
34 conn:reply(req, {message="foo2"});
35 print("Call to function 'hello1'")
36 end, {id = ubus.INT32, msg = ubus.STRING }
37 }
38 }
39 }
40
41 conn:add(my_method)
42
43 local my_event = {
44 test = function(msg)
45 print("Call to test event")
46 for k, v in pairs(msg) do
47 print("key=" .. k .. " value=" .. tostring(v))
48 end
49 end,
50 }
51
52 conn:listen(my_event)
53
54 uloop.run()