assure that helpers.wrequire search widgets in order

This commit is contained in:
mutlusun 2016-12-21 22:56:14 +01:00
parent 6f5a6825a1
commit 151b5f6196
1 changed files with 29 additions and 21 deletions

View File

@ -20,6 +20,7 @@ local setmetatable = setmetatable
local getmetatable = getmetatable local getmetatable = getmetatable
local string = { local string = {
upper = string.upper, upper = string.upper,
lower = string.lower,
format = string.format format = string.format
} }
local error = error local error = error
@ -43,7 +44,7 @@ function helpers.getos()
local uname = f:read("*line") local uname = f:read("*line")
f:close() f:close()
return uname:lower() return string.lower(uname)
end end
-- }}} -- }}}
@ -51,27 +52,34 @@ end
function helpers.wrequire(table, key) function helpers.wrequire(table, key)
local ret = rawget(table, key) local ret = rawget(table, key)
if ret then
return ret
end
local ostable = {
linux = { "linux", "all" },
freebsd = { "freebsd", "bsd", "all" }
}
os = ostable[helpers.getos()]
if not os then
error("Vicious: platform not supported.")
end
for i = 1, #os do
local status, value =
pcall(function()
return require(table._NAME .. "." .. key .. "_" .. os[i])
end)
if status then
ret = value
break
end
end
if not ret then if not ret then
os = helpers.getos() error("Vicious: widget not available for current platform.")
if os == "linux" then
os = { "linux", "all" }
elseif os == "freebsd" then
os = { "freebsd", "bsd", "all" }
else
error("Vicious: platform not supported.")
end
for _, i in pairs(os) do -- there is a break in loop
local status, value =
pcall(function()
return require(table._NAME .. "." .. key .. "_" .. i)
end)
if status then
ret = value
break
end
end
end end
return ret return ret