diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-11-27 16:57:39 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-11-27 16:57:39 +0000 |
commit | e29167801238586e90b9437877a2caf21c5f1552 (patch) | |
tree | 204ed132be296445a373512e22e4d9b2dfc31ebf /libs/sys/luasrc | |
parent | 37ac71b816b395e4ed9a16b02fa04eafea81a6a9 (diff) |
libs/sys: protect iwinfo loading and return stub if module is not present
Diffstat (limited to 'libs/sys/luasrc')
-rw-r--r-- | libs/sys/luasrc/sys.lua | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index d1137b76a..61da6f1cb 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -624,7 +624,7 @@ wifi = {} -- @param ifname String containing the interface name -- @return A wrapped iwinfo object instance function wifi.getiwinfo(ifname) - local iwinfo = require "iwinfo" + local stat, iwinfo = pcall(require, "iwinfo") if ifname then local c = 0 @@ -652,19 +652,17 @@ function wifi.getiwinfo(ifname) end) end - local t = iwinfo.type(ifname) - if t then - local x = iwinfo[t] - return setmetatable({}, { - __index = function(t, k) - if k == "ifname" then - return ifname - elseif x[k] then - return x[k](ifname) - end + local t = stat and iwinfo.type(ifname) + local x = t and iwinfo[t] or { } + return setmetatable({}, { + __index = function(t, k) + if k == "ifname" then + return ifname + elseif x[k] then + return x[k](ifname) end - }) - end + end + }) end end |