Module:Yesno: Difference between revisions

m 1 revision imported
No edit summary
 
Line 1: Line 1:
-- Function allowing for consistent treatment of boolean-like wikitext input.
local p = {}
-- It works similarly to the template {{yesno}}.


return function (val, default)
-- Core yes/no logic
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
local function _yesno(val, default)
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
-- following line.
val = type(val) == 'string' and val:lower() or val
val = type(val) == 'string' and val:lower() or val
if val == nil then
if val == nil then
Line 31: Line 28:
end
end
end
end
-- Wikipedia-style API
function p.yesno(val, default)
return _yesno(val, default)
end
-- Allow direct calls: require(...)(val)
setmetatable(p, {
__call = function(_, val, default)
return _yesno(val, default)
end
})
return p