Module:Yesno/doc
| This is a documentation subpage for Module:Yesno/doc. It contains usage information, categories, and other content that is not part of the original module page. |
| 편집하지 마십시오. 이 문서는 자동화 도구에 의해 정비되고 있습니다. 모든 편집은 [[mw:{{{1}}}|mediawiki.org]]에서 수행하는 것이 좋습니다. (이 경고 번역하기) |
| This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
| This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikimania user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
| This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
이 모듈은 부울 또는 부울 형식의 문자열 입력을 처리하기 위한 일관된 인터페이스를 제공합니다.
루아에서는 true과 false와 같은 부울 값을 사용할 수 있지만, 위키코드 템플릿에서는 "1", "0", "yes", "no" 등과 같은 문자열을 통해서만 부울 값을 표현할 수 있습니다.
이 모듈은 이러한 종류의 문자열을 처리하여 루아가 처리할 수 있는 부울 입력으로 변환합니다.
또한 nil과 false를 구분할 수 있도록 nil 값을 false로 반환합니다.
이 모듈은 부울, 숫자, 표, 함수와 같은 다른 루아 구조도 입력으로 허용합니다.
입력값이 부울 또는 nil로 인식되지 않는 경우, 반환할 기본값을 지정할 수 있습니다.
모듈 품질
구문
yesno(value, default)
value은 테스트할 값입니다.
부울 입력 또는 부울 스타일 입력(아래 참조)은 항상 true 또는 false로 평가되고, nil은 항상 nil으로 평가됩니다.
다른 값들은 default로 평가됩니다.
사용법
먼저 모듈을 로드합니다. 이 모듈은 일반 위키 페이지가 아닌 다른 루아 모듈에서만 로드할 수 있다는 점에 유의하십시오.
일반 위키 페이지의 경우 {{yesno}}을 대신 사용할 수 있습니다.
local yesno = require('Module:Yesno')
일부 입력값은 항상 true를 반환하고, 일부 입력값은 항상 false를 반환합니다.
nil 값은 항상 nil를 반환합니다.
-- 이것들은 항상 true를 반환합니다:
yesno('yes')
yesno('y')
yesno('true')
yesno('t')
yesno('1')
yesno(1)
yesno(true)
-- 이것들은 항상 false를 반환합니다:
yesno('no')
yesno('n')
yesno('false')
yesno('f')
yesno('0')
yesno(0)
yesno(false)
-- nil 값은 항상 nil를 반환합니다.
yesno(nil)
문자열 값은 일치시키기 전에 소문자로 변환됩니다.
-- 이것들은 항상 true를 반환합니다:
yesno('Yes')
yesno('YES')
yesno('yEs')
yesno('Y')
yesno('tRuE')
-- 이것들은 항상 false를 반환합니다:
yesno('No')
yesno('NO')
yesno('nO')
yesno('N')
yesno('fALsE')
yesno에 위에 나열된 값 이외의 입력이 들어올 경우를 대비하여 기본값을 지정할 수 있습니다.
기본값을 제공하지 않으면 모듈은 해당 입력에 대해 nil를 반환합니다.
-- 이것들은 nil를 반환합니다:
yesno('foo')
yesno({})
yesno(5)
yesno(function() return 'This is a function.' end)
-- 이것들은 true를 반환합니다:
yesno('foo', true)
yesno({}, true)
yesno(5, true)
yesno(function() return 'This is a function.' end, true)
-- 이것들은 "bar"를 반환합니다:
yesno('foo', 'bar')
yesno({}, 'bar')
yesno(5, 'bar')
yesno(function() return 'This is a function.' end, 'bar')
참고로 빈 문자열도 이와 같은 기능을 합니다.
yesno('') -- nil를 반환합니다.
yesno('', true) -- true를 반환합니다.
yesno('', 'bar') -- "bar"를 반환합니다.
빈 문자열은 일반적으로 위키텍스트에서는 false로 평가되지만, 루아에서는 true로 평가됩니다.
이 모듈은 위키텍스트의 동작 방식보다 루아의 동작 방식을 선호합니다.
모듈에서 빈 문자열을 false로 처리하는 것이 중요하다면, 처리 과정의 초기 단계에서 빈 인수를 제거해야 합니다.