从配置文件中获取字符串值 - LuCI

时间:2013-10-17 09:31:20

标签: lua openwrt

我正在尝试为Luci的OpenWRT模块构建一个Web界面。我有以下代码:

m = Map("amld_cbi", translate ("amld_status"))
s = m:section(TypedSection, "amld_conf","Status")
fqdn = s:option(DummyValue, "fqdn", "FQDN value")

这适用于在屏幕上显示fqdn(位于amld_cbi内)的值。现在我想要String值本身。

当我尝试做的时候:

m = Map("amld_cbi", translate ("amld_status"))
s = m:section(TypedSection, "amld_conf","Status")
fqdn = s:option(DummyValue, "fqdn", "FQDN value")

luci.sys.call("amld " .. fqdn)

我收到以下错误:

The called action terminated with an exception:
/usr/lib/lua/luci/model/cbi/amld/amld_status.lua:25: attempt to concatenate global 'fqdn' (a table value)
stack traceback:
    [C]: in function 'assert'
    /usr/lib/lua/luci/dispatcher.lua:448: in function 'dispatch'
    /usr/lib/lua/luci/dispatcher.lua:195: in function </usr/lib/lua/luci/dispatcher.lua:194>

有人知道如何从变量fqdn中获取实际值吗?

1 个答案:

答案 0 :(得分:5)

刚想出来,看起来你必须添加以下内容:

m = Map("amld_cbi", translate ("amld_status"))
s = m:section(TypedSection, "amld_conf","Status")
fqdn = s:option(DummyValue, "fqdn", "FQDN value")

fqdn_string = uci.get("amld_cbi", "amld", "fqdn")

luci.sys.call("amld " .. tostring(fqdn_string)) **the tostring function may not be necessary **

我的amld_cbi文件如下所示:

config amld_conf 'amld'
    option fqdn 'www.google.com'