Module:For: Difference between revisions
m 1 revision imported |
No edit summary |
||
| Line 2: | Line 2: | ||
local mHatlist = require('Module:Hatnote list') | local mHatlist = require('Module:Hatnote list') | ||
local mHatnote = require('Module:Hatnote') | local mHatnote = require('Module:Hatnote') | ||
local yesNo = require | |||
-- FIX: Import yesno function correctly | |||
local yesNo | |||
local success, result = pcall(require, 'Module:Yesno') | |||
if success and type(result) == "table" then | |||
yesNo = result._yesno or result.yesno | |||
if type(yesNo) ~= "function" then | |||
yesNo = function(val, default) | |||
if val == nil then return default end | |||
if type(val) == "boolean" then return val end | |||
if type(val) == "string" then | |||
val = val:lower():match('^%s*(.-)%s*$') or "" | |||
if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then | |||
return true | |||
elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then | |||
return false | |||
end | |||
elseif type(val) == "number" then | |||
if val == 1 then return true | |||
elseif val == 0 then return false end | |||
end | |||
return default | |||
end | |||
end | |||
else | |||
yesNo = function(val, default) | |||
if val == nil then return default end | |||
if type(val) == "boolean" then return val end | |||
if type(val) == "string" then | |||
val = val:lower():match('^%s*(.-)%s*$') or "" | |||
if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then | |||
return true | |||
elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then | |||
return false | |||
end | |||
elseif type(val) == "number" then | |||
if val == 1 then return true | |||
elseif val == 0 then return false end | |||
end | |||
return default | |||
end | |||
end | |||
local p = {} | local p = {} | ||