본문으로 이동
  • 토론란발전소에서 진행되는 토의에 많은 참여 바랍니다.
  • 2024년 2월 16일부로 TemplateSandbox 확장 기능을 설치하였습니다. 문제가 발생하면 오락실로 제보 바랍니다.

모듈:Yesno

리버티게임, 모두가 만들어가는 자유로운 게임
백괴게임>Bd3076님의 2018년 7월 19일 (목) 17:16 판 (새 문서: -- 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 no...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

이 모듈에 대한 설명문서는 모듈: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 tonumber(val) == 1
	then
		return true
	elseif val == false
		or val == 'no'
		or val == 'n'
		or val == 'false'
		or val == 'f'
		or tonumber(val) == 0
	then
		return false
	else
		return default
	end
end