X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fsys%2Fluasrc%2Fsys.lua;h=61da6f1cb41873c96b40a21e2fc0794147c18c8f;hp=c0ee4a1d1b93a97196fbec13f12caedea3bd8130;hb=e29167801238586e90b9437877a2caf21c5f1552;hpb=3b5123937e901ee70cf5b602d7efcf83d23dc0ee diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index c0ee4a1d1..61da6f1cb 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -30,15 +30,14 @@ local os = require "os" local table = require "table" local nixio = require "nixio" local fs = require "nixio.fs" -local iwinfo = require "iwinfo" local uci = require "luci.model.uci" local luci = {} luci.util = require "luci.util" luci.ip = require "luci.ip" -local tonumber, ipairs, pairs, pcall, type, next, setmetatable = - tonumber, ipairs, pairs, pcall, type, next, setmetatable +local tonumber, ipairs, pairs, pcall, type, next, setmetatable, require = + tonumber, ipairs, pairs, pcall, type, next, setmetatable, require --- LuCI Linux and POSIX system utilities. @@ -625,6 +624,8 @@ wifi = {} -- @param ifname String containing the interface name -- @return A wrapped iwinfo object instance function wifi.getiwinfo(ifname) + local stat, iwinfo = pcall(require, "iwinfo") + if ifname then local c = 0 local u = uci.cursor_state() @@ -651,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