打开/关闭菜单
打开/关闭个人菜单
未登录
登录即可进行编辑

模块:Yesno

出自Tardis百科,中文神秘博士维基
胡大夫讨论 | 贡献2024年5月22日 (三) 14:30的版本 (创建页面,内容为“-- Imported from: https://en.wikipedia.org/wiki/Module:Yesno -- Function allowing for consistent treatment of boolean-like wikitext input. -- It works similarly to the template {{yesno}}. return function (val, default) -- If your wiki uses non-ascii characters for any of "yes", "no", etc., you -- should replace "val:lower()" with "mw.ustring.lower(val)" in the -- following line. val = type(val) == 'string' and val:lower() or val if val == nil then retu…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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

-- Imported from: https://en.wikipedia.org/wiki/Module:Yesno

-- Function allowing for consistent treatment of boolean-like wikitext input.
-- It works similarly to the template {{yesno}}.

return function (val, default)
	-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
	-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
	-- following line.
	val = type(val) == 'string' and val:lower() or val
	if val == nil then
		return nil
	elseif val == true 
		or val == 'yes'
		or val == 'y'
		or val == 'true'
		or val == 't'
		or val == 'on'
		or val == '是'
		or val == '真'
		or val == '开'
		or tonumber(val) == 1
	then
		return true
	elseif val == false
		or val == 'no'
		or val == 'n'
		or val == 'false'
		or val == 'f'
		or val == 'off'
		or val == '否'
		or val == '假'
		or val == '关'
		or tonumber(val) == 0
	then
		return false
	else
		return default
	end
end
我们提供服务需要使用Cookie。您使用我们的服务,即表示您同意我们使用Cookie。