add lua binding test scripts
[project/ubus.git] / lua / test.lua
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()