Skip to content

Commit 756b063

Browse files
committed
chore: move ubus examples in ubus sub directory.
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
1 parent cc8ea20 commit 756b063

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

examples/ubus/signatures.lua

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env eco
2+
3+
local ubus = require 'eco.ubus'
4+
5+
local attr_types = {
6+
[ubus.ARRAY] = 'Array',
7+
[ubus.TABLE] = 'Table',
8+
[ubus.STRING] = 'String',
9+
[ubus.INT64] = 'Integer',
10+
[ubus.INT32] = 'Integer',
11+
[ubus.INT16] = 'Integer',
12+
[ubus.INT8] = 'Boolean',
13+
[ubus.DOUBLE] = 'Number'
14+
}
15+
16+
local con, err = ubus.connect()
17+
if not con then
18+
error(err)
19+
end
20+
21+
for id, o in pairs(con:objects()) do
22+
print(string.format('"%s" @%08x', o, id))
23+
for method, signature in pairs(con:signatures(o)) do
24+
io.write(string.format('\t"%s":{', method))
25+
local comma = ''
26+
for k, v in pairs(signature) do
27+
io.write(string.format('%s"%s":"%s"', comma, k, attr_types[v] or 'unknown'))
28+
comma = ','
29+
end
30+
print('}')
31+
end
32+
end
33+
34+
con:close()

examples/ubus.lua examples/ubus/ubus.lua

-27
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,6 @@ time.at(1, function()
5454
print('call eco.defer:', res.message)
5555
end)
5656

57-
print('\nubus objects:')
58-
59-
local attr_types = {
60-
[ubus.ARRAY] = 'Array',
61-
[ubus.TABLE] = 'Table',
62-
[ubus.STRING] = 'String',
63-
[ubus.INT64] = 'Integer',
64-
[ubus.INT32] = 'Integer',
65-
[ubus.INT16] = 'Integer',
66-
[ubus.INT8] = 'Boolean',
67-
[ubus.DOUBLE] = 'Number'
68-
}
69-
70-
for id, obj in pairs(con:objects()) do
71-
print(string.format('"%s" @%08x', obj, id))
72-
for method, signature in pairs(con:signatures(obj)) do
73-
io.write(string.format('\t"%s":{', method))
74-
local comma = ''
75-
for k, v in pairs(signature) do
76-
io.write(string.format('%s"%s":"%s"', comma, k, attr_types[v] or 'unknown'))
77-
comma = ','
78-
end
79-
print('}')
80-
end
81-
end
82-
print()
83-
8457
while true do
8558
time.sleep(1)
8659
end

0 commit comments

Comments
 (0)