add lua binding test scripts

Signed-off-by: John Crispin <blogic@openwrt.org>
This commit is contained in:
John Crispin 2012-09-26 18:27:10 +02:00 committed by Felix Fietkau
parent c382792d98
commit 73380e45c9
2 changed files with 78 additions and 0 deletions

39
lua/test.lua Executable file
View file

@ -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()

39
lua/test_client.lua Executable file
View file

@ -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()