Skip to content

Commit

Permalink
chore: move ubus examples in ubus sub directory.
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Jan 22, 2025
1 parent cc8ea20 commit 756b063
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
34 changes: 34 additions & 0 deletions examples/ubus/signatures.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env eco

local ubus = require 'eco.ubus'

local attr_types = {
[ubus.ARRAY] = 'Array',
[ubus.TABLE] = 'Table',
[ubus.STRING] = 'String',
[ubus.INT64] = 'Integer',
[ubus.INT32] = 'Integer',
[ubus.INT16] = 'Integer',
[ubus.INT8] = 'Boolean',
[ubus.DOUBLE] = 'Number'
}

local con, err = ubus.connect()
if not con then
error(err)
end

for id, o in pairs(con:objects()) do
print(string.format('"%s" @%08x', o, id))
for method, signature in pairs(con:signatures(o)) do
io.write(string.format('\t"%s":{', method))
local comma = ''
for k, v in pairs(signature) do
io.write(string.format('%s"%s":"%s"', comma, k, attr_types[v] or 'unknown'))
comma = ','
end
print('}')
end
end

con:close()
27 changes: 0 additions & 27 deletions examples/ubus.lua → examples/ubus/ubus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,6 @@ time.at(1, function()
print('call eco.defer:', res.message)
end)

print('\nubus objects:')

local attr_types = {
[ubus.ARRAY] = 'Array',
[ubus.TABLE] = 'Table',
[ubus.STRING] = 'String',
[ubus.INT64] = 'Integer',
[ubus.INT32] = 'Integer',
[ubus.INT16] = 'Integer',
[ubus.INT8] = 'Boolean',
[ubus.DOUBLE] = 'Number'
}

for id, obj in pairs(con:objects()) do
print(string.format('"%s" @%08x', obj, id))
for method, signature in pairs(con:signatures(obj)) do
io.write(string.format('\t"%s":{', method))
local comma = ''
for k, v in pairs(signature) do
io.write(string.format('%s"%s":"%s"', comma, k, attr_types[v] or 'unknown'))
comma = ','
end
print('}')
end
end
print()

while true do
time.sleep(1)
end

0 comments on commit 756b063

Please sign in to comment.