add lua binding test scripts
authorJohn Crispin <blogic@openwrt.org>
Wed, 26 Sep 2012 16:27:10 +0000 (18:27 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 27 Sep 2012 12:05:51 +0000 (14:05 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
lua/test.lua [new file with mode: 0755]
lua/test_client.lua [new file with mode: 0755]

diff --git a/lua/test.lua b/lua/test.lua
new file mode 100755 (executable)
index 0000000..d9ecb45
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env lua
+
+require "ubus"
+require "uloop"
+
+uloop.init()
+
+local conn = ubus.connect()
+if not conn then
+       error("Failed to connect to ubus")
+end
+
+local my_method = {
+       broken = {
+               hello = 1,
+               hello1 = {
+                       function(req)
+                       end, {id = "fail" }
+               },
+       },
+       test = {
+               hello = {
+                       function(req)
+                               conn:reply(req, {message="foo"});
+                               print("Call to function 'hello'")
+                       end, {id = ubus.INT32, msg = ubus.STRING }
+               },
+               hello1 = {
+                       function(req)
+                               conn:reply(req, {message="foo1"});
+                               conn:reply(req, {message="foo2"});
+                               print("Call to function 'hello1'")
+                       end, {id = ubus.INT32, msg = ubus.STRING }
+               }
+       }
+}
+
+conn:add(my_method)
+uloop.run()
diff --git a/lua/test_client.lua b/lua/test_client.lua
new file mode 100755 (executable)
index 0000000..f55c327
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env lua
+
+require "ubus"
+require "uloop"
+
+uloop.init()
+
+local conn = ubus.connect()
+if not conn then
+       error("Failed to connect to ubusd")
+end
+
+local namespaces = conn:objects()
+for i, n in ipairs(namespaces) do
+       print("namespace=" .. n)
+       local signatures = conn:signatures(n)
+       for p, s in pairs(signatures) do
+               print("\tprocedure=" .. p)
+               for k, v in pairs(s) do
+                       print("\t\tattribute=" .. k .. " type=" .. v)
+               end
+       end
+end
+
+local status = conn:call("test", "hello", { msg = "eth0" })
+
+for k, v in pairs(status) do
+       print("key=" .. k .. " value=" .. tostring(v))
+end
+
+local status = {conn:call("test", "hello1", { msg = "eth0" })}
+
+for a = 1, #status do
+       for k, v in pairs(status[a]) do
+               print("key=" .. k .. " value=" .. tostring(v))
+       end
+end
+
+uloop.run()