模块:Yesno

来自汉语教学技术研究与应用
86.135.251.105讨论2014年2月2日 (日) 20:53的版本 (Created page with "-- Function allowing for consistent treatment of boolean-like wikitext input. -- It works similarly to the template {{yesno}}. return function (val, default) val = type(va...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到导航 跳转到搜索

可在模块:Yesno/doc创建此模块的帮助文档

脚本错误:Lua错误:无法创建进程:proc_open(/dev/null): Failed to open stream: Operation not permitted

-- Function allowing for consistent treatment of boolean-like wikitext input.
-- It works similarly to the template {{yesno}}.
return function (val, default)
    val = type(val) == 'string' and mw.ustring.lower(val) or val -- put in lower case
    if val == nil then
        return nil
    elseif val == false or val == 'no' or val == 'n' or val == 'false' or tonumber(val) == 0 then
        return false
    elseif val == true or val == 'yes' or val == 'y' or val == 'true' or tonumber(val) == 1 then
        return true
    else
        return default
    end
end