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 not ret then if ret then
os = helpers.getos() return ret
end
if os == "linux" then local ostable = {
os = { "linux", "all" } linux = { "linux", "all" },
elseif os == "freebsd" then freebsd = { "freebsd", "bsd", "all" }
os = { "freebsd", "bsd", "all" } }
else
os = ostable[helpers.getos()]
if not os then
error("Vicious: platform not supported.") error("Vicious: platform not supported.")
end end
for _, i in pairs(os) do -- there is a break in loop for i = 1, #os do
local status, value = local status, value =
pcall(function() pcall(function()
return require(table._NAME .. "." .. key .. "_" .. i) return require(table._NAME .. "." .. key .. "_" .. os[i])
end) end)
if status then if status then
ret = value ret = value
break break
end end
end end
if not ret then
error("Vicious: widget not available for current platform.")
end end
return ret return ret