我的openwrt学习笔记(三十五):Openwrt之luci-lua调用uci的测试
好了 ,lua 学习 , uci也学习了,接下来就是luci
Lua中使用UCI 例子:
Luci文件源代码:
linux@ubuntu:~/linux_c/lua/lua-5.1.5/luca_study$cat test1.luci
#!/usr/bin/lua
--helloworld lua program
print("Hello World!")
require("uci")
-- Get asection type or an option
x =uci.cursor()
a =x:get("test", "abc", "test_var")
print(a)
-- Getthe configuration directory
b =x:get_confdir()
print(b)
-- Getall sections of a config or all values of a section
d =x:get_all("test", "abc")
print(d)
print(d["test_var"])
print(d["test_var2"])
uci 文件具体内容
linux@ubuntu:/etc/config$pwd
/etc/config
linux@ubuntu:/etc/config$cat test
config'test' 'abc'
option 'test_var' 'value'
option 'test_var2' 'value22'
执行测试输出结果:
linux@ubuntu:~/linux_c/lua/lua-5.1.5/luca_study$lua test1.luci
HelloWorld!
value
/etc/config
table:0x9190018
value
value22
Luci api
http://luci.subsignal.org/api/luci/
http://wiki.openwrt.org/doc/techref/uci#api